Skip to content

Commit

Permalink
Merge pull request #80 from magmodules/release/2.1.8
Browse files Browse the repository at this point in the history
Release/2.1.8
  • Loading branch information
Marvin-Magmodules authored Sep 26, 2024
2 parents 993aafc + eebdeef commit fa62c7a
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 104 deletions.
26 changes: 8 additions & 18 deletions Controller/Wishlist/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Magento\Framework\App\ActionInterface;
use Magento\Wishlist\Controller\WishlistProviderInterface;
use Magento\Wishlist\Model\AuthenticationStateInterface;
use Magento\Wishlist\Model\ResourceModel\Wishlist as WishlistResourceModel;
use Magmodules\Sooqr\Api\Config\RepositoryInterface as ConfigProvider;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Controller\Result\Redirect;
Expand Down Expand Up @@ -86,24 +87,11 @@ class Add implements ActionInterface
* @var ResultFactory
*/
private $resultFactory;

/**
* Add constructor.
*
* @param ConfigProvider $configProvider
* @param Session $customerSession
* @param WishlistProviderInterface $wishlistProvider
* @param ProductRepositoryInterface $productRepository
* @param WishlistHelper $wishlistHelper
* @param RedirectInterface $redirect
* @param LogRepository $logRepository
* @param AuthenticationStateInterface $authenticationState
* @param ScopeConfigInterface $config
* @param MessageManagerInterface $messageManager
* @param RequestInterface $request
* @param EventManagerInterface $eventManager
* @param ResultFactory $resultFactory
* @var WishlistResourceModel
*/
private $wishlistResource;

public function __construct(
ConfigProvider $configProvider,
Session $customerSession,
Expand All @@ -117,6 +105,7 @@ public function __construct(
MessageManagerInterface $messageManager,
RequestInterface $request,
EventManagerInterface $eventManager,
WishlistResourceModel $wishlistResource,
ResultFactory $resultFactory
) {
$this->configProvider = $configProvider;
Expand All @@ -132,6 +121,7 @@ public function __construct(
$this->request = $request;
$this->eventManager = $eventManager;
$this->resultFactory = $resultFactory;
$this->wishlistResource = $wishlistResource;
}

/**
Expand All @@ -140,7 +130,7 @@ public function __construct(
* We can't extend default execute method, because it works only with POST requests
*
* @return Redirect
* @throws NotFoundException
* @throws NotFoundException|SessionException
*/
public function execute(): Redirect
{
Expand Down Expand Up @@ -193,7 +183,7 @@ public function execute(): Redirect
throw new LocalizedException(__($result));
}
if ($wishlist->isObjectNew()) {
$wishlist->save();
$this->wishlistResource->save($wishlist);
}
$this->eventManager->dispatch(
'wishlist_add_product',
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magmodules/magento2-sooqr",
"description": "Sooqr integration for Magento 2",
"type": "magento2-module",
"version": "2.1.7",
"version": "2.1.8",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<sooqr_general>
<general>
<enable>1</enable>
<version>v2.1.7</version>
<version>v2.1.8</version>
</general>
<credentials>
<environment>production</environment>
Expand Down
114 changes: 68 additions & 46 deletions view/frontend/templates/search.phtml
Original file line number Diff line number Diff line change
@@ -1,52 +1,74 @@
<?php

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Helper\SecureHtmlRenderer;
use Magmodules\Sooqr\ViewModel\Search;
use Magento\Framework\Escaper;

/**
* @var \Magento\Framework\View\Element\Template $block
* @var \Magmodules\Sooqr\ViewModel\Search $viewModel
* @var Template $block
* @var Search $viewModel
* @var SecureHtmlRenderer $secureRenderer
* @var Escaper $escaper
*/
$viewModel = $block->getData('view_model');

if (!$viewModel->isSearchEnabled()) {
return;
}

if ($viewModel->getLoaderType() == 'custom'):
$scriptString = '
(function() {
var ws = document.createElement(\'script\'); ws.type = \'text/javascript\'; ws.async = true;
ws.src = (\'https:\' === document.location.protocol ? \'https://\' : \'http://\')
+ \'' . $escaper->escapeUrl($viewModel->getSooqrScriptUri()) . '\';
var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ws, s);
})();';
else:
$scriptString = '
var _wssq = _wssq || [];
_wssq.push([\'_load\', {\'suggest\': ' . /* @noEscape */ $viewModel->getSooqrOptions() . '}]);
_wssq.push([\'suggest._setPosition\', \'screen-middle\']);
_wssq.push([\'suggest._setLocale\', \'' . $escaper->escapeHtml($viewModel->getSooqrLanguage()) .'\']);';

if ($viewModel->isTrackingEnabled()):
$scriptString .= '
(function() {
var ws = document.createElement(\'script\'); ws.type = \'text/javascript\'; ws.async = true;
ws.src = (\'https:\' == document.location.protocol ? \'https://\' : \'http://\')
+ \'' . $escaper->escapeUrl($viewModel->getSooqrInsightsUri()) . '\';
var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ws, s);
})();';
endif;

$scriptString .= '
(function () {
var ws = document.createElement(\'script\');
ws.type = \'text/javascript\';
ws.async = true;
ws.src = (\'https:\' === document.location.protocol ? \'https://\' : \'http://\')
+ \'' . $escaper->escapeUrl($viewModel->getSooqrScriptUri()) . '\';
var s = document.getElementsByTagName(\'script\')[0];
s.parentNode.insertBefore(ws, s);
})();';
endif;

// @phpstan-ignore-next-line
if (isset($secureRenderer)) {
// phpcs:ignore
echo /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false);
} else {
echo /* @noEscape */ '<script>' . $scriptString . '</script>';
}
?>
<?php if ($viewModel->isSearchEnabled()): ?>
<?php if ($viewModel->getLoaderType() == 'custom'): ?>
<script>
(function() {
var ws = document.createElement('script'); ws.type = 'text/javascript'; ws.async = true;
ws.src = ('https:' === document.location.protocol ? 'https://' : 'http://')
+ '<?= $block->escapeUrl($viewModel->getSooqrScriptUri()) ?>';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ws, s);
})();
</script>
<?php else: ?>
<script>
var _wssq = _wssq || [];
_wssq.push(['_load', {'suggest': <?= /* @noEscape */ $viewModel->getSooqrOptions() ?>}]);
_wssq.push(['suggest._setPosition', 'screen-middle']);
_wssq.push(['suggest._setLocale', '<?= $block->escapeHtml($viewModel->getSooqrLanguage()) ?>']);
<?php if ($viewModel->isTrackingEnabled()): ?>
(function() {
var ws = document.createElement('script'); ws.type = 'text/javascript'; ws.async = true;
ws.src = ('https:' == document.location.protocol ? 'https://' : 'http://')
+ '<?= $block->escapeUrl($viewModel->getSooqrInsightsUri()) ?>';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ws, s);
})();
<?php endif; ?>
(function () {
var ws = document.createElement('script');
ws.type = 'text/javascript';
ws.async = true;
ws.src = ('https:' === document.location.protocol ? 'https://' : 'http://')
+ '<?= $block->escapeUrl($viewModel->getSooqrScriptUri()) ?>';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ws, s);
})();
</script>
<?php endif; ?>
<?php if ($viewModel->isAjaxAddToCartEnabled()): ?>
<script type="text/x-magento-init">
{
"*": {
"Magmodules_Sooqr/js/add-to-cart": {}
}

<?php if ($viewModel->isAjaxAddToCartEnabled()): ?>
<script type="text/x-magento-init">
{
"*": {
"Magmodules_Sooqr/js/add-to-cart": {}
}
</script>
<?php endif; ?>
<?php endif; ?>
}
</script>
<?php endif; ?>
80 changes: 42 additions & 38 deletions view/frontend/web/js/add-to-cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,52 @@ define([
], function ($, customerData) {
return function() {
document.addEventListener('submit', (e) => {
e.preventDefault();


const form = e.target.closest('form');
if (!form || !form.classList.contains('sqrAddToCart')) {
return;
}

e.preventDefault();

const button = form.querySelector('button');
const minicart = document.querySelector('[data-block="minicart"]');

if (form.classList.contains('sqrAddToCart')) {
$.ajax({
type: 'GET',
url: $(form).attr('action'),
data: $(form).serialize(),

beforeSend() {
button.setAttribute('disabled', 'disabled');
minicart.dispatchEvent(new CustomEvent('contentLoading'));
},

success() {
customerData.invalidate(['cart']);
customerData.reload(['cart'], true);
},

error() {
$('.sqr-closeButton').trigger('click');
const customerMessages = customerData.get('messages')() || {},
messages = customerMessages.messages || [];

messages.push({
text: 'Something went wrong while adding product to the cart. Please reload page and try again.',
type: 'error'
});

customerMessages.messages = messages;
customerData.set('messages', customerMessages);
},

complete() {
button.removeAttribute('disabled');
minicart.dispatchEvent(new CustomEvent('contentUpdated'));
}
});
}
$.ajax({
type: 'GET',
url: $(form).attr('action'),
data: $(form).serialize(),

beforeSend() {
button.setAttribute('disabled', 'disabled');
minicart.dispatchEvent(new CustomEvent('contentLoading'));
},

success() {
customerData.invalidate(['cart']);
customerData.reload(['cart'], true);
},

error() {
$('.sqr-closeButton').trigger('click');
const customerMessages = customerData.get('messages')() || {},
messages = customerMessages.messages || [];

messages.push({
text: 'Something went wrong while adding product to the cart. Please reload page and try again.',
type: 'error'
});

customerMessages.messages = messages;
customerData.set('messages', customerMessages);
},

complete() {
button.removeAttribute('disabled');
minicart.dispatchEvent(new CustomEvent('contentUpdated'));
}
});

});
}
});

0 comments on commit fa62c7a

Please sign in to comment.