Skip to content

Commit

Permalink
Merge pull request #509 from magento-goinc/MAGETWO-31442-manual
Browse files Browse the repository at this point in the history
[GoInc] Splitting observers - MAGETWO-31442
  • Loading branch information
Onischenko, Yaroslav(yonischenko) committed Aug 7, 2015
2 parents 04c2e63 + 6098a13 commit 0a1db3c
Show file tree
Hide file tree
Showing 98 changed files with 4,159 additions and 3,060 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,48 @@
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Model;
namespace Magento\Bundle\Observer;

/**
* Bundle Products Observer
*
* @author Magento Core Team <core@magentocommerce.com>
*/
class Observer
class AppendUpsellProducts
{
/**
* Bundle data
*
* @var \Magento\Bundle\Helper\Data
*/
protected $_bundleData = null;

/**
* Catalog helper
*
* @var \Magento\Catalog\Helper\Catalog
*/
protected $_helperCatalog = null;
protected $bundleData;

/**
* @var \Magento\Bundle\Model\Resource\Selection
*/
protected $_bundleSelection;
protected $bundleSelection;

/**
* @var \Magento\Catalog\Model\Config
*/
protected $_config;
protected $config;

/**
* @var \Magento\Catalog\Model\Product\Visibility
*/
protected $_productVisibility;
protected $productVisibility;

/**
* @param \Magento\Bundle\Helper\Data $bundleData
* @param \Magento\Catalog\Model\Product\Visibility $productVisibility
* @param \Magento\Catalog\Model\Config $config
* @param \Magento\Bundle\Model\Resource\Selection $bundleSelection
* @param \Magento\Catalog\Helper\Catalog $helperCatalog
* @param \Magento\Bundle\Helper\Data $bundleData
*/
public function __construct(
\Magento\Bundle\Helper\Data $bundleData,
\Magento\Catalog\Model\Product\Visibility $productVisibility,
\Magento\Catalog\Model\Config $config,
\Magento\Bundle\Model\Resource\Selection $bundleSelection,
\Magento\Catalog\Helper\Catalog $helperCatalog,
\Magento\Bundle\Helper\Data $bundleData
\Magento\Bundle\Model\Resource\Selection $bundleSelection
) {
$this->_helperCatalog = $helperCatalog;
$this->_bundleData = $bundleData;
$this->_bundleSelection = $bundleSelection;
$this->_config = $config;
$this->_productVisibility = $productVisibility;
$this->bundleData = $bundleData;
$this->productVisibility = $productVisibility;
$this->config = $config;
$this->bundleSelection = $bundleSelection;
}

/**
Expand All @@ -70,15 +55,15 @@ public function __construct(
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function appendUpsellProducts($observer)
public function invoke($observer)
{
/* @var $product \Magento\Catalog\Model\Product */
$product = $observer->getEvent()->getProduct();

/**
* Check is current product type is allowed for bundle selection product type
*/
if (!in_array($product->getTypeId(), $this->_bundleData->getAllowedSelectionTypes())) {
if (!in_array($product->getTypeId(), $this->bundleData->getAllowedSelectionTypes())) {
return $this;
}

Expand All @@ -94,7 +79,7 @@ public function appendUpsellProducts($observer)
}

/* @var $resource \Magento\Bundle\Model\Resource\Selection */
$resource = $this->_bundleSelection;
$resource = $this->bundleSelection;

$productIds = array_keys($collection->getItems());
if ($limit !== null && $limit <= count($productIds)) {
Expand All @@ -112,9 +97,9 @@ public function appendUpsellProducts($observer)

/* @var $bundleCollection \Magento\Catalog\Model\Resource\Product\Collection */
$bundleCollection = $product->getCollection()->addAttributeToSelect(
$this->_config->getProductAttributes()
$this->config->getProductAttributes()
)->addStoreFilter()->addMinimalPrice()->addFinalPrice()->addTaxPercents()->setVisibility(
$this->_productVisibility->getVisibleInCatalogIds()
$this->productVisibility->getVisibleInCatalogIds()
);

if ($limit !== null) {
Expand Down Expand Up @@ -142,50 +127,4 @@ public function appendUpsellProducts($observer)

return $this;
}

/**
* Add price index data for catalog product collection
* only for front end
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function loadProductOptions($observer)
{
$collection = $observer->getEvent()->getCollection();
/* @var $collection \Magento\Catalog\Model\Resource\Product\Collection */
$collection->addPriceData();

return $this;
}

/**
* Setting attribute tab block for bundle
*
* @param \Magento\Framework\DataObject $observer
* @return $this
*/
public function setAttributeTabBlock($observer)
{
$product = $observer->getEvent()->getProduct();
if ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
$this->_helperCatalog->setAttributeTabBlock(
'Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes'
);
}
return $this;
}

/**
* Initialize product options renderer with bundle specific params
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function initOptionRenderer(\Magento\Framework\Event\Observer $observer)
{
$block = $observer->getBlock();
$block->addOptionsRenderCfg('bundle', 'Magento\Bundle\Helper\Catalog\Product\Configuration');
return $this;
}
}
22 changes: 22 additions & 0 deletions app/code/Magento/Bundle/Observer/InitOptionRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Observer;

class InitOptionRenderer
{
/**
* Initialize product options renderer with bundle specific params
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function invoke(\Magento\Framework\Event\Observer $observer)
{
$block = $observer->getBlock();
$block->addOptionsRenderCfg('bundle', 'Magento\Bundle\Helper\Catalog\Product\Configuration');
return $this;
}
}
25 changes: 25 additions & 0 deletions app/code/Magento/Bundle/Observer/LoadProductOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Observer;

class LoadProductOptions
{
/**
* Add price index data for catalog product collection
* only for front end
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function invoke($observer)
{
$collection = $observer->getEvent()->getCollection();
/* @var $collection \Magento\Catalog\Model\Resource\Product\Collection */
$collection->addPriceData();

return $this;
}
}
41 changes: 41 additions & 0 deletions app/code/Magento/Bundle/Observer/SetAttributeTabBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Observer;

class SetAttributeTabBlock
{
/**
* Catalog helper
*
* @var \Magento\Catalog\Helper\Catalog
*/
protected $helperCatalog;

/**
* @param \Magento\Catalog\Helper\Catalog $helperCatalog
*/
public function __construct(\Magento\Catalog\Helper\Catalog $helperCatalog)
{
$this->helperCatalog = $helperCatalog;
}

/**
* Setting attribute tab block for bundle
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function invoke($observer)
{
$product = $observer->getEvent()->getProduct();
if ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
$this->helperCatalog->setAttributeTabBlock(
'Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes'
);
}
return $this;
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/Bundle/etc/adminhtml/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="catalog_product_edit_action">
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="setAttributeTabBlock" />
<observer name="bundle_observer" instance="Magento\Bundle\Observer\SetAttributeTabBlock" method="invoke" />
</event>
<event name="catalog_product_new_action">
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="setAttributeTabBlock" />
<observer name="bundle_observer" instance="Magento\Bundle\Observer\SetAttributeTabBlock" method="invoke" />
</event>
</config>
6 changes: 3 additions & 3 deletions app/code/Magento/Bundle/etc/frontend/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="catalog_product_upsell">
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="appendUpsellProducts" />
<observer name="bundle_observer" instance="Magento\Bundle\Observer\AppendUpsellProducts" method="invoke"/>
</event>
<event name="catalog_product_collection_load_after">
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="loadProductOptions" />
<observer name="bundle_observer" instance="Magento\Bundle\Observer\LoadProductOptions" method="invoke"/>
</event>
<event name="product_option_renderer_init">
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="initOptionRenderer" />
<observer name="bundle_observer" instance="Magento\Bundle\Observer\InitOptionRenderer" method="invoke"/>
</event>
</config>
111 changes: 0 additions & 111 deletions app/code/Magento/CacheInvalidate/Model/Observer.php

This file was deleted.

Loading

0 comments on commit 0a1db3c

Please sign in to comment.