Skip to content

Commit 3be18f3

Browse files
authored
Merge pull request #125 from magento-nord/EPAM-SPRINT-13
[Nord] Epam Sprint 13
2 parents 73a5230 + c15766a commit 3be18f3

File tree

43 files changed

+522
-94
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+522
-94
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Block\Product;
7+
8+
/**
9+
* Class Product Aware interface
10+
*/
11+
interface AwareInterface
12+
{
13+
/**
14+
* Set product
15+
*
16+
* @param \Magento\Catalog\Api\Data\ProductInterface $product
17+
* @return $this
18+
*/
19+
public function setProduct(\Magento\Catalog\Api\Data\ProductInterface $product);
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Block\Product\ProductList\Item\AddTo;
7+
8+
/**
9+
* Add product to compare
10+
*/
11+
class Compare extends \Magento\Catalog\Block\Product\ProductList\Item\Block
12+
{
13+
/**
14+
* @return \Magento\Catalog\Helper\Product\Compare
15+
*/
16+
public function getCompareHelper()
17+
{
18+
return $this->_compareProduct;
19+
}
20+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Block\Product\ProductList\Item;
7+
8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Catalog\Block\Product\AbstractProduct;
10+
use Magento\Catalog\Block\Product\AwareInterface as ProductAwareInterface;
11+
12+
/**
13+
* Class List Item Block
14+
*/
15+
class Block extends AbstractProduct implements ProductAwareInterface
16+
{
17+
/**
18+
* @var ProductInterface
19+
*/
20+
private $product;
21+
22+
/**
23+
* {@inheritdoc}
24+
*/
25+
public function setProduct(ProductInterface $product)
26+
{
27+
$this->product = $product;
28+
return $this;
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function getProduct()
35+
{
36+
return $this->product;
37+
}
38+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Block\Product\ProductList\Item;
7+
8+
use Magento\Catalog\Block\Product\AwareInterface as ProductAwareInterface;
9+
10+
/**
11+
* Class List Item Block Container
12+
*/
13+
class Container extends Block
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
public function getChildHtml($alias = '', $useCache = false)
19+
{
20+
$layout = $this->getLayout();
21+
if ($layout) {
22+
$name = $this->getNameInLayout();
23+
foreach ($layout->getChildBlocks($name) as $child) {
24+
if ($child instanceof ProductAwareInterface) {
25+
$child->setProduct($this->getProduct());
26+
}
27+
}
28+
}
29+
return parent::getChildHtml($alias, $useCache);
30+
}
31+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function __construct(
110110
* Return wishlist widget options
111111
*
112112
* @return array
113+
* @deprecated
113114
*/
114115
public function getWishlistOptions()
115116
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Block\Product\View\AddTo;
8+
9+
/**
10+
* Product view compare block
11+
*/
12+
class Compare extends \Magento\Catalog\Block\Product\View
13+
{
14+
/**
15+
* Return compare params
16+
*
17+
* @return string
18+
*/
19+
public function getPostDataParams()
20+
{
21+
$product = $this->getProduct();
22+
return $this->_compareProduct->getPostDataParams($product);
23+
}
24+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
<block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
2222
<block class="Magento\Framework\View\Element\Template" as="default"/>
2323
</block>
24+
<block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="category.product.addto" as="addto">
25+
<block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
26+
name="category.product.addto.compare" as="compare"
27+
template="Magento_Catalog::product/list/addto/compare.phtml"/>
28+
</block>
2429
<block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
2530
<block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
2631
<!-- The following code shows how to set your own pager increments -->

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@
8282
</block>
8383
<container name="product.info.extrahint" as="extrahint" label="Product View Extra Hint">
8484
<container name="product.info.social" label="Product social links container" htmlTag="div" htmlClass="product-social-links" after="product.info.overview">
85-
<block class="Magento\Catalog\Block\Product\View" name="product.info.addto" as="addto" template="product/view/addto.phtml"/>
85+
<block class="Magento\Catalog\Block\Product\View" name="product.info.addto" as="addto" template="product/view/addto.phtml">
86+
<block class="Magento\Catalog\Block\Product\View\AddTo\Compare" name="view.addto.compare" after="view.addto.wishlist"
87+
template="Magento_Catalog::product/view/addto/compare.phtml" />
88+
</block>
8689
<block class="Magento\Catalog\Block\Product\View" name="product.info.mailto" template="product/view/mailto.phtml"/>
8790
</container>
8891
</container>
@@ -129,11 +132,21 @@
129132
<arguments>
130133
<argument name="type" xsi:type="string">related</argument>
131134
</arguments>
135+
<block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="related.product.addto" as="addto">
136+
<block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
137+
name="related.product.addto.compare" as="compare"
138+
template="Magento_Catalog::product/list/addto/compare.phtml"/>
139+
</block>
132140
</block>
133141
<block class="Magento\Catalog\Block\Product\ProductList\Upsell" name="product.info.upsell" template="Magento_Catalog::product/list/items.phtml">
134142
<arguments>
135143
<argument name="type" xsi:type="string">upsell</argument>
136144
</arguments>
145+
<block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="upsell.product.addto" as="addto">
146+
<block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
147+
name="upsell.product.addto.compare" as="compare"
148+
template="Magento_Catalog::product/list/addto/compare.phtml"/>
149+
</block>
137150
</block>
138151
<block class="Magento\Catalog\Block\Product\View\Additional" name="product.info.additional" as="product_additional_data"/>
139152
</referenceContainer>

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,9 @@ $_helper = $this->helper('Magento\Catalog\Helper\Output');
9797
<?php endif; ?>
9898
</div>
9999
<div data-role="add-to-links" class="actions-secondary"<?php echo strpos($pos, $viewMode . '-secondary') ? $position : ''; ?>>
100-
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
101-
<a href="#"
102-
class="action towishlist"
103-
title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
104-
aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
105-
data-post='<?php /* @escapeNotVerified */ echo $block->getAddToWishlistParams($_product); ?>'
106-
data-action="add-to-wishlist"
107-
role="button">
108-
<span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span>
109-
</a>
100+
<?php if ($addToBlock = $block->getChildBlock('addto')): ?>
101+
<?php echo $addToBlock->setProduct($_product)->getChildHtml(); ?>
110102
<?php endif; ?>
111-
<?php
112-
$compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
113-
?>
114-
<a href="#"
115-
class="action tocompare"
116-
title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
117-
aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
118-
data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product); ?>'
119-
role="button">
120-
<span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
121-
</a>
122103
</div>
123104
</div>
124105
<?php if ($showDescription):?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
// @codingStandardsIgnoreFile
8+
/** @var $block Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare */
9+
?>
10+
<a href="#"
11+
class="action tocompare"
12+
title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
13+
aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
14+
data-post='<?php /* @escapeNotVerified */ echo $block->getCompareHelper()->getPostDataParams($block->getProduct()); ?>'
15+
role="button">
16+
<span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
17+
</a>

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

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ switch ($type = $block->getType()) {
2424
$shuffle = (int) $block->isShuffled();
2525
$canItemsAddToCart = $block->canItemsAddToCart();
2626

27-
$showWishlist = true;
28-
$showCompare = true;
27+
$showAddTo = true;
2928
$showCart = false;
3029
$templateType = null;
3130
$description = false;
@@ -45,8 +44,7 @@ switch ($type = $block->getType()) {
4544
$shuffle = 0;
4645
$canItemsAddToCart = $block->canItemsAddToCart();
4746

48-
$showWishlist = true;
49-
$showCompare = true;
47+
$showAddTo = true;
5048
$showCart = false;
5149
$templateType = null;
5250
$description = false;
@@ -64,8 +62,7 @@ switch ($type = $block->getType()) {
6462
$limit = $block->getPositionLimit();
6563
$shuffle = (int) $block->isShuffled();
6664

67-
$showWishlist = false;
68-
$showCompare = false;
65+
$showAddTo = false;
6966
$showCart = false;
7067
$templateType = null;
7168
$description = false;
@@ -85,8 +82,7 @@ switch ($type = $block->getType()) {
8582
$limit = $block->getItemLimit('upsell');
8683
$shuffle = 0;
8784

88-
$showWishlist = false;
89-
$showCompare = false;
85+
$showAddTo = false;
9086
$showCart = false;
9187
$templateType = null;
9288
$description = false;
@@ -104,8 +100,7 @@ switch ($type = $block->getType()) {
104100
$title = __('More Choices:');
105101
$items = $block->getItemCollection();
106102

107-
$showWishlist = true;
108-
$showCompare = true;
103+
$showAddTo = true;
109104
$showCart = true;
110105
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
111106
$description = false;
@@ -123,8 +118,7 @@ switch ($type = $block->getType()) {
123118
$title = __('More Choices:');
124119
$items = $block->getItems();
125120

126-
$showWishlist = true;
127-
$showCompare = true;
121+
$showAddTo = true;
128122
$showCart = true;
129123
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
130124
$description = false;
@@ -144,8 +138,7 @@ switch ($type = $block->getType()) {
144138
$title = __('New Products');
145139
$items = $exist;
146140

147-
$showWishlist = true;
148-
$showCompare = true;
141+
$showAddTo = true;
149142
$showCart = true;
150143
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
151144
$description = ($mode == 'list') ? true : false;
@@ -219,7 +212,7 @@ switch ($type = $block->getType()) {
219212
<?php endif; ?>
220213
<?php endif; ?>
221214

222-
<?php if ($showWishlist || $showCompare || $showCart): ?>
215+
<?php if ($showAddTo || $showCart): ?>
223216
<div class="product actions product-item-actions">
224217
<?php if ($showCart): ?>
225218
<div class="actions-primary">
@@ -248,23 +241,10 @@ switch ($type = $block->getType()) {
248241
</div>
249242
<?php endif; ?>
250243

251-
<?php if ($showWishlist || $showCompare): ?>
244+
<?php if ($showAddTo): ?>
252245
<div class="secondary-addto-links actions-secondary" data-role="add-to-links">
253-
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && $showWishlist): ?>
254-
<a href="#" data-post='<?php /* @escapeNotVerified */ echo $block->getAddToWishlistParams($_item); ?>' class="action towishlist" data-action="add-to-wishlist" title="<?php /* @escapeNotVerified */ echo __('Add to Wish List') ?>">
255-
<span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span>
256-
</a>
257-
<?php endif; ?>
258-
<?php if ($block->getAddToCompareUrl() && $showCompare): ?>
259-
<?php
260-
$compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
261-
?>
262-
<a href="#" class="action tocompare"
263-
data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_item);?>'
264-
data-role="add-to-links"
265-
title="<?php /* @escapeNotVerified */ echo __('Add to Compare'); ?>">
266-
<span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
267-
</a>
246+
<?php if ($addToBlock = $block->getChildBlock('addto')): ?>
247+
<?php echo $addToBlock->setProduct($_item)->getChildHtml(); ?>
268248
<?php endif; ?>
269249
</div>
270250
<?php endif; ?>

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,6 @@
88

99
/** @var $block \Magento\Catalog\Block\Product\View*/
1010
?>
11-
<?php
12-
$_product = $block->getProduct();
13-
$_wishlistSubmitParams = $this->helper('Magento\Wishlist\Helper\Data')->getAddParams($_product);
14-
$compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
15-
?>
16-
1711
<div class="product-addto-links" data-role="add-to-links">
18-
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()) : ?>
19-
<a href="#"
20-
class="action towishlist"
21-
data-post='<?php /* @escapeNotVerified */ echo $_wishlistSubmitParams; ?>'
22-
data-action="add-to-wishlist"><span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span></a>
23-
<?php endif; ?>
24-
<a href="#" data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product);?>'
25-
data-role="add-to-links"
26-
class="action tocompare"><span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span></a>
12+
<?php echo $block->getChildHtml(); ?>
2713
</div>
28-
<script type="text/x-magento-init">
29-
{
30-
"body": {
31-
"addToWishlist": <?php /* @escapeNotVerified */ echo $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getWishlistOptions())?>
32-
}
33-
}
34-
</script>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
// @codingStandardsIgnoreFile
8+
9+
/** @var $block \Magento\Catalog\Block\Catalog\Product\View\Addto\Compare */
10+
?>
11+
12+
<a href="#" data-post='<?php /* @escapeNotVerified */ echo $block->getPostDataParams();?>'
13+
data-role="add-to-links"
14+
class="action tocompare"><span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span></a>

0 commit comments

Comments
 (0)