From 69281282265cbd9a8baf507be65ee0d1eda63617 Mon Sep 17 00:00:00 2001 From: Oleksii Bilan Date: Thu, 21 Nov 2024 11:26:18 +0200 Subject: [PATCH] ACP-3963 Algolia Event-Based Features. (#2559) ACP-3963 Algolia Event-Based Features. --- .../Transfer/quick_order_page.transfer.xml | 7 +++ .../PriceResolver/PriceResolver.php | 22 ++++--- .../quick-order-row-partial.twig | 2 + .../views/quick-order/quick-order.twig | 61 +++++++++++++++++++ 4 files changed, 84 insertions(+), 8 deletions(-) diff --git a/src/SprykerShop/Shared/QuickOrderPage/Transfer/quick_order_page.transfer.xml b/src/SprykerShop/Shared/QuickOrderPage/Transfer/quick_order_page.transfer.xml index 667f56c..961cff4 100644 --- a/src/SprykerShop/Shared/QuickOrderPage/Transfer/quick_order_page.transfer.xml +++ b/src/SprykerShop/Shared/QuickOrderPage/Transfer/quick_order_page.transfer.xml @@ -18,6 +18,11 @@ + + + + + @@ -28,6 +33,8 @@ + + diff --git a/src/SprykerShop/Yves/QuickOrderPage/PriceResolver/PriceResolver.php b/src/SprykerShop/Yves/QuickOrderPage/PriceResolver/PriceResolver.php index 6416505..8e61b61 100644 --- a/src/SprykerShop/Yves/QuickOrderPage/PriceResolver/PriceResolver.php +++ b/src/SprykerShop/Yves/QuickOrderPage/PriceResolver/PriceResolver.php @@ -8,6 +8,7 @@ namespace SprykerShop\Yves\QuickOrderPage\PriceResolver; use ArrayObject; +use Generated\Shared\Transfer\CurrentProductPriceTransfer; use Generated\Shared\Transfer\PriceProductFilterTransfer; use Generated\Shared\Transfer\QuickOrderItemTransfer; use Generated\Shared\Transfer\QuickOrderTransfer; @@ -75,13 +76,17 @@ public function setSumPriceForQuickOrderItemTransfer(QuickOrderItemTransfer $qui return $quickOrderItemTransfer; } - $sumPrice = $this->getSumPriceForQuickOrderItemTransfer( + $currentProductPriceTransfer = $this->getCurrentProductPriceTransfer( $quickOrderItemTransfer, $idProduct, $this->productResolver->getIdProductAbstractByIdProduct($idProduct), ); - $quickOrderItemTransfer->setSumPrice($sumPrice); + $quickOrderItemTransfer->setSumPrice($currentProductPriceTransfer->getSumPrice()); + $quickOrderItemTransfer->getProductConcrete()->setDefaultPrice( + $currentProductPriceTransfer->getPrice() ? (string)$currentProductPriceTransfer->getPrice() : null, + ); + $quickOrderItemTransfer->getProductConcrete()->setPrices(new ArrayObject($currentProductPriceTransfer->getPrices())); return $quickOrderItemTransfer; } @@ -91,18 +96,19 @@ public function setSumPriceForQuickOrderItemTransfer(QuickOrderItemTransfer $qui * @param int $idProduct * @param int $idProductAbstract * - * @return int|null + * @return \Generated\Shared\Transfer\CurrentProductPriceTransfer */ - protected function getSumPriceForQuickOrderItemTransfer(QuickOrderItemTransfer $quickOrderItemTransfer, int $idProduct, int $idProductAbstract): ?int - { + protected function getCurrentProductPriceTransfer( + QuickOrderItemTransfer $quickOrderItemTransfer, + int $idProduct, + int $idProductAbstract + ): CurrentProductPriceTransfer { $priceProductFilterTransfer = (new PriceProductFilterTransfer()) ->fromArray($quickOrderItemTransfer->toArray(), true) ->setIdProduct($idProduct) ->setIdProductAbstract($idProductAbstract) ->setSku(null); - return $this->priceProductStorageClient - ->getResolvedCurrentProductPriceTransfer($priceProductFilterTransfer) - ->getSumPrice(); + return $this->priceProductStorageClient->getResolvedCurrentProductPriceTransfer($priceProductFilterTransfer); } } diff --git a/src/SprykerShop/Yves/QuickOrderPage/Theme/default/components/molecules/quick-order-row-partial/quick-order-row-partial.twig b/src/SprykerShop/Yves/QuickOrderPage/Theme/default/components/molecules/quick-order-row-partial/quick-order-row-partial.twig index 04a3938..f8b656c 100644 --- a/src/SprykerShop/Yves/QuickOrderPage/Theme/default/components/molecules/quick-order-row-partial/quick-order-row-partial.twig +++ b/src/SprykerShop/Yves/QuickOrderPage/Theme/default/components/molecules/quick-order-row-partial/quick-order-row-partial.twig @@ -98,6 +98,8 @@ {% block price %}
{% block priceInner %} + + {% include molecule('money-price') with { data: { amount: data.price is empty ? null : data.price, diff --git a/src/SprykerShop/Yves/QuickOrderPage/Theme/default/views/quick-order/quick-order.twig b/src/SprykerShop/Yves/QuickOrderPage/Theme/default/views/quick-order/quick-order.twig index 94dd341..546e792 100644 --- a/src/SprykerShop/Yves/QuickOrderPage/Theme/default/views/quick-order/quick-order.twig +++ b/src/SprykerShop/Yves/QuickOrderPage/Theme/default/views/quick-order/quick-order.twig @@ -26,3 +26,64 @@ }, } only %} {% endblock %} + +{% block eventTracker %} + {% set productsConfig = { + multi: true, + selector: '.quick-order-row', + composed: { + sku: { + selector: '.js-autocomplete-form__value-input', + attribute: 'value', + }, + quantity: { + selector: '.js-formatted-number-input__hidden-input', + attribute: 'value', + }, + price: { + selector: '[itemprop="itemPrice"]', + attribute: 'content', + }, + }, + } %} + {% set events = { + list: events.list | merge([ + { + event: 'ADD_TO_SHOPPING_LIST', + name: 'click', + triggers: [ + { + selector: 'body:has([name="addToShoppingList"]:focus)', + data: { + products: productsConfig, + }, + }, + ], + }, + { + event: 'ADD_TO_CART', + name: 'click', + triggers: [ + { + selector: 'body:has([name="addToCart"]:focus)', + data: { + products: productsConfig, + }, + }, + { + selector: 'body:has([name="createOrder"]:focus)', + data: { + products: productsConfig, + }, + }, + ], + } + ]), + + data: events.data | merge({ + page: 'QUICK_ORDER', + }), + } %} + + {{ parent() }} +{% endblock %}