-
Notifications
You must be signed in to change notification settings - Fork 16
/
Patch-Bss_AjaxCart-1.1.4-improvements-v2.patch
68 lines (62 loc) · 3.18 KB
/
Patch-Bss_AjaxCart-1.1.4-improvements-v2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
--- Controller/Index/Index.php
+++ Controller/Index/Index.php
@@ -226,7 +226,7 @@ class Index extends \Magento\Framework\App\Action\Action
$resultItem = $product->getTypeId() == \Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE ?
$this->dataObjectFactory->create()->setProduct($product)
- : $this->registry->registry('last_added_quote_item');
+ : $this->registry->registry(\Bss\AjaxCart\Model\Observer\ProductAddToCartAfter::LAST_ADDED_QUOTE_ITEM_KEY);
return $this->returnResult($resultItem, $this->relatedAdded);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addNoticeMessage(
@@ -235,6 +235,7 @@ class Index extends \Magento\Framework\App\Action\Action
$result = [];
$result['error'] = true;
+ $result['message'] = $e->getMessage();
$result['view'] = true;
$result['url'] = $this->escaper->escapeUrl(
$this->urlInterface->getUrl('ajaxcart/index/view', ['id' => $params['id']])
@@ -252,6 +252,7 @@ class Index extends \Magento\Framework\App\Action\Action
$result = [];
$result['error'] = true;
+ $result['message'] = __('We can\'t add this item to your shopping cart right now.');
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$resultJson->setData($result);
@@ -330,6 +330,10 @@ class Index extends \Magento\Framework\App\Action\Action
$this->messageManager->addSuccessMessage($message);
$result['popup'] = $html;
+ $this->_eventManager->dispatch(
+ 'bss_ajaxcart_result',
+ ['subject' => $this, 'item' => $resultItem, 'request' => $this->getRequest(), 'result' => &$result]
+ );
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$resultJson->setData($result);
--- Model/Observer/ProductAddToCartAfter.php
+++ Model/Observer/ProductAddToCartAfter.php
@@ -23,6 +23,11 @@ use Magento\Framework\Event\ObserverInterface;
class ProductAddToCartAfter implements ObserverInterface
{
/**
+ * Last added quote item register key
+ */
+ const LAST_ADDED_QUOTE_ITEM_KEY = 'last_added_quote_item';
+
+ /**
* Ajax cart helper.
*
* @var \Bss\AjaxCart\Helper\Data
@@ -60,7 +65,14 @@ class ProductAddToCartAfter implements ObserverInterface
{
if ($this->helper->isEnabled()) {
$resultItem = $observer->getQuoteItem();
- $this->registry->register('last_added_quote_item', $resultItem);
+ /**
+ * when have event multiple add to cart (reorder), we have trouble
+ * with last quote item
+ */
+ if ($this->registry->registry(self::LAST_ADDED_QUOTE_ITEM_KEY) !== null) {
+ $this->registry->unregister(self::LAST_ADDED_QUOTE_ITEM_KEY);
+ }
+ $this->registry->register(self::LAST_ADDED_QUOTE_ITEM_KEY, $resultItem);
}
}
}