Skip to content

Commit a8f1eaa

Browse files
author
Klymenko, Volodymyr(vklymenko)
committed
Merge pull request #373 from magento-dragons/epam-swatches
[Epam - Swatches] Merge pull requests (EE: #5, CE: #10)
2 parents 0fecd76 + 0c4432c commit a8f1eaa

File tree

12 files changed

+164
-18
lines changed

12 files changed

+164
-18
lines changed

app/code/Magento/Catalog/Block/Product/AbstractProduct.php

+44
Original file line numberDiff line numberDiff line change
@@ -598,4 +598,48 @@ public function isRedirectToCartEnabled()
598598
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
599599
);
600600
}
601+
602+
/**
603+
* Retrieve product details html
604+
*
605+
* @param \Magento\Catalog\Model\Product $product
606+
* @return mixed
607+
*/
608+
public function getProductDetailsHtml(\Magento\Catalog\Model\Product $product)
609+
{
610+
$renderer = $this->getDetailsRenderer($product->getTypeId());
611+
if ($renderer) {
612+
$renderer->setProduct($product);
613+
return $renderer->toHtml();
614+
}
615+
return '';
616+
}
617+
618+
/**
619+
* @param null $type
620+
* @return bool|\Magento\Framework\View\Element\AbstractBlock
621+
*/
622+
public function getDetailsRenderer($type = null)
623+
{
624+
if ($type === null) {
625+
$type = 'default';
626+
}
627+
$rendererList = $this->getDetailsRendererList();
628+
if ($rendererList) {
629+
return $rendererList->getRenderer($type, 'default');
630+
}
631+
return null;
632+
}
633+
634+
/**
635+
* @return \Magento\Framework\View\Element\RendererList
636+
*/
637+
protected function getDetailsRendererList()
638+
{
639+
return $this->getDetailsRendererListName() ? $this->getLayout()->getBlock(
640+
$this->getDetailsRendererListName()
641+
) : $this->getChildBlock(
642+
'details.renderers'
643+
);
644+
}
601645
}

app/code/Magento/Catalog/view/frontend/layout/catalog_category_view.xml

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml">
1919
<block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">
2020
<container name="category.product.list.additional" as="additional" />
21+
<block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
22+
<block class="Magento\Framework\View\Element\Template" as="default"/>
23+
</block>
2124
<block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="product/list/toolbar.phtml">
2225
<block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
2326
<!-- The following code shows how to set your own pager increments -->

app/code/Magento/Catalog/view/frontend/templates/product/list.phtml

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ $imageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\I
6969
</strong>
7070
<?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
7171
<?php echo $block->getProductPrice($_product) ?>
72+
<?php echo $block->getProductDetailsHtml($_product); ?>
7273

7374
<div class="product-item-inner">
7475
<div class="product actions product-item-actions"<?php echo strpos($pos, $viewMode . '-actions') ? $position : ''; ?>>
@@ -94,7 +95,7 @@ $imageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\I
9495
</div>
9596
<div data-role="add-to-links" class="actions-secondary"<?php echo strpos($pos, $viewMode . '-secondary') ? $position : ''; ?>>
9697
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
97-
<a href="#"
98+
<a href="#"
9899
class="action towishlist"
99100
title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
100101
aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
@@ -107,7 +108,7 @@ $imageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\I
107108
<?php
108109
$compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
109110
?>
110-
<a href="#"
111+
<a href="#"
111112
class="action tocompare"
112113
title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
113114
aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"

app/code/Magento/CatalogSearch/view/frontend/layout/catalogsearch_advanced_result.xml

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<action method="setToolbarBlockName">
2323
<argument name="name" xsi:type="string">product_list_toolbar</argument>
2424
</action>
25+
<block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
26+
<block class="Magento\Framework\View\Element\Template" as="default"/>
27+
</block>
2528
</block>
2629
<action method="setListOrders"/>
2730
<action method="setListModes"/>

app/code/Magento/CatalogSearch/view/frontend/layout/catalogsearch_result_index.xml

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<action method="setToolbarBlockName">
2424
<argument name="name" xsi:type="string">product_list_toolbar</argument>
2525
</action>
26+
<block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
27+
<block class="Magento\Framework\View\Element\Template" as="default"/>
28+
</block>
2629
</block>
2730
<action method="setListOrders"/>
2831
<action method="setListModes"/>

app/code/Magento/ConfigurableProduct/Model/SuggestedAttributeList.php

+51-11
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,45 @@ class SuggestedAttributeList
1414
*
1515
* @var \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory
1616
*/
17-
protected $_attributeColFactory;
17+
protected $attributeCollectionFactory;
1818

1919
/**
2020
* Catalog resource helper
2121
*
2222
* @var \Magento\Catalog\Model\Resource\Helper
2323
*/
24-
protected $_resourceHelper;
24+
protected $resourceHelper;
2525

2626
/**
27-
* @param \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeColFactory
27+
* Application Event Dispatcher
28+
*
29+
* @var \Magento\Framework\Event\ManagerInterface
30+
*/
31+
protected $eventManager;
32+
33+
/**
34+
* Object Factory
35+
*
36+
* @var \Magento\Framework\ObjectFactory
37+
*/
38+
protected $objectFactory;
39+
40+
/**
41+
* @param \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory
2842
* @param \Magento\Catalog\Model\Resource\Helper $resourceHelper
43+
* @param \Magento\Framework\Event\ManagerInterface $eventManager
44+
* @param \Magento\Framework\ObjectFactory $objectFactory
2945
*/
3046
public function __construct(
31-
\Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeColFactory,
32-
\Magento\Catalog\Model\Resource\Helper $resourceHelper
47+
\Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory,
48+
\Magento\Catalog\Model\Resource\Helper $resourceHelper,
49+
\Magento\Framework\Event\ManagerInterface $eventManager,
50+
\Magento\Framework\ObjectFactory $objectFactory
3351
) {
34-
$this->_attributeColFactory = $attributeColFactory;
35-
$this->_resourceHelper = $resourceHelper;
52+
$this->attributeCollectionFactory = $attributeCollectionFactory;
53+
$this->resourceHelper = $resourceHelper;
54+
$this->objectFactory = $objectFactory;
55+
$this->eventManager = $eventManager;
3656
}
3757

3858
/**
@@ -43,12 +63,14 @@ public function __construct(
4363
*/
4464
public function getSuggestedAttributes($labelPart)
4565
{
46-
$escapedLabelPart = $this->_resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
66+
$escapedLabelPart = $this->resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
67+
$availableFrontendTypes = $this->getAvailableFrontendTypes();
68+
4769
/** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
48-
$collection = $this->_attributeColFactory->create();
70+
$collection = $this->attributeCollectionFactory->create();
4971
$collection->addFieldToFilter(
50-
'frontend_input',
51-
'select'
72+
'main_table.frontend_input',
73+
['in' => $availableFrontendTypes->getData('values')]
5274
)->addFieldToFilter(
5375
'frontend_label',
5476
['like' => $escapedLabelPart]
@@ -79,4 +101,22 @@ public function getSuggestedAttributes($labelPart)
79101
}
80102
return $result;
81103
}
104+
105+
/**
106+
* @return \Magento\Framework\Object
107+
*/
108+
private function getAvailableFrontendTypes()
109+
{
110+
$availableFrontendTypes = $this->objectFactory->create();
111+
$availableFrontendTypes->setData(
112+
[
113+
'values' => ['select']
114+
]
115+
);
116+
$this->eventManager->dispatch(
117+
'product_suggested_attribute_frontend_type_init_after',
118+
['types_dto' => $availableFrontendTypes]
119+
);
120+
return $availableFrontendTypes;
121+
}
82122
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/SuggestedAttributeListTest.php

+37-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ class SuggestedAttributeListTest extends \PHPUnit_Framework_TestCase
2020
*/
2121
protected $attributeFactoryMock;
2222

23+
/**
24+
* @var \PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
protected $eventManagerMock;
27+
28+
/**
29+
* @var \PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
protected $objectFactoryMock;
32+
2333
/**
2434
* @var \PHPUnit_Framework_MockObject_MockObject
2535
*/
@@ -53,6 +63,20 @@ protected function setUp()
5363
'',
5464
false
5565
);
66+
$this->eventManagerMock = $this->getMock(
67+
'\Magento\Framework\Event\ManagerInterface',
68+
[],
69+
[],
70+
'',
71+
false
72+
);
73+
$this->objectFactoryMock = $this->getMock(
74+
'\Magento\Framework\ObjectFactory',
75+
['create'],
76+
[],
77+
'',
78+
false
79+
);
5680
$this->collectionMock = $this->getMock(
5781
'Magento\Catalog\Model\Resource\Product\Attribute\Collection',
5882
[],
@@ -78,7 +102,7 @@ protected function setUp()
78102
$this->returnValue($this->collectionMock)
79103
);
80104
$valueMap = [
81-
['frontend_input', 'select', $this->collectionMock],
105+
['main_table.frontend_input', ['in' => 123 ], $this->collectionMock],
82106
['frontend_label', ['like' => $this->labelPart], $this->collectionMock],
83107
['is_user_defined', 1, $this->collectionMock],
84108
['is_global', \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL, $this->collectionMock],
@@ -107,12 +131,19 @@ protected function setUp()
107131
);
108132
$this->suggestedListModel = new \Magento\ConfigurableProduct\Model\SuggestedAttributeList(
109133
$this->attributeFactoryMock,
110-
$this->resourceHelperMock
134+
$this->resourceHelperMock,
135+
$this->eventManagerMock,
136+
$this->objectFactoryMock
111137
);
112138
}
113139

114140
public function testGetSuggestedAttributesIfTheyApplicable()
115141
{
142+
$object = $this->getMock('\Magento\Framework\Object', [], [], '', false);
143+
$object->expects($this->once())->method('setData');
144+
$object->expects($this->once())->method('getData')->willReturn(123);
145+
$this->objectFactoryMock->expects($this->once())->method('create')->willReturn($object);
146+
116147
$source = $this->getMock(
117148
'Magento\Eav\Model\Entity\Attribute\Source\AbstractSource',
118149
[],
@@ -132,6 +163,10 @@ public function testGetSuggestedAttributesIfTheyApplicable()
132163

133164
public function testGetSuggestedAttributesIfTheyNotApplicable()
134165
{
166+
$object = $this->getMock('\Magento\Framework\Object', [], [], '', false);
167+
$object->expects($this->once())->method('setData');
168+
$object->expects($this->once())->method('getData')->willReturn(123);
169+
$this->objectFactoryMock->expects($this->once())->method('create')->willReturn($object);
135170
$this->attributeMock->expects($this->any())->method('getApplyTo')->will($this->returnValue(['simple']));
136171
$this->attributeMock->expects($this->never())->method('getId');
137172
$this->attributeMock->expects($this->never())->method('getFrontendLabel');

app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Options/Options.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public function getStoreOptionValues($storeId)
268268
*
269269
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute
270270
*/
271-
private function getAttributeObject()
271+
protected function getAttributeObject()
272272
{
273273
return $this->_registry->registry('entity_attribute');
274274
}

app/design/frontend/Magento/blank/etc/view.xml

+8
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@
185185
<var name="product_stock_alert_email_product_image:width">76</var>
186186
<var name="product_stock_alert_email_product_image:ratio">1</var>
187187
<var name="product_stock_alert_email_product_image:height">76</var>
188+
189+
<var name="swatch_image:width">30</var>
190+
<var name="swatch_image:ratio">0.8</var>
191+
<var name="swatch_image:height">20</var>
192+
193+
<var name="swatch_thumb:width">110</var>
194+
<var name="swatch_thumb:ratio">0.8</var>
195+
<var name="swatch_thumb:height">90</var>
188196
</vars>
189197
<vars module="Magento_Bundle">
190198
<var name="product_summary_image_size">58</var> <!-- New Product image size used for summary block-->

app/design/frontend/Magento/luma/etc/view.xml

+8
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@
190190
<var name="product_stock_alert_email_product_image:width">76</var>
191191
<var name="product_stock_alert_email_product_image:ratio">1</var>
192192
<var name="product_stock_alert_email_product_image:height">76</var>
193+
194+
<var name="swatch_image:width">30</var>
195+
<var name="swatch_image:ratio">0.8</var>
196+
<var name="swatch_image:height">20</var>
197+
198+
<var name="swatch_thumb:width">110</var>
199+
<var name="swatch_thumb:ratio">0.8</var>
200+
<var name="swatch_thumb:height">90</var>
193201
</vars>
194202
<vars module="Magento_Bundle">
195203
<var name="product_summary_image_size">58</var> <!-- New Product image size used for summary block-->

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function persist(FixtureInterface $fixture = null)
9090

9191
if ($fixture->hasData('options')) {
9292
$optionsData = $fixture->getData()['options'];
93-
foreach ($matches[1] as $key => $optionId) {
93+
foreach (array_unique($matches[1]) as $key => $optionId) {
9494
$optionsData[$key]['id'] = $optionId;
9595
}
9696
$resultData['options'] = $optionsData;

dev/tests/static/testsuite/Magento/Test/Legacy/LayoutTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ public function getAllowedActionNodeMethods()
349349
'setWrapperClass',
350350
'unsetChild',
351351
'unsetChildren',
352-
'updateButton'
352+
'updateButton',
353+
'setIsProductListingContext'
353354
];
354355
}
355356
}

0 commit comments

Comments
 (0)