Skip to content

Commit

Permalink
Merge pull request #578 from magento-troll/troll_bugfix
Browse files Browse the repository at this point in the history
MAGETWO-54365 [GitHub] Bundle Products - The price calculation fails for user defined quantity #4446
MAGETWO-47017 [Github] Add Configurable Product To Cart from Category Page #2574 #5850 #5882 #6572 #5558 #4184
  • Loading branch information
rganin authored Nov 9, 2016
2 parents 6619bdf + 0112e42 commit e643a67
Show file tree
Hide file tree
Showing 50 changed files with 1,511 additions and 57 deletions.
4 changes: 4 additions & 0 deletions app/code/Magento/Bundle/view/base/web/js/price-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ define([
case 'hidden':
optionHash = 'bundle-option-' + optionName + '##' + optionValue;
optionQty = optionConfig[optionValue].qty || 0;
canQtyCustomize = optionConfig[optionValue].customQty === '1';
qtyField = element.data('qtyField');
qtyField.data('option', element);
toggleQtyField(qtyField, optionQty, optionId, optionValue, canQtyCustomize);
tempChanges = utils.deepClone(optionConfig[optionValue].prices);
tempChanges = applyTierPrice(tempChanges, optionQty, optionConfig);
tempChanges = applyQty(tempChanges, optionQty);
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Product/AbstractProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function __construct(\Magento\Catalog\Block\Product\Context $context, arr
*/
public function getAddToCartUrl($product, $additional = [])
{
if ($product->getTypeInstance()->hasRequiredOptions($product)) {
if (!$product->getTypeInstance()->isPossibleBuyFromList($product)) {
if (!isset($additional['_escape'])) {
$additional['_escape'] = true;
}
Expand Down
11 changes: 11 additions & 0 deletions app/code/Magento/Catalog/Model/Product/Type/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -1092,4 +1092,15 @@ public function getAssociatedProducts($product)
{
return [];
}

/**
* Check if product can be potentially buyed from the category page or some other list
*
* @param \Magento\Catalog\Model\Product $product
* @return bool
*/
public function isPossibleBuyFromList($product)
{
return !$this->hasRequiredOptions($product);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ public function testGetAddToCartPostParams()
];

$this->typeInstanceMock->expects($this->once())
->method('hasRequiredOptions')
->method('isPossibleBuyFromList')
->with($this->equalTo($this->productMock))
->will($this->returnValue(false));
->will($this->returnValue(true));
$this->cartHelperMock->expects($this->any())
->method('getAddUrl')
->with($this->equalTo($this->productMock), $this->equalTo([]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ define([
}

if (res.backUrl) {
var eventData = {
'form': form,
'redirectParameters': []
}
// trigger global event, so other modules will be able add parameters to redirect url
$('body').trigger('catalogCategoryAddToCartRedirect', eventData);
if (eventData.redirectParameters.length > 0) {
var parameters = res.backUrl.split('#');
parameters.push(eventData.redirectParameters.join('&'));
res.backUrl = parameters.join('#');
}
window.location = res.backUrl;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1287,4 +1287,19 @@ private function getCatalogConfig()
}
return $this->catalogConfig;
}

/**
* @inheritdoc
*/
public function isPossibleBuyFromList($product)
{
$isAllCustomOptionsDisplayed = true;
foreach ($this->getConfigurableAttributes($product) as $attribute) {
$eavAttribute = $attribute->getProductAttribute();

$isAllCustomOptionsDisplayed = ($isAllCustomOptionsDisplayed && $eavAttribute->getUsedInProductListing());
}

return $isAllCustomOptionsDisplayed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
<?php /** @var $block \Magento\Swatches\Block\Product\Renderer\Configurable */ ?>
<div class="swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>"></div>
<script>
require(["jquery", "jquery/ui", "Magento_Swatches/js/swatch-renderer"], function ($) {
$('.swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>').SwatchRenderer({
selectorProduct: '.product-item-details',
onlySwatches: true,
enableControlLabel: false,
numberToShow: <?php /* @escapeNotVerified */ echo $block->getNumberSwatchesPerProduct(); ?>,
jsonConfig: <?php /* @escapeNotVerified */ echo $block->getJsonConfig(); ?>,
jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $block->getJsonSwatchConfig(); ?>,
mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'
});
require(
["jquery", "jquery/ui", "Magento_Swatches/js/swatch-renderer", "Magento_Swatches/js/catalog-add-to-cart"],
function ($) {
$('.swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>').SwatchRenderer({
selectorProduct: '.product-item-details',
onlySwatches: true,
enableControlLabel: false,
numberToShow: <?php /* @escapeNotVerified */ echo $block->getNumberSwatchesPerProduct(); ?>,
jsonConfig: <?php /* @escapeNotVerified */ echo $block->getJsonConfig(); ?>,
jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $block->getJsonSwatchConfig(); ?>,
mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'
});
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
require([
'jquery'
], function ($) {
'use strict';

$('body').on('catalogCategoryAddToCartRedirect', function (event, data) {
$(data.form).find('[name*="super"]').each(function (index, item) {
var $item = $(item);

data.redirectParameters.push($item.attr('data-attr-name') + '=' + $item.val());
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ define([
*/
_init: function () {
if (this.options.jsonConfig !== '' && this.options.jsonSwatchConfig !== '') {
// store unsorted attributes
this.options.jsonConfig.mappedAttributes = _.clone(this.options.jsonConfig.attributes);
this._sortAttributes();
this._RenderControls();
$(this.element).trigger('swatch.initialized');
Expand Down Expand Up @@ -617,6 +619,7 @@ define([
$parent.attr('option-selected', $this.attr('option-id')).find('.selected').removeClass('selected');
$label.text($this.attr('option-label'));
$input.val($this.attr('option-id'));
$input.attr('data-attr-name', this._getAttributeCodeById(attributeId));
$this.addClass('selected');
$widget._toggleCheckedAttributes($this, $wrapper);
}
Expand All @@ -633,6 +636,19 @@ define([
$input.trigger('change');
},

/**
* Get human readable attribute code (eg. size, color) by it ID from configuration
*
* @param {Number} attributeId
* @returns {*}
* @private
*/
_getAttributeCodeById: function (attributeId) {
var attribute = this.options.jsonConfig.mappedAttributes[attributeId];

return attribute ? attribute.code : attributeId;
},

/**
* Toggle accessibility attributes
*
Expand Down Expand Up @@ -1104,7 +1120,7 @@ define([
params = $.parseQuery(window.location.href.substr(hashIndex + 1));

selectedAttributes = _.invert(_.mapObject(_.invert(params), function (attributeId) {
var attribute = this.options.jsonConfig.attributes[attributeId];
var attribute = this.options.jsonConfig.mappedAttributes[attributeId];

return attribute ? attribute.code : attributeId;
}.bind(this)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<selection_qty>
<selector>[name$='[selection_qty]']</selector>
</selection_qty>
<user_defined>
<selector>[name$='[selection_can_change_qty]']</selector>
<input>checkbox</input>
</user_defined>
<getProductName>
<selector>span[data-index="name"]</selector>
</getProductName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

namespace Magento\Bundle\Test\Block\Catalog\Product;

use Magento\Bundle\Test\Block\Catalog\Product\View\Summary;
use Magento\Bundle\Test\Block\Catalog\Product\View\Type\Bundle;
use Magento\Bundle\Test\Fixture\BundleProduct;
use Magento\Mtf\Client\Locator;
use Magento\Mtf\Fixture\FixtureInterface;
use Magento\Mtf\Fixture\InjectableFixture;

/**
* Class View
Expand Down Expand Up @@ -46,6 +45,13 @@ class View extends \Magento\Catalog\Test\Block\Product\View
*/
protected $newsletterFormSelector = '#newsletter-validate-detail[novalidate="novalidate"]';

/**
* Summary Block selector.
*
* @var string
*/
private $summaryBlockSelector = '#bundleSummary';

/**
* Get bundle options block.
*
Expand All @@ -59,6 +65,19 @@ public function getBundleBlock()
);
}

/**
* Get bundle Summary block.
*
* @return Summary
*/
public function getBundleSummaryBlock()
{
return $this->blockFactory->create(
Summary::class,
['element' => $this->_rootElement->find($this->summaryBlockSelector)]
);
}

/**
* Click "Customize and add to cart button".
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Bundle\Test\Block\Catalog\Product\View;

use Magento\Bundle\Test\Block\Catalog\Product\View\Summary\ConfiguredPrice;

/**
* Bundle Summary block.
*/
class Summary extends \Magento\Catalog\Test\Block\Product\View
{
/**
* Configured Price block selector.
*
* @var string
*/
private $configuredPriceBlockSelector = '.price-configured_price';

/**
* Get configured price block.
*
* @return ConfiguredPrice
*/
public function getConfiguredPriceBlock()
{
return $this->blockFactory->create(
ConfiguredPrice::class,
['element' => $this->_rootElement->find($this->configuredPriceBlockSelector)]
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Bundle\Test\Block\Catalog\Product\View\Summary;

/**
* This class is used to access the price related information from the storefront.
*/
class ConfiguredPrice extends \Magento\Catalog\Test\Block\AbstractPriceBlock
{
/**
* Mapping for different type of price.
*
* @var array
*/
protected $mapTypePrices = [
'configured_price' => [
'selector' => '.price',
]
];

/**
* This method returns the price represented by the block.
*
* @param string $currency
* @return string|null
*/
public function getPrice($currency = '$')
{
return $this->getTypePrice('configured_price', $currency);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public function getOptions(FixtureInterface $product)

/** @var SimpleElement $optionElement */
$optionElement = $listFormOptions[$title];
$getTypeData = 'get' . $this->optionNameConvert($option['type']) . 'Data';
$getTypeData = 'get' . $this->optionNameConvert($option['frontend_type']) . 'Data';

$optionData = $this->$getTypeData($optionElement);
$optionData['title'] = $title;
$optionData['type'] = $option['type'];
$optionData['type'] = $option['frontend_type'];
$optionData['is_require'] = $optionElement->find($this->required, Locator::SELECTOR_XPATH)->isVisible()
? 'Yes'
: 'No';
Expand Down Expand Up @@ -266,7 +266,7 @@ public function fillBundleOptions($bundleOptions)
/** @var Option $optionBlock */
$optionBlock = $this->blockFactory->create(
'Magento\Bundle\Test\Block\Catalog\Product\View\Type\Option\\'
. $this->optionNameConvert($option['type']),
. $this->optionNameConvert($option['frontend_type']),
['element' => $this->_rootElement->find($selector, Locator::SELECTOR_XPATH)]
);
$optionBlock->fillOption($option['value']);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Bundle\Test\Block\Catalog\Product\View\Type\Option\Element;

use Magento\Mtf\Client\Element\SimpleElement;

/**
* Typified element class for qty element.
*/
class Qty extends SimpleElement
{
/**
* "Backspace" key code.
*/
const BACKSPACE = "\xEE\x80\x83";

/**
* "RIGHT" key code.
*/
const RIGHT = "\xEE\x80\x94";

/**
* Set the value.
*
* @param string|array $value
* @return void
*/
public function setValue($value)
{
$this->keys([self::RIGHT, self::BACKSPACE, $value]);
$this->context->click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Bundle\Test\Block\Catalog\Product\View\Type\Option;

use Magento\Bundle\Test\Block\Catalog\Product\View\Type\Option;

/**
* Bundle option hidden type.
*/
class Hidden extends Option
{
//
}
Loading

0 comments on commit e643a67

Please sign in to comment.