Skip to content

Commit

Permalink
Merge pull request #1244 from BearGroup/release/5.18.0
Browse files Browse the repository at this point in the history
Release/5.18.0
  • Loading branch information
akshitaWaldia authored Sep 30, 2024
2 parents 50ec143 + 6a16954 commit 658f831
Show file tree
Hide file tree
Showing 22 changed files with 486 additions and 58 deletions.
157 changes: 157 additions & 0 deletions Block/Promo/PromoMessaging.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

namespace Amazon\Pay\Block\Promo;

use Amazon\Pay\Model\AmazonConfig;
use Magento\Catalog\Model\Product;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;

class PromoMessaging extends \Magento\Framework\View\Element\Template
{

/**
* These product types are not supported for promo messaging
*/
protected const EXCLUDED_PRODUCT_TYPES = ['giftcard', 'grouped', 'virtual'];

/**
* @var AmazonConfig
*/
protected $amazonConfig;

/**
* @var Registry
*/
protected $registry;

/**
* @param AmazonConfig $amazonConfig
* @param Template\Context $context
* @param Registry $registry
* @param array $data
*/
public function __construct(
AmazonConfig $amazonConfig,
Template\Context $context,
Registry $registry,
array $data = []
) {
parent::__construct($context, $data);
$this->amazonConfig = $amazonConfig;
$this->registry = $registry;
}

/**
* Checks if promo messaging is enabled
*
* @return int
*/
public function isPromoMessageEnabled(): int
{
return $this->_scopeConfig->getValue('payment/amazon_payment_v2/promo_message_enabled');
}

/**
* AP Merchant Id getter
*
* @return string|null
*/
public function getMerchantId(): ?string
{
return $this->amazonConfig->getMerchantId();
}

/**
* AP Currency Code getter
*
* @return string
*/
public function getCurrencyCode(): string
{
return $this->amazonConfig->getCurrencyCode();
}

/**
* AP Language Code getter
*
* @return string
*/
public function getLanguageCode(): string
{
return $this->amazonConfig->getLanguage();
}

/**
* Determines current environment based on if sandbox is enabled or not
*
* @return string
*/
public function getEnvironment(): string
{
return $this->amazonConfig->isSandboxEnabled() ? 'sandbox' : 'live';
}

/**
* Get product from registry
*
* @return Product
*/
private function getProduct(): Product
{
return $this->registry->registry('product');
}

/**
* Grabs current product's price for promo vars
*
* @return float|null
*/
public function getProductPrice(): ?float
{
$product = $this->getProduct();
return $product ? $product->getPrice() : null;
}

/**
* Checks if product is of a type that does not contain static price values
*
* @return bool
*/
public function checkIsEligibleProduct(): bool
{
$product = $this->getProduct();
return !in_array($product->getTypeId(), self::EXCLUDED_PRODUCT_TYPES, true);
}

/**
* AP Payment Product Type
*
* @return string|null
*/
public function getPaymentProductType(): ?string
{
return $this->_scopeConfig->getValue('payment/amazon_payment_v2/promo_message_product_type');
}

/**
* AP Promo Font Color getter
*
* @return string|null
*/
public function getPromoFontColor(): ?string
{
return $this->_scopeConfig->getValue('payment/amazon_payment_v2/promo_message_color');
}

/**
* AP Promo Font Color getter
*
* @return string|null
*/
public function getPromoFontSize(): ?string
{
return $this->_scopeConfig->getValue('payment/amazon_payment_v2/promo_message_font_size');
}
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 5.18.0
* Added product page promo banner functionality and configuration

## 5.17.1
* Changed php allowed versions to include 8.3
* Fixed issue where orders could be processing but not capture payment
Expand Down
3 changes: 1 addition & 2 deletions Model/CheckoutSessionManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -1146,9 +1146,8 @@ private function placeOrCollectOrder($amazonSessionId, $cartId)
if ($transaction) {
$result = [
'success' => true,
'order_id' => null
'order_id' => $transaction->getOrderId()
];
$result['order_id'] = $this->magentoCheckoutSession->getLastOrderId();
} else {
$result = $this->placeOrder($amazonSessionId);
}
Expand Down
34 changes: 34 additions & 0 deletions Model/Config/Source/PromoFontSize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Amazon\Pay\Model\Config\Source;

class PromoFontSize implements \Magento\Framework\Data\OptionSourceInterface
{

/**
* Font values available for promo message banner
*
* @return array[]
*/
public function toOptionArray(): array
{
return [
[
'label' => __('14px'),
'value' => '14',
],
[
'label' => __('16px'),
'value' => '16',
],
[
'label' => __('18px'),
'value' => '18',
],
[
'label' => __('20px'),
'value' => '20',
]
];
}
}
26 changes: 26 additions & 0 deletions Model/Config/Source/PromoPaymentType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Amazon\Pay\Model\Config\Source;

class PromoPaymentType implements \Magento\Framework\Data\OptionSourceInterface
{

/**
* Payment "product type" checkout values available for promo message banner
*
* @return array[]
*/
public function toOptionArray(): array
{
return [
[
'label' => __('Pay And Ship'),
'value' => 'PayAndShip',
],
[
'label' => __('Pay Only'),
'value' => 'PayOnly',
]
];
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The following table provides an overview on which Git branch is compatible to wh
Magento Version | Github Branch | Latest release
---|---|---
2.2.6 - 2.2.11 (EOL) | [V2checkout-1.2.x](https://github.com/amzn/amazon-payments-magento-2-plugin/tree/V2checkout-1.2.x) | 1.20.0 (EOL)
2.3.0 - 2.4.x | [master](https://github.com/amzn/amazon-payments-magento-2-plugin/tree/master) | 5.17.1
2.3.0 - 2.4.x | [master](https://github.com/amzn/amazon-payments-magento-2-plugin/tree/master) | 5.18.0

## Release Notes
See [CHANGELOG.md](/CHANGELOG.md)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "amzn/amazon-pay-magento-2-module",
"description": "Official Magento2 Plugin to integrate with Amazon Pay",
"type": "magento2-module",
"version": "5.17.1",
"version": "5.18.0",
"license": [
"Apache-2.0"
],
Expand Down
22 changes: 22 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@
<field id="amazonloggin">1</field>
</depends>
</field>
<field id="promo_message_enabled" translate="label comment" type="select" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Product Page Promo Messaging</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/amazon_payment_v2/promo_message_enabled</config_path>
<comment><![CDATA[Note: Promo messaging for buy now, pay later on the pdp.]]></comment>
</field>
<field id="promo_message_product_type" translate="label comment" type="select" sortOrder="110" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Promo Message Payment Product Type</label>
<config_path>payment/amazon_payment_v2/promo_message_product_type</config_path>
<source_model>Amazon\Pay\Model\Config\Source\PromoPaymentType</source_model>
<comment><![CDATA[Note: Product type for payment. Pay Only not compatible with promo banner functionality.]]></comment>
</field>
<field id="promo_message_color" translate="label" type="select" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Promo Message Color</label>
<config_path>payment/amazon_payment_v2/promo_message_color</config_path>
<source_model>Amazon\Pay\Model\Config\Source\ButtonColor</source_model>
</field>
<field id="promo_message_font_size" translate="label" type="select" sortOrder="140" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Promo Message Font Size</label>
<config_path>payment/amazon_payment_v2/promo_message_font_size</config_path>
<source_model>Amazon\Pay\Model\Config\Source\PromoFontSize</source_model>
</field>
</group>
<group id="sales_options" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Sales Options</label>
Expand Down
4 changes: 4 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
<can_use_internal>0</can_use_internal>
<can_authorize_vault>1</can_authorize_vault>
<can_capture_vault>1</can_capture_vault>
<promo_message_enabled>0</promo_message_enabled>
<promo_message_banner_class>ap-promotional-message</promo_message_banner_class>
<promo_message_product_type>PayAndShip</promo_message_product_type>
<promo_message_font_size>20</promo_message_font_size>
</amazon_payment_v2>
<amazon_payment_v2_vault>
<model>AmazonPayVaultFacade</model>
Expand Down
Loading

0 comments on commit 658f831

Please sign in to comment.