Skip to content

Commit bcbc070

Browse files
author
okarpenko
committed
MAGETWO-38156: Move gift message to cart
1 parent d07be23 commit bcbc070

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

app/code/Magento/GiftMessage/Model/GiftMessageConfigProvider.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Customer\Model\Context as CustomerContext;
1212
use Magento\Framework\UrlInterface;
1313
use Magento\Framework\Locale\FormatInterface as LocaleFormat;
14+
use Magento\Framework\Data\Form\FormKey;
1415

1516
/**
1617
* Configuration provider for GiftMessage rendering on "Checkout cart" page.
@@ -49,6 +50,11 @@ class GiftMessageConfigProvider implements ConfigProviderInterface
4950
*/
5051
protected $localeFormat;
5152

53+
/**
54+
* @var FormKey
55+
*/
56+
protected $formKey;
57+
5258
/**
5359
* @param \Magento\Framework\App\Helper\Context $context
5460
* @param \Magento\GiftMessage\Api\CartRepositoryInterface $cartRepository
@@ -65,7 +71,8 @@ public function __construct(
6571
\Magento\Checkout\Model\Session $checkoutSession,
6672
HttpContext $httpContext,
6773
\Magento\Store\Model\StoreManagerInterface $storeManager,
68-
LocaleFormat $localeFormat
74+
LocaleFormat $localeFormat,
75+
FormKey $formKey
6976
) {
7077
$this->scopeConfiguration = $context->getScopeConfig();
7178
$this->cartRepository = $cartRepository;
@@ -74,6 +81,7 @@ public function __construct(
7481
$this->httpContext = $httpContext;
7582
$this->storeManager = $storeManager;
7683
$this->localeFormat = $localeFormat;
84+
$this-> formKey = $formKey;
7785
}
7886

7987
/**
@@ -107,6 +115,7 @@ public function getConfig()
107115
);
108116
$configuration['storeCode'] = $this->getStoreCode();
109117
$configuration['isCustomerLoggedIn'] = $this->isCustomerLoggedIn();
118+
$configuration['formKey'] = $this->formKey->getFormKey();
110119
$store = $this->storeManager->getStore();
111120
$configuration['baseUrl'] = $store->isFrontUrlSecure()
112121
? $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, true)

app/code/Magento/GiftMessage/view/frontend/web/js/model/gift-message.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* See COPYING.txt for license details.
44
*/
55
/*global define*/
6-
define(['Magento_Ui/js/lib/component/provider', 'underscore'],
7-
function (provider, _) {
6+
define(['Magento_Ui/js/lib/component/provider', 'underscore', 'mage/url'],
7+
function (provider, _, url) {
88
"use strict";
99
return function (itemId) {
1010
var model = {
@@ -65,13 +65,19 @@ define(['Magento_Ui/js/lib/component/provider', 'underscore'],
6565
},
6666
getAfterSubmitCallbacks: function() {
6767
var callbacks = [];
68+
callbacks.push(this.afterSubmit);
6869
_.each(this.additionalOptions, function(option) {
6970
if (_.isFunction(option.afterSubmit)) {
7071
callbacks.push(option.afterSubmit);
7172
}
7273
});
7374
return callbacks;
7475
},
76+
afterSubmit: function() {
77+
window.location.href = url.build('checkout/cart/updatePost')
78+
+ '?form_key=' + window.giftOptionsConfig.giftMessage.formKey
79+
+ '&cart[]';
80+
},
7581
getSubmitParams: function(remove) {
7682
var params = {},
7783
self = this;

0 commit comments

Comments
 (0)