Skip to content

Commit 0025497

Browse files
author
Palamar, Mykola
committed
MAGETWO-47017: [Github] Add Configurable Product To Cart from Category Page #2574 #5850 #5882 #6572 #5558
- CR changes
1 parent 92e0a75 commit 0025497

File tree

10 files changed

+32
-31
lines changed

10 files changed

+32
-31
lines changed

app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ public function testGetAddToCartPostParams()
154154
];
155155

156156
$this->typeInstanceMock->expects($this->once())
157-
->method('hasRequiredOptions')
157+
->method('isPossibleBuyFromList')
158158
->with($this->equalTo($this->productMock))
159-
->will($this->returnValue(false));
159+
->will($this->returnValue(true));
160160
$this->cartHelperMock->expects($this->any())
161161
->method('getAddUrl')
162162
->with($this->equalTo($this->productMock), $this->equalTo([]))

app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
<?php /** @var $block \Magento\Swatches\Block\Product\Renderer\Configurable */ ?>
88
<div class="swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>"></div>
99
<script>
10-
require(["jquery", "jquery/ui", "Magento_Swatches/js/swatch-renderer", "Magento_Swatches/js/catalog-add-to-cart"], function ($) {
11-
$('.swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>').SwatchRenderer({
12-
selectorProduct: '.product-item-details',
13-
onlySwatches: true,
14-
enableControlLabel: false,
15-
numberToShow: <?php /* @escapeNotVerified */ echo $block->getNumberSwatchesPerProduct(); ?>,
16-
jsonConfig: <?php /* @escapeNotVerified */ echo $block->getJsonConfig(); ?>,
17-
jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $block->getJsonSwatchConfig(); ?>,
18-
mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'
19-
});
10+
require(
11+
["jquery", "jquery/ui", "Magento_Swatches/js/swatch-renderer", "Magento_Swatches/js/catalog-add-to-cart"],
12+
function ($) {
13+
$('.swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>').SwatchRenderer({
14+
selectorProduct: '.product-item-details',
15+
onlySwatches: true,
16+
enableControlLabel: false,
17+
numberToShow: <?php /* @escapeNotVerified */ echo $block->getNumberSwatchesPerProduct(); ?>,
18+
jsonConfig: <?php /* @escapeNotVerified */ echo $block->getJsonConfig(); ?>,
19+
jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $block->getJsonSwatchConfig(); ?>,
20+
mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'
21+
});
2022
});
2123
</script>

app/code/Magento/Swatches/view/frontend/web/js/catalog-add-to-cart.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ require([
1010
$('body').on('catalogCategoryAddToCartRedirect', function (event, data) {
1111
$(data.form).find('[name*="super"]').each(function (index, item) {
1212
var $item = $(item);
13+
1314
data.redirectParameters.push($item.attr('data-attr-name') + '=' + $item.val());
1415
});
15-
})
16+
});
1617
});

app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,13 @@ define([
639639
/**
640640
* Get human readable attribute code (eg. size, color) by it ID from configuration
641641
*
642-
* @param attributeId
642+
* @param {Number} attributeId
643643
* @returns {*}
644644
* @private
645645
*/
646646
_getAttributeCodeById: function (attributeId) {
647647
var attribute = this.options.jsonConfig.mappedAttributes[attributeId];
648+
648649
return attribute ? attribute.code : attributeId;
649650
},
650651

dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductAttribute/Curl.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ public function persist(FixtureInterface $fixture = null)
118118
* @param array $data
119119
* @return array
120120
*/
121-
protected function changeStructureOfTheData(array $data) {
121+
protected function changeStructureOfTheData(array $data)
122+
{
122123
return $data;
123124
}
124125
}

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Handler/ConfigurableProduct/Curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected function prepareConfigurableMatrix(FixtureInterface $product)
172172
$keyIds[] = $attribute['options'][$optionKey]['id'];
173173
$configurableAttribute[] = sprintf(
174174
'"%s":"%s"',
175-
isset($attribute['attribute_code']) ? $attribute['attribute_code'] : $attribute['frontend_label'] ,
175+
isset($attribute['attribute_code']) ? $attribute['attribute_code'] : $attribute['frontend_label'],
176176
$attribute['options'][$optionKey]['id']
177177
);
178178
}

dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ProductList/ProductItem.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class ProductItem extends CatalogProductItem
2727
* @param \Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct $product
2828
* @return void
2929
*/
30-
public function fillData(\Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct $product) {
30+
public function fillData(\Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct $product)
31+
{
3132
$checkoutData = $product->getCheckoutData();
3233
$options = $checkoutData['options']['configurable_options'];
3334
$confAttrData = $product->getDataFieldConfig('configurable_attributes_data');
@@ -52,7 +53,8 @@ public function fillData(\Magento\ConfigurableProduct\Test\Fixture\ConfigurableP
5253
*
5354
* @param $optionId
5455
*/
55-
private function clickOnSwatch($optionId) {
56+
private function clickOnSwatch($optionId)
57+
{
5658
$selector = sprintf($this->swatchSelector, $optionId);
5759
$this->_rootElement->find($selector, Locator::SELECTOR_CSS)->click();
5860
}

dev/tests/functional/tests/app/Magento/Swatches/Test/Constraint/AssertSwatchConfigurableProductPage.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,17 @@
1717
class AssertSwatchConfigurableProductPage extends AssertProductPage
1818
{
1919
/**
20-
* Assert that configurable product with swatches displays correctly.
21-
*
22-
* @param BrowserInterface $browser
23-
* @param CatalogProductView $catalogProductView
24-
* @param FixtureInterface $product
25-
*/
20+
* {@inheritdoc}
21+
*/
2622
public function processAssert(
2723
BrowserInterface $browser,
2824
CatalogProductView $catalogProductView,
2925
FixtureInterface $product
30-
)
31-
{
26+
) {
3227
$this->product = $product;
3328
$this->productView = $catalogProductView->getProductViewWithSwatchesBlock();
3429
$this->objectManager->create(
35-
\Magento\Swatches\Test\TestStep\AddProductToCartFromCatalogCategoryPageStep ::class,
30+
\Magento\Swatches\Test\TestStep\AddProductToCartFromCatalogCategoryPageStep::class,
3631
[
3732
'product' => $product
3833
]

dev/tests/functional/tests/app/Magento/Swatches/Test/Handler/SwatchProductAttribute/Curl.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public function __construct(DataInterface $configuration, EventManagerInterface
3636
* @param array $data
3737
* @return array
3838
*/
39-
protected function changeStructureOfTheData(array $data) {
39+
protected function changeStructureOfTheData(array $data)
40+
{
4041
$data = parent::changeStructureOfTheData($data);
4142
$data['optiontext'] = $data['option'];
4243
$data['swatchtext'] = [

dev/tests/functional/tests/app/Magento/Swatches/Test/TestStep/AddProductToCartFromCatalogCategoryPageStep.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class AddProductToCartFromCatalogCategoryPageStep implements TestStepInterface
4646
*/
4747
private $cmsIndex;
4848

49-
5049
/**
5150
* @constructor
5251
* @param FixtureFactory $fixtureFactory
@@ -59,8 +58,7 @@ public function __construct(
5958
CmsIndex $cmsIndex,
6059
CatalogCategoryView $categoryView,
6160
InjectableFixture $product
62-
)
63-
{
61+
) {
6462
$this->fixtureFactory = $fixtureFactory;
6563
$this->cmsIndex = $cmsIndex;
6664
$this->categoryView = $categoryView;

0 commit comments

Comments
 (0)