From 9605f2651321598e0853a4326f3aa4a56053713d Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Thu, 3 Mar 2022 14:56:25 +0100 Subject: [PATCH 1/6] MOL-701 update ideal svg logo --- public/images/ideal-qr.svg | 24 +------------------ public/images/ideal.svg | 49 ++++++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/public/images/ideal-qr.svg b/public/images/ideal-qr.svg index ee501624b..fe706207d 100644 --- a/public/images/ideal-qr.svg +++ b/public/images/ideal-qr.svg @@ -1,23 +1 @@ - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/public/images/ideal.svg b/public/images/ideal.svg index 98df33cf2..fded9442b 100644 --- a/public/images/ideal.svg +++ b/public/images/ideal.svg @@ -1,13 +1,38 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + From 48712505a95b1d84d7efe3f365f7b2de03e61500 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 4 Mar 2022 12:35:47 +0100 Subject: [PATCH 2/6] MOL-702 Check voucher availability on checkout block call --- src/BlockService/CheckoutBlockService.php | 79 ++++++++++++++++----- src/Gateway/GatewayModule.php | 3 +- src/Gateway/Voucher/MaybeDisableGateway.php | 12 ++++ 3 files changed, 74 insertions(+), 20 deletions(-) diff --git a/src/BlockService/CheckoutBlockService.php b/src/BlockService/CheckoutBlockService.php index c38b9d925..e1818185a 100644 --- a/src/BlockService/CheckoutBlockService.php +++ b/src/BlockService/CheckoutBlockService.php @@ -5,17 +5,28 @@ namespace Mollie\WooCommerce\BlockService; use InvalidArgumentException; +use Mollie\WooCommerce\Gateway\Voucher\MaybeDisableGateway; +use Mollie\WooCommerce\Shared\Data; +/** + * Class CheckoutBlockService + * @package Mollie\WooCommerce\BlockService + */ class CheckoutBlockService { protected $dataService; + /** + * @var MaybeDisableGateway + */ + protected $voucherDisabler; /** * CheckoutBlockService constructor. */ - public function __construct($dataService) + public function __construct(Data $dataService, MaybeDisableGateway $voucherDisabler) { $this->dataService = $dataService; + $this->voucherDisabler = $voucherDisabler; } /** @@ -38,21 +49,17 @@ function () { ); } + /** + * When the country changes in the checkout block + * We need to check again the list of available gateways accordingly + * And return the result with a key based on the evaluated filters for the script to cache + */ public function availableGateways() { $currency = filter_var($_POST['currency'], FILTER_SANITIZE_STRING); - $cartTotal = filter_var( - $_POST['cartTotal'], - FILTER_SANITIZE_NUMBER_INT - ); - $paymentLocale = filter_var( - $_POST['paymentLocale'], - FILTER_SANITIZE_STRING - ); - $billingCountry = filter_var( - $_POST['billingCountry'], - FILTER_SANITIZE_STRING - ); + $cartTotal = filter_var($_POST['cartTotal'], FILTER_SANITIZE_NUMBER_INT); + $paymentLocale = filter_var($_POST['paymentLocale'], FILTER_SANITIZE_STRING); + $billingCountry = filter_var($_POST['billingCountry'], FILTER_SANITIZE_STRING); $cartTotal = $cartTotal / 100; $availablePaymentMethods = []; try { @@ -68,17 +75,51 @@ public function availableGateways() if ($filters) { WC()->customer->set_billing_country($billingCountry); $availableGateways = WC()->payment_gateways()->get_available_payment_gateways(); - foreach ($availableGateways as $key => $gateway){ - if(strpos($key, 'mollie_wc_gateway_') === false){ - unset($availableGateways[$key]); - } - } + $availableGateways = $this->removeNonMollieGateway($availableGateways); + $availableGateways = $this->maybeRemoveVoucher($availableGateways); $filterKey = "{$filters['amount']['currency']}-{$filters['locale']}-{$filters['billingCountry']}"; foreach ($availableGateways as $key => $gateway){ $availablePaymentMethods[$filterKey][$key] = $gateway->paymentMethod->getProperty('id'); } } - wp_send_json_success($availablePaymentMethods); } + + /** + * Remove the voucher gateway from the available ones + * if the products in the cart don't fit the requirements + * + * @param array $availableGateways + * @return array + */ + protected function maybeRemoveVoucher(array $availableGateways): array + { + foreach ($availableGateways as $key => $gateway) { + if ($key !=='mollie_wc_gateway_voucher') { + continue; + } + $shouldRemoveVoucher = $this->voucherDisabler->shouldRemoveVoucher(); + if($shouldRemoveVoucher){ + unset($availableGateways[$key]); + } + } + return $availableGateways; + } + + /** + * Remove the non Mollie gateways from the available ones + * so we don't deal with them in our block logic + * + * @param array $availableGateways + * @return array + */ + protected function removeNonMollieGateway(array $availableGateways): array + { + foreach ($availableGateways as $key => $gateway) { + if (strpos($key, 'mollie_wc_gateway_') === false) { + unset($availableGateways[$key]); + } + } + return $availableGateways; + } } diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index 18170a66a..a28d40cbe 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -207,7 +207,8 @@ static function () { $this->molliePayPalButtonHandling($paypalGateway, $notice, $logger, $pluginUrl); } - $checkoutBlockHandler = new CheckoutBlockService($container->get('settings.data_helper')); + $maybeDisableVoucher = new MaybeDisableGateway(); + $checkoutBlockHandler = new CheckoutBlockService($container->get('settings.data_helper'), $maybeDisableVoucher); $checkoutBlockHandler->bootstrapAjaxRequest(); add_action( 'woocommerce_rest_checkout_process_payment_with_context', function($paymentContext){ if(strpos($paymentContext->payment_method, 'mollie_wc_gateway_') === false){ diff --git a/src/Gateway/Voucher/MaybeDisableGateway.php b/src/Gateway/Voucher/MaybeDisableGateway.php index 0c53c8fef..c18c51606 100644 --- a/src/Gateway/Voucher/MaybeDisableGateway.php +++ b/src/Gateway/Voucher/MaybeDisableGateway.php @@ -59,6 +59,18 @@ public function maybeDisableMealVoucherGateway(array $gateways) return $gateways; } + /** + * If there are no products with category + * then we should not see the voucher gateway + * + * @return bool + */ + public function shouldRemoveVoucher(): bool + { + $productsWithCategory = $this->numberProductsWithCategory(); + return $productsWithCategory === 0; + } + /** * Compares the products in the cart with the categories associated with * every product in the cart. So it returns 0 if no products have category From acb80e74016434e0bdbc74d2b17cabb7fc44bccc Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 4 Mar 2022 13:11:15 +0100 Subject: [PATCH 3/6] MOL-704 add width and height as other svg logos --- public/images/ideal.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/images/ideal.svg b/public/images/ideal.svg index fded9442b..a35102e55 100644 --- a/public/images/ideal.svg +++ b/public/images/ideal.svg @@ -1,7 +1,7 @@ + width="33" height="24" viewBox="0 0 306.1 269.8" style="enable-background:new 0 0 306.1 269.8;" xml:space="preserve">