Skip to content

Commit

Permalink
Merge pull request #1558 from magento-tango/2.1-DEVELOP-PR
Browse files Browse the repository at this point in the history
Bugs
- MAGETWO-70892 [Backport] - [Google Tag Manager] Ajax "Add to Cart" / "Remove from Cart" do not fire any events - for 2.1
- MAGETWO-71398 Attribute values on store view level not searchable
- MAGETWO-69560 [Backport] - Out of stock configurable product displays with zero price - for 2.1
- MAGETWO-70606 [Backport] - [GITHUB] Simple product videos display the thumbnail image rather than the embedded video player. #6360 - for 2.1
  • Loading branch information
VladimirZaets authored Oct 6, 2017
2 parents 0ccdb85 + 94d27d4 commit fdf7480
Show file tree
Hide file tree
Showing 27 changed files with 1,094 additions and 171 deletions.
4 changes: 4 additions & 0 deletions app/code/Magento/Catalog/Block/Product/View/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public function getGalleryImagesJson()
'caption' => $image->getLabel(),
'position' => $image->getPosition(),
'isMain' => $this->isMainImage($image),
'type' => str_replace('external-', '', $image->getMediaType()),
'videoUrl' => $image->getVideoUrl(),
];
}
if (empty($imagesItems)) {
Expand All @@ -127,6 +129,8 @@ public function getGalleryImagesJson()
'caption' => '',
'position' => '0',
'isMain' => true,
'type' => 'image',
'videoUrl' => null,
];
}
return json_encode($imagesItems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

?>
<?php
/** @var \Magento\Catalog\Pricing\Render\FinalPriceBox $block */
Expand All @@ -14,11 +17,14 @@ $priceLabel = ($block->getPriceLabel() !== null)
: '';
?>
<p class="price-as-configured">
<?php /* @escapeNotVerified */ echo $block->renderAmount($configuredPrice->getAmount(), [
'display_label' => $priceLabel,
'price_id' => $block->getPriceId('product-price-'),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]); ?>
<?php if ($configuredPrice->getAmount()->getValue() !== null): ?>
<?php /* @noEscape */
echo $block->renderAmount($configuredPrice->getAmount(), [
'display_label' => $priceLabel,
'price_id' => $block->getPriceId('product-price-'),
'price_type' => 'finalPrice',
'include_container' => true,
'schema' => $schema
]); ?>
<?php endif; ?>
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ $_helper = $this->helper('Magento\Catalog\Helper\Output');
<div class="actions-primary"<?php echo strpos($pos, $viewMode . '-primary') ? $position : ''; ?>>
<?php if ($_product->isSaleable()): ?>
<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
<form data-role="tocart-form" data-product-sku="<?php echo $block->escapeHtml($_product->getSku()); ?>"
action="<?php echo $block->escapeHtml($postParams['action']); ?>" method="post">
<input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
<input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
<?php echo $block->getBlockHtml('formkey')?>
Expand Down Expand Up @@ -121,7 +122,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": "<?php /* @escapeNotVerified */ echo $_product->getSku() ?>"
}
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
</div>
</div>
<?php endif; ?>
<script type="text/x-magento-init">
<?php if ($block->isRedirectToCartEnabled()) : ?>
<script type="text/x-magento-init">
{
"#product_addtocart_form": {
"Magento_Catalog/product/view/validation": {
Expand All @@ -49,13 +50,11 @@
}
}
</script>
<?php if (!$block->isRedirectToCartEnabled()) : ?>
<script type="text/x-magento-init">
<?php else : ?>
<script type="text/x-magento-init">
{
"#product_addtocart_form": {
"catalogAddToCart": {
"bindSubmit": false
}
"Magento_Catalog/js/validate-product": {}
}
}
</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="<?php /* @escapeNotVerified */ echo $block->getSubmitUrl($_product) ?>" method="post"
<form data-product-sku="<?php echo $block->escapeHtml($_product->getSku()) ?>"
action="<?php echo $block->escapeHtml($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="<?php /* @escapeNotVerified */ echo $_product->getId() ?>" />
<input type="hidden" name="selected_configurable_option" value="" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ define([
}
},
success: function(res) {
$(document).trigger('ajax:addToCart', form.data().productSku);

if (self.isLoaderEnabled()) {
$('body').trigger(self.options.processStop);
}
Expand Down
48 changes: 48 additions & 0 deletions app/code/Magento/Catalog/view/frontend/web/js/validate-product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define([
'jquery',
'mage/mage',
'Magento_Catalog/product/view/validation',
'catalogAddToCart'
], function ($) {
'use strict';

$.widget('mage.productValidate', {
options: {
bindSubmit: false,
radioCheckboxClosest: '.nested'
},

/**
* Uses Magento's validation widget for the form object.
* @private
*/
_create: function () {
var bindSubmit = this.options.bindSubmit;

this.element.validation({
radioCheckboxClosest: this.options.radioCheckboxClosest,

/**
* Uses catalogAddToCart widget as submit handler.
* @param {Object} form
* @returns {Boolean}
*/
submitHandler: function (form) {
var jqForm = $(form).catalogAddToCart({
bindSubmit: bindSubmit
});

jqForm.catalogAddToCart('submitForm', jqForm);

return false;
}
});
}
});

return $.mage.productValidate;
});
Original file line number Diff line number Diff line change
Expand Up @@ -300,28 +300,40 @@ public function getProductAttributes($storeId, array $productIds, array $attribu
foreach ($attributeTypes as $backendType => $attributeIds) {
if ($attributeIds) {
$tableName = $this->getTable('catalog_product_entity_' . $backendType);
$selects[] = $this->connection->select()->from(
['t_default' => $tableName],
[$linkField, 'attribute_id']

$select = $this->connection->select()->from(
['t' => $tableName],
[
$linkField => 't.' . $linkField,
'attribute_id' => 't.attribute_id',
'value' => $this->unifyField($ifStoreValue, $backendType),
]
)->joinLeft(
['t_store' => $tableName],
$this->connection->quoteInto(
't_default.' . $linkField . '=t_store.' . $linkField .
' AND t_default.attribute_id=t_store.attribute_id' .
't.' . $linkField . '=t_store.' . $linkField .
' AND t.attribute_id=t_store.attribute_id' .
' AND t_store.store_id = ?',
$storeId
),
['value' => $this->unifyField($ifStoreValue, $backendType)]
)->where(
't_default.store_id = ?',
0
[]
)->joinLeft(
['t_default' => $tableName],
$this->connection->quoteInto(
't.' . $linkField . '=t_default.' . $linkField .
' AND t.attribute_id=t_default.attribute_id' .
' AND t_default.store_id = ?',
0
),
[]
)->where(
't_default.attribute_id IN (?)',
't.attribute_id IN (?)',
$attributeIds
)->where(
't_default.' . $linkField . ' IN (?)',
't.' . $linkField . ' IN (?)',
array_keys($productLinkFieldsToEntityIdMap)
);
)->distinct();
$selects[] = $select;
}
}

Expand Down
11 changes: 8 additions & 3 deletions app/code/Magento/Checkout/view/frontend/web/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ define([

_removeItem: function (elem) {
var itemId = elem.data('cart-item');

this._ajax(this.options.url.remove, {
item_id: itemId
}, elem, this._removeItemAfter);
Expand All @@ -185,11 +186,15 @@ define([
/**
* Update content after item remove
*
* @param elem
* @param response
* @param {Object} elem
* @private
*/
_removeItemAfter: function (elem, response) {
_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
@@ -0,0 +1,57 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Block\Plugin\Product\Media;

use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Catalog\Model\Product;

/**
* Provides a serialized media gallery data for configurable product options.
*/
class Gallery
{
/**
* @param \Magento\Catalog\Block\Product\View\Gallery $subject
* @param string $result
* @return string
*/
public function afterGetOptionsMediaGalleryDataJson(
\Magento\Catalog\Block\Product\View\Gallery $subject,
$result
) {
$result = json_decode($result, true);
$parentProduct = $subject->getProduct();
if ($parentProduct->getTypeId() == Configurable::TYPE_CODE) {
/** @var Configurable $productType */
$productType = $parentProduct->getTypeInstance();
$products = $productType->getUsedProducts($parentProduct);
/** @var Product $product */
foreach ($products as $product) {
$key = $product->getId();
$result[$key] = $this->getProductGallery($product);
}
}
return json_encode($result);
}

/**
* @param Product $product
* @return array
*/
private function getProductGallery($product)
{
$result = [];
$images = $product->getMediaGalleryImages();
foreach ($images as $image) {
$result[] = [
'mediaType' => $image->getMediaType(),
'videoUrl' => $image->getVideoUrl(),
'isBase' => $product->getImage() == $image->getFile(),
];
}
return $result;
}
}
Loading

0 comments on commit fdf7480

Please sign in to comment.