Skip to content

Commit

Permalink
Merge pull request #912 from PrestaShopCorp/release/v2.20.2
Browse files Browse the repository at this point in the history
Release v2.20.2
  • Loading branch information
Matt75 authored Aug 9, 2022
2 parents 27b5595 + 5fa8edb commit 9ad1d11
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 30 deletions.
30 changes: 13 additions & 17 deletions _dev/js/front/src/components/1_7/payment-options.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,8 @@ export class PaymentOptionsComponent extends BaseComponent {
};

created() {
this.data.HTMLElement = this.querySelectorService.getPaymentOptions();

this.data.HTMLElementPaymentOptionsContainer = this.querySelectorService.getPaymentOptions();
this.data.HTMLBasePaymentConfirmation = this.querySelectorService.getBasePaymentConfirmation();

this.data.HTMLElementPayPalButton = document.querySelector(
'.ps_checkout-button[data-funding-source="paypal"]'
);
this.data.HTMLElementPayPalRadio = document.querySelector(
'input[type="radio"][data-module-name="ps_checkout-paypal"]'
);
}

renderPaymentOptionItems() {
Expand Down Expand Up @@ -72,9 +64,14 @@ export class PaymentOptionsComponent extends BaseComponent {
}

renderExpressCheckoutPaymentButton() {
const paymentButton = this.data.HTMLBasePaymentConfirmation.cloneNode(true);
this.data.HTMLElementPaymentOptionsContainer.style.display = 'none';
const nativePaymentButton = this.data.HTMLBasePaymentConfirmation;
const paymentButton = nativePaymentButton.cloneNode(true);
const nativePaymentButtonContainer = nativePaymentButton.parentElement;

nativePaymentButton.style.display = 'none';

paymentButton.id = 'ps_checkout-hosted-submit-button';
paymentButton.id = 'ps_checkout-express-checkout-button';
paymentButton.type = 'button';

paymentButton.addEventListener('click', (event) => {
Expand Down Expand Up @@ -108,20 +105,22 @@ export class PaymentOptionsComponent extends BaseComponent {

this.children.expressCheckoutButton.id = 'button-paypal';
this.children.expressCheckoutButton.classList.add(
'.ps_checkout-express-checkout-button'
'ps_checkout-express-checkout-button'
);

paymentButton.disabled = !this.data.conditions.isChecked();
paymentButton.classList.remove('disabled');
paymentButton.classList.toggle('disabled', paymentButton.disabled);

this.data.conditions.onChange(() => {
setTimeout(() => {
nativePaymentButton.style.display = 'none';
paymentButton.disabled = !this.data.conditions.isChecked();
paymentButton.classList.toggle('disabled', paymentButton.disabled);
}, 0);
});

this.children.expressCheckoutButton.append(paymentButton);
this.data.HTMLElementPayPalButton.append(
nativePaymentButtonContainer.append(
this.children.expressCheckoutButton
);
}
Expand All @@ -135,9 +134,6 @@ export class PaymentOptionsComponent extends BaseComponent {
this.renderPaymentOptionItems();
this.renderPaymentOptionRadios();
} else {
this.data.HTMLElement.style.display = 'none';
this.data.HTMLElementPayPalRadio.checked = true;

this.renderExpressCheckoutPaymentButton();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,20 @@ export class PrestashopPs1_6Service {
}

static getCartAmount() {
let totalPrice = document.querySelector('.cart_block_total').textContent || '';
return totalPrice.replace(',', '.').replace(/[^.\d]/g, '');
let cartAmountContainer = document.querySelector('.cart_block_total');

if (!cartAmountContainer) {
return '';
}

return cartAmountContainer.textContent.replace(',', '.').replace(/[^.\d]/g, '');
}

static getProductPrice() {
if (!window.productPrice) {
return '';
}

return Number.parseFloat(window.productPrice).toFixed(2) || '';
}

Expand All @@ -104,7 +113,12 @@ export class PrestashopPs1_6Service {
let productAllowBuyWhenOutOfStock = window.allowBuyWhenOutOfStock || false;
let productQuantityAvailable = window.quantityAvailable || 0;
let productMinimalQuantity = window.minimalQuantity || 0;
let productQuantityWanted = parseInt(document.querySelector('#quantity_wanted').value) || 0;
let productQuantityWantedElement = document.querySelector('#quantity_wanted');
let productQuantityWanted = 0;

if (productQuantityWantedElement) {
productQuantityWanted = parseInt(productQuantityWantedElement.value) || 0;
}

return !productIsAvailableForOrder
|| (!productAllowBuyWhenOutOfStock && (productQuantityAvailable <= 0 || productQuantityWanted > productQuantityAvailable))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@
*/
export class PrestashopPs1_7Service {
static getProductDetails() {
const productDetails = document.getElementById('product-details');

if (!productDetails || !productDetails.dataset || !productDetails.dataset.product) {
throw new Error('Unable to retrieve product details from DOM: document.getElementById("product-details").dataset.product');
}

return JSON.parse(
document.getElementById('product-details').dataset.product
productDetails.dataset.product
);
}

Expand Down Expand Up @@ -86,14 +92,18 @@ export class PrestashopPs1_7Service {
productPrice = document.querySelector('.current-price [itemprop="price"]');
}

return productPrice.getAttribute('content') || '';
if (productPrice) {
return productPrice.getAttribute('content');
}

return '';
}

static isAddToCartButtonDisabled() {
let addToCartElement = document.querySelector('.page-product:not(.modal-open) .row .product-add-to-cart, .page-product:not(.modal-open) .product-container .product-add-to-cart, .page-product:not(.modal-open) .row .js-product-add-to-cart, .page-product:not(.modal-open) .product-container .js-product-add-to-cart');
let addToCartButtonElement = addToCartElement.querySelector('button.add-to-cart');

return addToCartButtonElement.disabled;
return addToCartButtonElement ? addToCartButtonElement.disabled : true;
}

static onUpdatedCart(listener) {
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>ps_checkout</name>
<displayName><![CDATA[PrestaShop Checkout]]></displayName>
<version><![CDATA[2.20.1]]></version>
<version><![CDATA[2.20.2]]></version>
<description><![CDATA[Provide the most commonly used payment methods to your customers in this all-in-one module, and manage all your sales in a centralized interface.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
2 changes: 1 addition & 1 deletion controllers/front/ExpressCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private function createAddress(
$address->id_state = $idState;
}

if ($address->validateFields(false)) {
if (true !== $address->validateFields(false)) {
return false;
}

Expand Down
8 changes: 6 additions & 2 deletions ps_checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Ps_checkout extends PaymentModule

// Needed in order to retrieve the module version easier (in api call headers) than instanciate
// the module each time to get the version
const VERSION = '2.20.1';
const VERSION = '2.20.2';

const INTEGRATION_DATE = '2022-14-06';

Expand All @@ -155,7 +155,7 @@ public function __construct()

// We cannot use the const VERSION because the const is not computed by addons marketplace
// when the zip is uploaded
$this->version = '2.20.1';
$this->version = '2.20.2';
$this->author = 'PrestaShop';
$this->currencies = true;
$this->currencies_mode = 'checkbox';
Expand Down Expand Up @@ -962,6 +962,10 @@ public function hookActionFrontControllerSetMedia()
{
$controller = (string) Tools::getValue('controller');

if (empty($controller) && isset($this->context->controller->php_self)) {
$controller = $this->context->controller->php_self;
}

/** @var \PrestaShop\Module\PrestashopCheckout\Validator\FrontControllerValidator $frontControllerValidator */
$frontControllerValidator = $this->getService('ps_checkout.validator.front_controller');

Expand Down
10 changes: 7 additions & 3 deletions views/templates/hook/adminAfterHeader/incompatibleCodes.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<h2>
{if $codesType === 'countries'}
{l s='PrestaShop Checkout transactions won\'t work in some of your configured countries, but there is a solution !' mod='ps_checkout'}
{else if $codesType === 'currencies'}
{elseif $codesType === 'currencies'}
{l s='PrestaShop Checkout transactions won\'t work in some of your configured currencies, but there is a solution !' mod='ps_checkout'}
{/if}
</h2>
Expand All @@ -46,11 +46,15 @@
{foreach $incompatibleCodes as $key => $incompatibleCode}
{$incompatibleCode}{if $key != count($incompatibleCodes) - 1},{/if}
{/foreach}
</b></i>
</i></b>
</p>

<a href="{$paymentPreferencesLink}" class="button-link" target="_blank">
{l s="Change {$codesType} activation for this payment module" mod='ps_checkout'}
{if $codesType === 'countries'}
{l s='Change countries activation for this payment module' mod='ps_checkout'}
{elseif $codesType === 'currencies'}
{l s='Change currencies activation for this payment module' mod='ps_checkout'}
{/if}
</a>

<a class="btn btn-link banner-link" href="{$paypalLink}" target="_blank">
Expand Down

0 comments on commit 9ad1d11

Please sign in to comment.