Skip to content

Commit

Permalink
Merge pull request #373 from magento-dragons/epam-swatches
Browse files Browse the repository at this point in the history
[Epam - Swatches] Merge pull requests (EE: #5, CE: #10)
  • Loading branch information
Klymenko, Volodymyr(vklymenko) committed Jun 23, 2015
2 parents 0fecd76 + 0c4432c commit a8f1eaa
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 18 deletions.
44 changes: 44 additions & 0 deletions app/code/Magento/Catalog/Block/Product/AbstractProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,4 +598,48 @@ public function isRedirectToCartEnabled()
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* Retrieve product details html
*
* @param \Magento\Catalog\Model\Product $product
* @return mixed
*/
public function getProductDetailsHtml(\Magento\Catalog\Model\Product $product)
{
$renderer = $this->getDetailsRenderer($product->getTypeId());
if ($renderer) {
$renderer->setProduct($product);
return $renderer->toHtml();
}
return '';
}

/**
* @param null $type
* @return bool|\Magento\Framework\View\Element\AbstractBlock
*/
public function getDetailsRenderer($type = null)
{
if ($type === null) {
$type = 'default';
}
$rendererList = $this->getDetailsRendererList();
if ($rendererList) {
return $rendererList->getRenderer($type, 'default');
}
return null;
}

/**
* @return \Magento\Framework\View\Element\RendererList
*/
protected function getDetailsRendererList()
{
return $this->getDetailsRendererListName() ? $this->getLayout()->getBlock(
$this->getDetailsRendererListName()
) : $this->getChildBlock(
'details.renderers'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml">
<block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">
<container name="category.product.list.additional" as="additional" />
<block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
<block class="Magento\Framework\View\Element\Template" as="default"/>
</block>
<block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="product/list/toolbar.phtml">
<block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
<!-- The following code shows how to set your own pager increments -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ $imageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\I
</strong>
<?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
<?php echo $block->getProductPrice($_product) ?>
<?php echo $block->getProductDetailsHtml($_product); ?>

<div class="product-item-inner">
<div class="product actions product-item-actions"<?php echo strpos($pos, $viewMode . '-actions') ? $position : ''; ?>>
Expand All @@ -94,7 +95,7 @@ $imageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\I
</div>
<div data-role="add-to-links" class="actions-secondary"<?php echo strpos($pos, $viewMode . '-secondary') ? $position : ''; ?>>
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
<a href="#"
<a href="#"
class="action towishlist"
title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
Expand All @@ -107,7 +108,7 @@ $imageBlock = $block->getLayout()->createBlock('Magento\Catalog\Block\Product\I
<?php
$compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
?>
<a href="#"
<a href="#"
class="action tocompare"
title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<action method="setToolbarBlockName">
<argument name="name" xsi:type="string">product_list_toolbar</argument>
</action>
<block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
<block class="Magento\Framework\View\Element\Template" as="default"/>
</block>
</block>
<action method="setListOrders"/>
<action method="setListModes"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<action method="setToolbarBlockName">
<argument name="name" xsi:type="string">product_list_toolbar</argument>
</action>
<block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
<block class="Magento\Framework\View\Element\Template" as="default"/>
</block>
</block>
<action method="setListOrders"/>
<action method="setListModes"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,45 @@ class SuggestedAttributeList
*
* @var \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory
*/
protected $_attributeColFactory;
protected $attributeCollectionFactory;

/**
* Catalog resource helper
*
* @var \Magento\Catalog\Model\Resource\Helper
*/
protected $_resourceHelper;
protected $resourceHelper;

/**
* @param \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeColFactory
* Application Event Dispatcher
*
* @var \Magento\Framework\Event\ManagerInterface
*/
protected $eventManager;

/**
* Object Factory
*
* @var \Magento\Framework\ObjectFactory
*/
protected $objectFactory;

/**
* @param \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory
* @param \Magento\Catalog\Model\Resource\Helper $resourceHelper
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param \Magento\Framework\ObjectFactory $objectFactory
*/
public function __construct(
\Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeColFactory,
\Magento\Catalog\Model\Resource\Helper $resourceHelper
\Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory,
\Magento\Catalog\Model\Resource\Helper $resourceHelper,
\Magento\Framework\Event\ManagerInterface $eventManager,
\Magento\Framework\ObjectFactory $objectFactory
) {
$this->_attributeColFactory = $attributeColFactory;
$this->_resourceHelper = $resourceHelper;
$this->attributeCollectionFactory = $attributeCollectionFactory;
$this->resourceHelper = $resourceHelper;
$this->objectFactory = $objectFactory;
$this->eventManager = $eventManager;
}

/**
Expand All @@ -43,12 +63,14 @@ public function __construct(
*/
public function getSuggestedAttributes($labelPart)
{
$escapedLabelPart = $this->_resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
$escapedLabelPart = $this->resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
$availableFrontendTypes = $this->getAvailableFrontendTypes();

/** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
$collection = $this->_attributeColFactory->create();
$collection = $this->attributeCollectionFactory->create();
$collection->addFieldToFilter(
'frontend_input',
'select'
'main_table.frontend_input',
['in' => $availableFrontendTypes->getData('values')]
)->addFieldToFilter(
'frontend_label',
['like' => $escapedLabelPart]
Expand Down Expand Up @@ -79,4 +101,22 @@ public function getSuggestedAttributes($labelPart)
}
return $result;
}

/**
* @return \Magento\Framework\Object
*/
private function getAvailableFrontendTypes()
{
$availableFrontendTypes = $this->objectFactory->create();
$availableFrontendTypes->setData(
[
'values' => ['select']
]
);
$this->eventManager->dispatch(
'product_suggested_attribute_frontend_type_init_after',
['types_dto' => $availableFrontendTypes]
);
return $availableFrontendTypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ class SuggestedAttributeListTest extends \PHPUnit_Framework_TestCase
*/
protected $attributeFactoryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $eventManagerMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $objectFactoryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
Expand Down Expand Up @@ -53,6 +63,20 @@ protected function setUp()
'',
false
);
$this->eventManagerMock = $this->getMock(
'\Magento\Framework\Event\ManagerInterface',
[],
[],
'',
false
);
$this->objectFactoryMock = $this->getMock(
'\Magento\Framework\ObjectFactory',
['create'],
[],
'',
false
);
$this->collectionMock = $this->getMock(
'Magento\Catalog\Model\Resource\Product\Attribute\Collection',
[],
Expand All @@ -78,7 +102,7 @@ protected function setUp()
$this->returnValue($this->collectionMock)
);
$valueMap = [
['frontend_input', 'select', $this->collectionMock],
['main_table.frontend_input', ['in' => 123 ], $this->collectionMock],
['frontend_label', ['like' => $this->labelPart], $this->collectionMock],
['is_user_defined', 1, $this->collectionMock],
['is_global', \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL, $this->collectionMock],
Expand Down Expand Up @@ -107,12 +131,19 @@ protected function setUp()
);
$this->suggestedListModel = new \Magento\ConfigurableProduct\Model\SuggestedAttributeList(
$this->attributeFactoryMock,
$this->resourceHelperMock
$this->resourceHelperMock,
$this->eventManagerMock,
$this->objectFactoryMock
);
}

public function testGetSuggestedAttributesIfTheyApplicable()
{
$object = $this->getMock('\Magento\Framework\Object', [], [], '', false);
$object->expects($this->once())->method('setData');
$object->expects($this->once())->method('getData')->willReturn(123);
$this->objectFactoryMock->expects($this->once())->method('create')->willReturn($object);

$source = $this->getMock(
'Magento\Eav\Model\Entity\Attribute\Source\AbstractSource',
[],
Expand All @@ -132,6 +163,10 @@ public function testGetSuggestedAttributesIfTheyApplicable()

public function testGetSuggestedAttributesIfTheyNotApplicable()
{
$object = $this->getMock('\Magento\Framework\Object', [], [], '', false);
$object->expects($this->once())->method('setData');
$object->expects($this->once())->method('getData')->willReturn(123);
$this->objectFactoryMock->expects($this->once())->method('create')->willReturn($object);
$this->attributeMock->expects($this->any())->method('getApplyTo')->will($this->returnValue(['simple']));
$this->attributeMock->expects($this->never())->method('getId');
$this->attributeMock->expects($this->never())->method('getFrontendLabel');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function getStoreOptionValues($storeId)
*
* @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute
*/
private function getAttributeObject()
protected function getAttributeObject()
{
return $this->_registry->registry('entity_attribute');
}
Expand Down
8 changes: 8 additions & 0 deletions app/design/frontend/Magento/blank/etc/view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@
<var name="product_stock_alert_email_product_image:width">76</var>
<var name="product_stock_alert_email_product_image:ratio">1</var>
<var name="product_stock_alert_email_product_image:height">76</var>

<var name="swatch_image:width">30</var>
<var name="swatch_image:ratio">0.8</var>
<var name="swatch_image:height">20</var>

<var name="swatch_thumb:width">110</var>
<var name="swatch_thumb:ratio">0.8</var>
<var name="swatch_thumb:height">90</var>
</vars>
<vars module="Magento_Bundle">
<var name="product_summary_image_size">58</var> <!-- New Product image size used for summary block-->
Expand Down
8 changes: 8 additions & 0 deletions app/design/frontend/Magento/luma/etc/view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@
<var name="product_stock_alert_email_product_image:width">76</var>
<var name="product_stock_alert_email_product_image:ratio">1</var>
<var name="product_stock_alert_email_product_image:height">76</var>

<var name="swatch_image:width">30</var>
<var name="swatch_image:ratio">0.8</var>
<var name="swatch_image:height">20</var>

<var name="swatch_thumb:width">110</var>
<var name="swatch_thumb:ratio">0.8</var>
<var name="swatch_thumb:height">90</var>
</vars>
<vars module="Magento_Bundle">
<var name="product_summary_image_size">58</var> <!-- New Product image size used for summary block-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function persist(FixtureInterface $fixture = null)

if ($fixture->hasData('options')) {
$optionsData = $fixture->getData()['options'];
foreach ($matches[1] as $key => $optionId) {
foreach (array_unique($matches[1]) as $key => $optionId) {
$optionsData[$key]['id'] = $optionId;
}
$resultData['options'] = $optionsData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ public function getAllowedActionNodeMethods()
'setWrapperClass',
'unsetChild',
'unsetChildren',
'updateButton'
'updateButton',
'setIsProductListingContext'
];
}
}

0 comments on commit a8f1eaa

Please sign in to comment.