Skip to content

Commit 8960bbb

Browse files
authored
Merge pull request #1370 from algolia/feature/MAGE-674
Feature/mage 674
2 parents afdbc7f + 91c3aec commit 8960bbb

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

Block/Algolia.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,12 @@ public function getLastOrder()
270270
return $this->checkoutSession->getLastRealOrder();
271271
}
272272

273-
public function getAddToCartParams()
273+
public function getAddToCartParams() : array
274274
{
275-
$url = $this->getAddToCartUrl();
276-
277275
return [
278-
'action' => $url,
276+
'action' => $this->_urlBuilder->getUrl('checkout/cart/add', []),
279277
'formKey' => $this->formKey->getFormKey(),
278+
'redirectUrlParam' => ActionInterface::PARAM_NAME_URL_ENCODED
280279
];
281280
}
282281

@@ -285,6 +284,9 @@ public function getTimestamp()
285284
return $this->date->gmtTimestamp('today midnight');
286285
}
287286

287+
/**
288+
* @deprecated This function is deprecated as redirect routes must be derived on the frontend not backend
289+
*/
288290
protected function getAddToCartUrl($additional = [])
289291
{
290292
$continueUrl = $this->urlHelper->getEncodedUrl($this->_urlBuilder->getCurrentUrl());

Block/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public function getConfiguration()
234234
'path' => $path,
235235
'level' => $level,
236236
'parentCategory' => $parentCategoryName,
237+
'url' => $this->getUrl('*/*/*', ['_use_rewrite' => true, '_forced_secure' => true])
237238
],
238239
'showCatsNotIncludedInNavigation' => $config->showCatsNotIncludedInNavigation(),
239240
'showSuggestionsOnNoResultsPage' => $config->showSuggestionsOnNoResultsPage(),

view/frontend/templates/instant/hit.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ $origFormatedVar = $block->escapeHtml('price' . $priceKey . '_original_formated'
8686
<input type="hidden" name="queryID" value="{{__queryID}}">
8787
<input type="hidden" name="product" value="{{objectID}}">
8888
{{#_highlightResult.default_bundle_options}}<input type="hidden" name="bundle_option[{{ optionId }}]" value="{{selectionId}}">{{/_highlightResult.default_bundle_options}}
89-
<input type="hidden" name="uenc" value="{{ addToCart.uenc }}">
89+
<input type="hidden" name="{{ addToCart.redirectUrlParam }}" value="{{ addToCart.uenc }}">
9090
<input name="form_key" type="hidden" value="{{ addToCart.formKey }}">
9191
<button type="submit" title="<?php echo __('Add to Cart') ?>" class="action tocart primary"
9292
data-objectid="{{objectID}}"

view/frontend/web/instantsearch.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,20 @@ define(
644644

645645
var isStarted = false;
646646

647+
// Capture active redirect URL with IS facet params for add to cart from PLP
648+
if (algoliaConfig.instant.isAddToCartEnabled) {
649+
search.on('render', () => {
650+
const cartForms = document.querySelectorAll('[data-role="tocart-form"]');
651+
cartForms.forEach((form, i) => {
652+
const ts = Date.now();
653+
form.addEventListener('submit', e => {
654+
const url = `${algoliaConfig.request.url}${window.location.search}`;
655+
e.target.elements[algoliaConfig.instant.addToCartParams.redirectUrlParam].value = AlgoliaBase64.mageEncode(url);
656+
})
657+
});
658+
});
659+
}
660+
647661
function startInstantSearch() {
648662
if (isStarted === true) {
649663
return;

view/frontend/web/internals/common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ define(['jquery', 'algoliaBundle'], function ($, algoliaBundle) {
198198

199199
hit.addToCart = {
200200
'action': action,
201+
'redirectUrlParam': algoliaConfig.instant.addToCartParams.redirectUrlParam,
201202
'uenc': AlgoliaBase64.mageEncode(action),
202203
'formKey': algoliaConfig.instant.addToCartParams.formKey
203204
};

0 commit comments

Comments
 (0)