Skip to content

Commit

Permalink
ACP-3963 Algolia Event-Based Features. (#2559)
Browse files Browse the repository at this point in the history
ACP-3963 Algolia Event-Based Features.
  • Loading branch information
supproduction authored Nov 21, 2024
1 parent 3434380 commit 6928128
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<property name="sku" type="string"/>
<property name="idProductConcrete" type="int"/>
<property name="localizedAttributes" type="LocalizedAttributes[]" singular="localizedAttributes"/>
<property name="defaultPrice" type="string"/>
<property name="prices" type="PriceProduct[]" singular="price"/>
</transfer>

<transfer name="PriceProduct">
</transfer>

<transfer name="Message">
Expand All @@ -28,6 +33,8 @@

<transfer name="CurrentProductPrice">
<property name="sumPrice" type="int"/>
<property name="price" type="int"/>
<property name="prices" type="array" singular="price"/>
</transfer>

<transfer name="Item">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
{% block price %}
<div class="col {{ priceColumnClass }} spacing spacing--inner">
{% block priceInner %}
<span itemprop="itemPrice" content="{{ product.prices['DEFAULT'] | default }}">

{% include molecule('money-price') with {
data: {
amount: data.price is empty ? null : data.price,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

0 comments on commit 6928128

Please sign in to comment.