Skip to content

Commit

Permalink
Merge remote-tracking branch 'tango/PR-2.2-develop' into perf_mpi
Browse files Browse the repository at this point in the history
  • Loading branch information
duhon committed Sep 9, 2017
2 parents 8752f42 + d804804 commit b5cca13
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ $numColumns = sizeof($block->getColumns());
<?php endif; ?>

<?php if (strpos($block->getRowClickCallback(), 'order.') !== false): ?>
deps.push('Magento_Sales/order/create/form')
deps.push('Magento_Sales/order/create/form');
deps.push('jquery');
<?php endif; ?>

deps.push('mage/adminhtml/grid');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ $_helper = $this->helper('Magento\Catalog\Helper\Output');
<div class="actions-primary"<?= strpos($pos, $viewMode . '-primary') ? $position : '' ?>>
<?php if ($_product->isSaleable()): ?>
<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form" action="<?= /* @escapeNotVerified */ $postParams['action'] ?>" method="post">
<form data-role="tocart-form" data-product-sku="<?= /* @NoEscape */ $_product->getSku() ?>" action="<?= /* @NoEscape */ $postParams['action'] ?>" method="post">
<input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $postParams['data']['product'] ?>">
<input type="hidden" name="<?= /* @escapeNotVerified */ Action::PARAM_NAME_URL_ENCODED ?>" value="<?= /* @escapeNotVerified */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
<?= $block->getBlockHtml('formkey') ?>
Expand Down Expand Up @@ -121,7 +121,9 @@ $_helper = $this->helper('Magento\Catalog\Helper\Output');
<script type="text/x-magento-init">
{
"[data-role=tocart-form], .form.map.checkout": {
"catalogAddToCart": {}
"catalogAddToCart": {
"product_sku": "<?= /* @NoEscape */ $_product->getSku() ?>"
}
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<?php $_product = $block->getProduct(); ?>

<div class="product-add-form">
<form action="<?= /* @escapeNotVerified */ $block->getSubmitUrl($_product) ?>" method="post"
<form data-product-sku="<?= /* @NoEscape */ $_product->getSku() ?>"
action="<?= /* @NoEscape */ $block->getSubmitUrl($_product) ?>" method="post"
id="product_addtocart_form"<?php if ($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $_product->getId() ?>" />
<input type="hidden" name="selected_configurable_option" value="" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ define([
success: function (res) {
var eventData, parameters;

$(document).trigger('ajax:addToCart', form.data().productSku);

if (self.isLoaderEnabled()) {
$('body').trigger(self.options.processStop);
}
Expand Down
11 changes: 9 additions & 2 deletions app/code/Magento/Checkout/view/frontend/web/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,17 @@ define([
},

/**
* Update content after item remove.
* Update content after item remove
*
* @param {Object} elem
* @private
*/
_removeItemAfter: function () {
_removeItemAfter: function (elem) {
var productData = customerData.get('cart')().items.find(function (item) {
return Number(elem.data('cart-item')) === Number(item['item_id']);
});

$(document).trigger('ajax:removeFromCart', productData['product_sku']);
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</head>
<body>
<referenceContainer name="after.body.start">
<block class="Magento\Framework\View\Element\Template" name="head.polyfill" as="polyfill" template="Magento_Theme::js/polyfill.phtml" before="-"/>
<block class="Magento\Framework\View\Element\Js\Components" name="head.components" as="components" template="Magento_Theme::js/components.phtml" before="-"/>
</referenceContainer>
</body>
Expand Down
132 changes: 132 additions & 0 deletions app/code/Magento/Theme/view/frontend/templates/js/polyfill.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/**
* Polyfill for local storage and session storage for old browsers and with enabled private mode.
*
* Emulates behavior of the native local storage and session storage. Adds ability to use "getItem", "setItem",
* "removeItem" methods.
*/
?>

<script>
try {
if (!window.localStorage || !window.sessionStorage) {
throw new Error();
}

localStorage.setItem('storage_test', 1);
localStorage.removeItem('storage_test');
} catch(e) {
(function () {
var Storage = function (type) {
var data;

function createCookie(name, value, days) {
var date, expires;

if (days) {
date = new Date();
date.setTime(date.getTime()+(days * 24 * 60 * 60 * 1000));
expires = '; expires=' + date.toGMTString();
} else {
expires = '';
}
document.cookie = name + '=' + value+expires+'; path=/';
}

function readCookie(name) {
var nameEQ = name + '=',
ca = document.cookie.split(';'),
i = 0,
c;

for (i=0; i < ca.length; i++) {
c = ca[i];

while (c.charAt(0) === ' ') {
c = c.substring(1,c.length);
}

if (c.indexOf(nameEQ) === 0) {
return c.substring(nameEQ.length, c.length);
}
}

return null;
}

function setData(data) {
data = encodeURIComponent(JSON.stringify(data));
createCookie(type === 'session' ? getSessionName() : 'localStorage', data, 365);
}

function clearData() {
createCookie(type === 'session' ? getSessionName() : 'localStorage', '', 365);
}

function getData() {
var data = type === 'session' ? readCookie(getSessionName()) : readCookie('localStorage');

return data ? JSON.parse(decodeURIComponent(data)) : {};
}

function getSessionName() {
if (!window.name) {
window.name = new Date().getTime();
}

return 'sessionStorage' + window.name;
}

data = getData();

return {
length: 0,
clear: function () {
data = {};
this.length = 0;
clearData();
},

getItem: function (key) {
return data[key] === undefined ? null : data[key];
},

key: function (i) {
var ctr = 0,
k;

for (k in data) {
if (ctr.toString() === i.toString()) {
return k;
} else {
ctr++
}
}

return null;
},

removeItem: function (key) {
delete data[key];
this.length--;
setData(data);
},

setItem: function (key, value) {
data[key] = value.toString();
this.length++;
setData(data);
}
};
};

window.localStorage.__proto__ = window.localStorage = new Storage('local');
window.sessionStorage.__proto__ = window.sessionStorag = new Storage('session');
})();
}
</script>

0 comments on commit b5cca13

Please sign in to comment.