Skip to content
Snippets Groups Projects
Commit bcbc0708 authored by okarpenko's avatar okarpenko
Browse files

MAGETWO-38156: Move gift message to cart

parent d07be232
No related merge requests found
...@@ -11,6 +11,7 @@ use Magento\Framework\App\Http\Context as HttpContext; ...@@ -11,6 +11,7 @@ use Magento\Framework\App\Http\Context as HttpContext;
use Magento\Customer\Model\Context as CustomerContext; use Magento\Customer\Model\Context as CustomerContext;
use Magento\Framework\UrlInterface; use Magento\Framework\UrlInterface;
use Magento\Framework\Locale\FormatInterface as LocaleFormat; use Magento\Framework\Locale\FormatInterface as LocaleFormat;
use Magento\Framework\Data\Form\FormKey;
/** /**
* Configuration provider for GiftMessage rendering on "Checkout cart" page. * Configuration provider for GiftMessage rendering on "Checkout cart" page.
...@@ -49,6 +50,11 @@ class GiftMessageConfigProvider implements ConfigProviderInterface ...@@ -49,6 +50,11 @@ class GiftMessageConfigProvider implements ConfigProviderInterface
*/ */
protected $localeFormat; protected $localeFormat;
/**
* @var FormKey
*/
protected $formKey;
/** /**
* @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\GiftMessage\Api\CartRepositoryInterface $cartRepository * @param \Magento\GiftMessage\Api\CartRepositoryInterface $cartRepository
...@@ -65,7 +71,8 @@ class GiftMessageConfigProvider implements ConfigProviderInterface ...@@ -65,7 +71,8 @@ class GiftMessageConfigProvider implements ConfigProviderInterface
\Magento\Checkout\Model\Session $checkoutSession, \Magento\Checkout\Model\Session $checkoutSession,
HttpContext $httpContext, HttpContext $httpContext,
\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Store\Model\StoreManagerInterface $storeManager,
LocaleFormat $localeFormat LocaleFormat $localeFormat,
FormKey $formKey
) { ) {
$this->scopeConfiguration = $context->getScopeConfig(); $this->scopeConfiguration = $context->getScopeConfig();
$this->cartRepository = $cartRepository; $this->cartRepository = $cartRepository;
...@@ -74,6 +81,7 @@ class GiftMessageConfigProvider implements ConfigProviderInterface ...@@ -74,6 +81,7 @@ class GiftMessageConfigProvider implements ConfigProviderInterface
$this->httpContext = $httpContext; $this->httpContext = $httpContext;
$this->storeManager = $storeManager; $this->storeManager = $storeManager;
$this->localeFormat = $localeFormat; $this->localeFormat = $localeFormat;
$this-> formKey = $formKey;
} }
/** /**
...@@ -107,6 +115,7 @@ class GiftMessageConfigProvider implements ConfigProviderInterface ...@@ -107,6 +115,7 @@ class GiftMessageConfigProvider implements ConfigProviderInterface
); );
$configuration['storeCode'] = $this->getStoreCode(); $configuration['storeCode'] = $this->getStoreCode();
$configuration['isCustomerLoggedIn'] = $this->isCustomerLoggedIn(); $configuration['isCustomerLoggedIn'] = $this->isCustomerLoggedIn();
$configuration['formKey'] = $this->formKey->getFormKey();
$store = $this->storeManager->getStore(); $store = $this->storeManager->getStore();
$configuration['baseUrl'] = $store->isFrontUrlSecure() $configuration['baseUrl'] = $store->isFrontUrlSecure()
? $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, true) ? $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, true)
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
* See COPYING.txt for license details. * See COPYING.txt for license details.
*/ */
/*global define*/ /*global define*/
define(['Magento_Ui/js/lib/component/provider', 'underscore'], define(['Magento_Ui/js/lib/component/provider', 'underscore', 'mage/url'],
function (provider, _) { function (provider, _, url) {
"use strict"; "use strict";
return function (itemId) { return function (itemId) {
var model = { var model = {
...@@ -65,6 +65,7 @@ define(['Magento_Ui/js/lib/component/provider', 'underscore'], ...@@ -65,6 +65,7 @@ define(['Magento_Ui/js/lib/component/provider', 'underscore'],
}, },
getAfterSubmitCallbacks: function() { getAfterSubmitCallbacks: function() {
var callbacks = []; var callbacks = [];
callbacks.push(this.afterSubmit);
_.each(this.additionalOptions, function(option) { _.each(this.additionalOptions, function(option) {
if (_.isFunction(option.afterSubmit)) { if (_.isFunction(option.afterSubmit)) {
callbacks.push(option.afterSubmit); callbacks.push(option.afterSubmit);
...@@ -72,6 +73,11 @@ define(['Magento_Ui/js/lib/component/provider', 'underscore'], ...@@ -72,6 +73,11 @@ define(['Magento_Ui/js/lib/component/provider', 'underscore'],
}); });
return callbacks; return callbacks;
}, },
afterSubmit: function() {
window.location.href = url.build('checkout/cart/updatePost')
+ '?form_key=' + window.giftOptionsConfig.giftMessage.formKey
+ '&cart[]';
},
getSubmitParams: function(remove) { getSubmitParams: function(remove) {
var params = {}, var params = {},
self = this; self = this;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment