Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mage 674 #1370

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions Block/Algolia.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,12 @@ public function getLastOrder()
return $this->checkoutSession->getLastRealOrder();
}

public function getAddToCartParams()
public function getAddToCartParams() : array
{
$url = $this->getAddToCartUrl();

return [
'action' => $url,
'action' => $this->_urlBuilder->getUrl('checkout/cart/add', []),
'formKey' => $this->formKey->getFormKey(),
'redirectUrlParam' => ActionInterface::PARAM_NAME_URL_ENCODED
];
}

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

/**
* @deprecated This function is deprecated as redirect routes must be derived on the frontend not backend
*/
protected function getAddToCartUrl($additional = [])
{
$continueUrl = $this->urlHelper->getEncodedUrl($this->_urlBuilder->getCurrentUrl());
Expand Down
3 changes: 2 additions & 1 deletion Block/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public function getConfiguration()
'path' => $path,
'level' => $level,
'parentCategory' => $parentCategoryName,
'url' => $this->getUrl('*/*/*', ['_use_rewrite' => true, '_forced_secure' => true])
],
'showCatsNotIncludedInNavigation' => $config->showCatsNotIncludedInNavigation(),
'showSuggestionsOnNoResultsPage' => $config->showSuggestionsOnNoResultsPage(),
Expand Down Expand Up @@ -381,4 +382,4 @@ protected function getLandingPageConfiguration()
{
return $this->isLandingPage() ? $this->getCurrentLandingPage()->getConfiguration() : json_encode([]);
}
}
}
2 changes: 1 addition & 1 deletion view/frontend/templates/instant/hit.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ $origFormatedVar = $block->escapeHtml('price' . $priceKey . '_original_formated'
<input type="hidden" name="queryID" value="{{__queryID}}">
<input type="hidden" name="product" value="{{objectID}}">
{{#_highlightResult.default_bundle_options}}<input type="hidden" name="bundle_option[{{ optionId }}]" value="{{selectionId}}">{{/_highlightResult.default_bundle_options}}
<input type="hidden" name="uenc" value="{{ addToCart.uenc }}">
<input type="hidden" name="{{ addToCart.redirectUrlParam }}" value="{{ addToCart.uenc }}">
<input name="form_key" type="hidden" value="{{ addToCart.formKey }}">
<button type="submit" title="<?php echo __('Add to Cart') ?>" class="action tocart primary"
data-objectid="{{objectID}}"
Expand Down
16 changes: 15 additions & 1 deletion view/frontend/web/instantsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,20 @@ define(

var isStarted = false;

// Capture active redirect URL with IS facet params for add to cart from PLP
if (algoliaConfig.instant.isAddToCartEnabled) {
search.on('render', () => {
const cartForms = document.querySelectorAll('[data-role="tocart-form"]');
cartForms.forEach((form, i) => {
const ts = Date.now();
form.addEventListener('submit', e => {
const url = `${algoliaConfig.request.url}${window.location.search}`;
e.target.elements[algoliaConfig.instant.addToCartParams.redirectUrlParam].value = AlgoliaBase64.mageEncode(url);
})
});
});
}

function startInstantSearch() {
if (isStarted === true) {
return;
Expand Down Expand Up @@ -689,4 +703,4 @@ define(
return options;
}
}
);
);
1 change: 1 addition & 0 deletions view/frontend/web/internals/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ define(['jquery', 'algoliaBundle'], function ($, algoliaBundle) {

hit.addToCart = {
'action': action,
'redirectUrlParam': algoliaConfig.instant.addToCartParams.redirectUrlParam,
'uenc': AlgoliaBase64.mageEncode(action),
'formKey': algoliaConfig.instant.addToCartParams.formKey
};
Expand Down