Skip to content

Commit 0a1db3c

Browse files
author
Onischenko, Yaroslav(yonischenko)
committed
Merge pull request #509 from magento-goinc/MAGETWO-31442-manual
[GoInc] Splitting observers - MAGETWO-31442
2 parents 04c2e63 + 6098a13 commit 0a1db3c

File tree

98 files changed

+4159
-3060
lines changed

Some content is hidden

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

98 files changed

+4159
-3060
lines changed

app/code/Magento/Bundle/Model/Observer.php renamed to app/code/Magento/Bundle/Observer/AppendUpsellProducts.php

Lines changed: 18 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,48 @@
33
* Copyright © 2015 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Bundle\Model;
6+
namespace Magento\Bundle\Observer;
77

8-
/**
9-
* Bundle Products Observer
10-
*
11-
* @author Magento Core Team <[email protected]>
12-
*/
13-
class Observer
8+
class AppendUpsellProducts
149
{
1510
/**
1611
* Bundle data
1712
*
1813
* @var \Magento\Bundle\Helper\Data
1914
*/
20-
protected $_bundleData = null;
21-
22-
/**
23-
* Catalog helper
24-
*
25-
* @var \Magento\Catalog\Helper\Catalog
26-
*/
27-
protected $_helperCatalog = null;
15+
protected $bundleData;
2816

2917
/**
3018
* @var \Magento\Bundle\Model\Resource\Selection
3119
*/
32-
protected $_bundleSelection;
20+
protected $bundleSelection;
3321

3422
/**
3523
* @var \Magento\Catalog\Model\Config
3624
*/
37-
protected $_config;
25+
protected $config;
3826

3927
/**
4028
* @var \Magento\Catalog\Model\Product\Visibility
4129
*/
42-
protected $_productVisibility;
30+
protected $productVisibility;
4331

4432
/**
33+
* @param \Magento\Bundle\Helper\Data $bundleData
4534
* @param \Magento\Catalog\Model\Product\Visibility $productVisibility
4635
* @param \Magento\Catalog\Model\Config $config
4736
* @param \Magento\Bundle\Model\Resource\Selection $bundleSelection
48-
* @param \Magento\Catalog\Helper\Catalog $helperCatalog
49-
* @param \Magento\Bundle\Helper\Data $bundleData
5037
*/
5138
public function __construct(
39+
\Magento\Bundle\Helper\Data $bundleData,
5240
\Magento\Catalog\Model\Product\Visibility $productVisibility,
5341
\Magento\Catalog\Model\Config $config,
54-
\Magento\Bundle\Model\Resource\Selection $bundleSelection,
55-
\Magento\Catalog\Helper\Catalog $helperCatalog,
56-
\Magento\Bundle\Helper\Data $bundleData
42+
\Magento\Bundle\Model\Resource\Selection $bundleSelection
5743
) {
58-
$this->_helperCatalog = $helperCatalog;
59-
$this->_bundleData = $bundleData;
60-
$this->_bundleSelection = $bundleSelection;
61-
$this->_config = $config;
62-
$this->_productVisibility = $productVisibility;
44+
$this->bundleData = $bundleData;
45+
$this->productVisibility = $productVisibility;
46+
$this->config = $config;
47+
$this->bundleSelection = $bundleSelection;
6348
}
6449

6550
/**
@@ -70,15 +55,15 @@ public function __construct(
7055
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7156
* @SuppressWarnings(PHPMD.NPathComplexity)
7257
*/
73-
public function appendUpsellProducts($observer)
58+
public function invoke($observer)
7459
{
7560
/* @var $product \Magento\Catalog\Model\Product */
7661
$product = $observer->getEvent()->getProduct();
7762

7863
/**
7964
* Check is current product type is allowed for bundle selection product type
8065
*/
81-
if (!in_array($product->getTypeId(), $this->_bundleData->getAllowedSelectionTypes())) {
66+
if (!in_array($product->getTypeId(), $this->bundleData->getAllowedSelectionTypes())) {
8267
return $this;
8368
}
8469

@@ -94,7 +79,7 @@ public function appendUpsellProducts($observer)
9479
}
9580

9681
/* @var $resource \Magento\Bundle\Model\Resource\Selection */
97-
$resource = $this->_bundleSelection;
82+
$resource = $this->bundleSelection;
9883

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

11398
/* @var $bundleCollection \Magento\Catalog\Model\Resource\Product\Collection */
11499
$bundleCollection = $product->getCollection()->addAttributeToSelect(
115-
$this->_config->getProductAttributes()
100+
$this->config->getProductAttributes()
116101
)->addStoreFilter()->addMinimalPrice()->addFinalPrice()->addTaxPercents()->setVisibility(
117-
$this->_productVisibility->getVisibleInCatalogIds()
102+
$this->productVisibility->getVisibleInCatalogIds()
118103
);
119104

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

143128
return $this;
144129
}
145-
146-
/**
147-
* Add price index data for catalog product collection
148-
* only for front end
149-
*
150-
* @param \Magento\Framework\Event\Observer $observer
151-
* @return $this
152-
*/
153-
public function loadProductOptions($observer)
154-
{
155-
$collection = $observer->getEvent()->getCollection();
156-
/* @var $collection \Magento\Catalog\Model\Resource\Product\Collection */
157-
$collection->addPriceData();
158-
159-
return $this;
160-
}
161-
162-
/**
163-
* Setting attribute tab block for bundle
164-
*
165-
* @param \Magento\Framework\DataObject $observer
166-
* @return $this
167-
*/
168-
public function setAttributeTabBlock($observer)
169-
{
170-
$product = $observer->getEvent()->getProduct();
171-
if ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
172-
$this->_helperCatalog->setAttributeTabBlock(
173-
'Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes'
174-
);
175-
}
176-
return $this;
177-
}
178-
179-
/**
180-
* Initialize product options renderer with bundle specific params
181-
*
182-
* @param \Magento\Framework\Event\Observer $observer
183-
* @return $this
184-
*/
185-
public function initOptionRenderer(\Magento\Framework\Event\Observer $observer)
186-
{
187-
$block = $observer->getBlock();
188-
$block->addOptionsRenderCfg('bundle', 'Magento\Bundle\Helper\Catalog\Product\Configuration');
189-
return $this;
190-
}
191130
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Observer;
7+
8+
class InitOptionRenderer
9+
{
10+
/**
11+
* Initialize product options renderer with bundle specific params
12+
*
13+
* @param \Magento\Framework\Event\Observer $observer
14+
* @return $this
15+
*/
16+
public function invoke(\Magento\Framework\Event\Observer $observer)
17+
{
18+
$block = $observer->getBlock();
19+
$block->addOptionsRenderCfg('bundle', 'Magento\Bundle\Helper\Catalog\Product\Configuration');
20+
return $this;
21+
}
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Observer;
7+
8+
class LoadProductOptions
9+
{
10+
/**
11+
* Add price index data for catalog product collection
12+
* only for front end
13+
*
14+
* @param \Magento\Framework\Event\Observer $observer
15+
* @return $this
16+
*/
17+
public function invoke($observer)
18+
{
19+
$collection = $observer->getEvent()->getCollection();
20+
/* @var $collection \Magento\Catalog\Model\Resource\Product\Collection */
21+
$collection->addPriceData();
22+
23+
return $this;
24+
}
25+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Observer;
7+
8+
class SetAttributeTabBlock
9+
{
10+
/**
11+
* Catalog helper
12+
*
13+
* @var \Magento\Catalog\Helper\Catalog
14+
*/
15+
protected $helperCatalog;
16+
17+
/**
18+
* @param \Magento\Catalog\Helper\Catalog $helperCatalog
19+
*/
20+
public function __construct(\Magento\Catalog\Helper\Catalog $helperCatalog)
21+
{
22+
$this->helperCatalog = $helperCatalog;
23+
}
24+
25+
/**
26+
* Setting attribute tab block for bundle
27+
*
28+
* @param \Magento\Framework\Event\Observer $observer
29+
* @return $this
30+
*/
31+
public function invoke($observer)
32+
{
33+
$product = $observer->getEvent()->getProduct();
34+
if ($product->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
35+
$this->helperCatalog->setAttributeTabBlock(
36+
'Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes'
37+
);
38+
}
39+
return $this;
40+
}
41+
}

app/code/Magento/Bundle/etc/adminhtml/events.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
99
<event name="catalog_product_edit_action">
10-
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="setAttributeTabBlock" />
10+
<observer name="bundle_observer" instance="Magento\Bundle\Observer\SetAttributeTabBlock" method="invoke" />
1111
</event>
1212
<event name="catalog_product_new_action">
13-
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="setAttributeTabBlock" />
13+
<observer name="bundle_observer" instance="Magento\Bundle\Observer\SetAttributeTabBlock" method="invoke" />
1414
</event>
1515
</config>

app/code/Magento/Bundle/etc/frontend/events.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
99
<event name="catalog_product_upsell">
10-
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="appendUpsellProducts" />
10+
<observer name="bundle_observer" instance="Magento\Bundle\Observer\AppendUpsellProducts" method="invoke"/>
1111
</event>
1212
<event name="catalog_product_collection_load_after">
13-
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="loadProductOptions" />
13+
<observer name="bundle_observer" instance="Magento\Bundle\Observer\LoadProductOptions" method="invoke"/>
1414
</event>
1515
<event name="product_option_renderer_init">
16-
<observer name="bundle_observer" instance="Magento\Bundle\Model\Observer" method="initOptionRenderer" />
16+
<observer name="bundle_observer" instance="Magento\Bundle\Observer\InitOptionRenderer" method="invoke"/>
1717
</event>
1818
</config>

app/code/Magento/CacheInvalidate/Model/Observer.php

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)