Skip to content

Commit

Permalink
MAGETWO-54833: Modularity Wishlist Module
Browse files Browse the repository at this point in the history
  • Loading branch information
balex13 committed Jun 29, 2016
1 parent 73a5230 commit c15766a
Show file tree
Hide file tree
Showing 43 changed files with 522 additions and 94 deletions.
20 changes: 20 additions & 0 deletions app/code/Magento/Catalog/Block/Product/AwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Block\Product;

/**
* Class Product Aware interface
*/
interface AwareInterface
{
/**
* Set product
*
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @return $this
*/
public function setProduct(\Magento\Catalog\Api\Data\ProductInterface $product);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Block\Product\ProductList\Item\AddTo;

/**
* Add product to compare
*/
class Compare extends \Magento\Catalog\Block\Product\ProductList\Item\Block
{
/**
* @return \Magento\Catalog\Helper\Product\Compare
*/
public function getCompareHelper()
{
return $this->_compareProduct;
}
}
38 changes: 38 additions & 0 deletions app/code/Magento/Catalog/Block/Product/ProductList/Item/Block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Block\Product\ProductList\Item;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Block\Product\AbstractProduct;
use Magento\Catalog\Block\Product\AwareInterface as ProductAwareInterface;

This comment has been minimized.

Copy link
@orlangur

orlangur Jun 30, 2016

Contributor

This is wrong. Interface should be named in such a way that there is no alias needed.

Word-per-directory was a common pattern in Magento 1 but there is no need to continue using such bad practice.


/**
* Class List Item Block
*/
class Block extends AbstractProduct implements ProductAwareInterface
{
/**
* @var ProductInterface
*/
private $product;

/**
* {@inheritdoc}
*/
public function setProduct(ProductInterface $product)
{
$this->product = $product;
return $this;
}

/**
* {@inheritdoc}
*/
public function getProduct()
{
return $this->product;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Block\Product\ProductList\Item;

use Magento\Catalog\Block\Product\AwareInterface as ProductAwareInterface;

/**
* Class List Item Block Container
*/
class Container extends Block
{
/**
* {@inheritdoc}
*/
public function getChildHtml($alias = '', $useCache = false)
{
$layout = $this->getLayout();
if ($layout) {
$name = $this->getNameInLayout();
foreach ($layout->getChildBlocks($name) as $child) {
if ($child instanceof ProductAwareInterface) {
$child->setProduct($this->getProduct());
}
}
}
return parent::getChildHtml($alias, $useCache);
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/Block/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function __construct(
* Return wishlist widget options
*
* @return array
* @deprecated
*/
public function getWishlistOptions()
{
Expand Down
24 changes: 24 additions & 0 deletions app/code/Magento/Catalog/Block/Product/View/AddTo/Compare.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Block\Product\View\AddTo;

/**
* Product view compare block
*/
class Compare extends \Magento\Catalog\Block\Product\View
{
/**
* Return compare params
*
* @return string
*/
public function getPostDataParams()
{
$product = $this->getProduct();
return $this->_compareProduct->getPostDataParams($product);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
<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\Item\Container" name="category.product.addto" as="addto">
<block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
name="category.product.addto.compare" as="compare"
template="Magento_Catalog::product/list/addto/compare.phtml"/>
</block>
<block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::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 @@ -82,7 +82,10 @@
</block>
<container name="product.info.extrahint" as="extrahint" label="Product View Extra Hint">
<container name="product.info.social" label="Product social links container" htmlTag="div" htmlClass="product-social-links" after="product.info.overview">
<block class="Magento\Catalog\Block\Product\View" name="product.info.addto" as="addto" template="product/view/addto.phtml"/>
<block class="Magento\Catalog\Block\Product\View" name="product.info.addto" as="addto" template="product/view/addto.phtml">
<block class="Magento\Catalog\Block\Product\View\AddTo\Compare" name="view.addto.compare" after="view.addto.wishlist"
template="Magento_Catalog::product/view/addto/compare.phtml" />
</block>
<block class="Magento\Catalog\Block\Product\View" name="product.info.mailto" template="product/view/mailto.phtml"/>
</container>
</container>
Expand Down Expand Up @@ -129,11 +132,21 @@
<arguments>
<argument name="type" xsi:type="string">related</argument>
</arguments>
<block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="related.product.addto" as="addto">
<block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
name="related.product.addto.compare" as="compare"
template="Magento_Catalog::product/list/addto/compare.phtml"/>
</block>
</block>
<block class="Magento\Catalog\Block\Product\ProductList\Upsell" name="product.info.upsell" template="Magento_Catalog::product/list/items.phtml">
<arguments>
<argument name="type" xsi:type="string">upsell</argument>
</arguments>
<block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="upsell.product.addto" as="addto">
<block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
name="upsell.product.addto.compare" as="compare"
template="Magento_Catalog::product/list/addto/compare.phtml"/>
</block>
</block>
<block class="Magento\Catalog\Block\Product\View\Additional" name="product.info.additional" as="product_additional_data"/>
</referenceContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,9 @@ $_helper = $this->helper('Magento\Catalog\Helper\Output');
<?php endif; ?>
</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="#"
class="action towishlist"
title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
data-post='<?php /* @escapeNotVerified */ echo $block->getAddToWishlistParams($_product); ?>'
data-action="add-to-wishlist"
role="button">
<span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span>
</a>
<?php if ($addToBlock = $block->getChildBlock('addto')): ?>
<?php echo $addToBlock->setProduct($_product)->getChildHtml(); ?>
<?php endif; ?>
<?php
$compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
?>
<a href="#"
class="action tocompare"
title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product); ?>'
role="button">
<span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
</a>
</div>
</div>
<?php if ($showDescription):?>
Expand Down
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.
*/

// @codingStandardsIgnoreFile
/** @var $block Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare */
?>
<a href="#"
class="action tocompare"
title="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
data-post='<?php /* @escapeNotVerified */ echo $block->getCompareHelper()->getPostDataParams($block->getProduct()); ?>'
role="button">
<span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ switch ($type = $block->getType()) {
$shuffle = (int) $block->isShuffled();
$canItemsAddToCart = $block->canItemsAddToCart();

$showWishlist = true;
$showCompare = true;
$showAddTo = true;
$showCart = false;
$templateType = null;
$description = false;
Expand All @@ -45,8 +44,7 @@ switch ($type = $block->getType()) {
$shuffle = 0;
$canItemsAddToCart = $block->canItemsAddToCart();

$showWishlist = true;
$showCompare = true;
$showAddTo = true;
$showCart = false;
$templateType = null;
$description = false;
Expand All @@ -64,8 +62,7 @@ switch ($type = $block->getType()) {
$limit = $block->getPositionLimit();
$shuffle = (int) $block->isShuffled();

$showWishlist = false;
$showCompare = false;
$showAddTo = false;
$showCart = false;
$templateType = null;
$description = false;
Expand All @@ -85,8 +82,7 @@ switch ($type = $block->getType()) {
$limit = $block->getItemLimit('upsell');
$shuffle = 0;

$showWishlist = false;
$showCompare = false;
$showAddTo = false;
$showCart = false;
$templateType = null;
$description = false;
Expand All @@ -104,8 +100,7 @@ switch ($type = $block->getType()) {
$title = __('More Choices:');
$items = $block->getItemCollection();

$showWishlist = true;
$showCompare = true;
$showAddTo = true;
$showCart = true;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
$description = false;
Expand All @@ -123,8 +118,7 @@ switch ($type = $block->getType()) {
$title = __('More Choices:');
$items = $block->getItems();

$showWishlist = true;
$showCompare = true;
$showAddTo = true;
$showCart = true;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
$description = false;
Expand All @@ -144,8 +138,7 @@ switch ($type = $block->getType()) {
$title = __('New Products');
$items = $exist;

$showWishlist = true;
$showCompare = true;
$showAddTo = true;
$showCart = true;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
$description = ($mode == 'list') ? true : false;
Expand Down Expand Up @@ -219,7 +212,7 @@ switch ($type = $block->getType()) {
<?php endif; ?>
<?php endif; ?>

<?php if ($showWishlist || $showCompare || $showCart): ?>
<?php if ($showAddTo || $showCart): ?>
<div class="product actions product-item-actions">
<?php if ($showCart): ?>
<div class="actions-primary">
Expand Down Expand Up @@ -248,23 +241,10 @@ switch ($type = $block->getType()) {
</div>
<?php endif; ?>

<?php if ($showWishlist || $showCompare): ?>
<?php if ($showAddTo): ?>
<div class="secondary-addto-links actions-secondary" data-role="add-to-links">
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow() && $showWishlist): ?>
<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') ?>">
<span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span>
</a>
<?php endif; ?>
<?php if ($block->getAddToCompareUrl() && $showCompare): ?>
<?php
$compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
?>
<a href="#" class="action tocompare"
data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_item);?>'
data-role="add-to-links"
title="<?php /* @escapeNotVerified */ echo __('Add to Compare'); ?>">
<span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span>
</a>
<?php if ($addToBlock = $block->getChildBlock('addto')): ?>
<?php echo $addToBlock->setProduct($_item)->getChildHtml(); ?>
<?php endif; ?>
</div>
<?php endif; ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,6 @@

/** @var $block \Magento\Catalog\Block\Product\View*/
?>
<?php
$_product = $block->getProduct();
$_wishlistSubmitParams = $this->helper('Magento\Wishlist\Helper\Data')->getAddParams($_product);
$compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
?>

<div class="product-addto-links" data-role="add-to-links">
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()) : ?>
<a href="#"
class="action towishlist"
data-post='<?php /* @escapeNotVerified */ echo $_wishlistSubmitParams; ?>'
data-action="add-to-wishlist"><span><?php /* @escapeNotVerified */ echo __('Add to Wish List') ?></span></a>
<?php endif; ?>
<a href="#" data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product);?>'
data-role="add-to-links"
class="action tocompare"><span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span></a>
<?php echo $block->getChildHtml(); ?>
</div>
<script type="text/x-magento-init">
{
"body": {
"addToWishlist": <?php /* @escapeNotVerified */ echo $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getWishlistOptions())?>
}
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

/** @var $block \Magento\Catalog\Block\Catalog\Product\View\Addto\Compare */
?>

<a href="#" data-post='<?php /* @escapeNotVerified */ echo $block->getPostDataParams();?>'
data-role="add-to-links"
class="action tocompare"><span><?php /* @escapeNotVerified */ echo __('Add to Compare') ?></span></a>
Loading

0 comments on commit c15766a

Please sign in to comment.