66namespace Magento \Bundle \Block \Catalog \Product \View \Type ;
77
88use Magento \Bundle \Model \Option ;
9+ use Magento \Bundle \Model \Product \Price ;
10+ use Magento \Bundle \Model \Product \PriceFactory ;
11+ use Magento \Bundle \Model \Product \Type ;
12+ use Magento \Catalog \Block \Product \Context ;
13+ use Magento \Catalog \Block \Product \View \AbstractView ;
914use Magento \Catalog \Model \Product ;
15+ use Magento \Catalog \Pricing \Price \FinalPrice ;
16+ use Magento \Catalog \Pricing \Price \RegularPrice ;
17+ use Magento \CatalogRule \Model \ResourceModel \Product \CollectionProcessor ;
18+ use Magento \Framework \App \ObjectManager ;
1019use Magento \Framework \DataObject ;
20+ use Magento \Framework \Json \EncoderInterface ;
21+ use Magento \Framework \Locale \FormatInterface ;
22+ use Magento \Framework \Stdlib \ArrayUtils ;
1123
1224/**
1325 * Catalog bundle product info block
1426 *
1527 * @api
16- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17- * @api
1828 * @since 100.0.2
29+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1930 */
20- class Bundle extends \ Magento \ Catalog \ Block \ Product \ View \ AbstractView
31+ class Bundle extends AbstractView
2132{
22-
2333 /**
2434 * @var array
2535 */
@@ -33,17 +43,17 @@ class Bundle extends \Magento\Catalog\Block\Product\View\AbstractView
3343 protected $ catalogProduct ;
3444
3545 /**
36- * @var \Magento\Bundle\Model\Product\ PriceFactory
46+ * @var PriceFactory
3747 */
3848 protected $ productPriceFactory ;
3949
4050 /**
41- * @var \Magento\Framework\Json\ EncoderInterface
51+ * @var EncoderInterface
4252 */
4353 protected $ jsonEncoder ;
4454
4555 /**
46- * @var \Magento\Framework\Locale\ FormatInterface
56+ * @var FormatInterface
4757 */
4858 protected $ localeFormat ;
4959
@@ -63,22 +73,24 @@ class Bundle extends \Magento\Catalog\Block\Product\View\AbstractView
6373 private $ optionsPosition = [];
6474
6575 /**
66- * @param \Magento\Catalog\Block\Product\ Context $context
67- * @param \Magento\Framework\Stdlib\ ArrayUtils $arrayUtils
76+ * @param Context $context
77+ * @param ArrayUtils $arrayUtils
6878 * @param \Magento\Catalog\Helper\Product $catalogProduct
69- * @param \Magento\Bundle\Model\Product\ PriceFactory $productPrice
70- * @param \Magento\Framework\Json\ EncoderInterface $jsonEncoder
71- * @param \Magento\Framework\Locale\ FormatInterface $localeFormat
79+ * @param PriceFactory $productPrice
80+ * @param EncoderInterface $jsonEncoder
81+ * @param FormatInterface $localeFormat
7282 * @param array $data
83+ * @param CollectionProcessor|null $catalogRuleProcessor
7384 */
7485 public function __construct (
75- \ Magento \ Catalog \ Block \ Product \ Context $ context ,
76- \ Magento \ Framework \ Stdlib \ ArrayUtils $ arrayUtils ,
86+ Context $ context ,
87+ ArrayUtils $ arrayUtils ,
7788 \Magento \Catalog \Helper \Product $ catalogProduct ,
78- \Magento \Bundle \Model \Product \PriceFactory $ productPrice ,
79- \Magento \Framework \Json \EncoderInterface $ jsonEncoder ,
80- \Magento \Framework \Locale \FormatInterface $ localeFormat ,
81- array $ data = []
89+ PriceFactory $ productPrice ,
90+ EncoderInterface $ jsonEncoder ,
91+ FormatInterface $ localeFormat ,
92+ array $ data = [],
93+ ?CollectionProcessor $ catalogRuleProcessor = null
8294 ) {
8395 $ this ->catalogProduct = $ catalogProduct ;
8496 $ this ->productPriceFactory = $ productPrice ;
@@ -89,22 +101,8 @@ public function __construct(
89101 $ arrayUtils ,
90102 $ data
91103 );
92- }
93-
94- /**
95- * Return catalog rule processor or creates processor if it does not exist
96- *
97- * @deprecated 100.2.0
98- * @return \Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor
99- */
100- private function getCatalogRuleProcessor ()
101- {
102- if ($ this ->catalogRuleProcessor === null ) {
103- $ this ->catalogRuleProcessor = \Magento \Framework \App \ObjectManager::getInstance ()
104- ->get (\Magento \CatalogRule \Model \ResourceModel \Product \CollectionProcessor::class);
105- }
106-
107- return $ this ->catalogRuleProcessor ;
104+ $ this ->catalogRuleProcessor = $ catalogRuleProcessor ?? ObjectManager::getInstance ()
105+ ->get (CollectionProcessor::class);
108106 }
109107
110108 /**
@@ -120,7 +118,7 @@ public function getOptions($stripSelection = false)
120118 {
121119 if (!$ this ->options ) {
122120 $ product = $ this ->getProduct ();
123- /** @var \Magento\Bundle\Model\Product\ Type $typeInstance */
121+ /** @var Type $typeInstance */
124122 $ typeInstance = $ product ->getTypeInstance ();
125123 $ typeInstance ->setStoreFilter ($ product ->getStoreId (), $ product );
126124
@@ -130,7 +128,7 @@ public function getOptions($stripSelection = false)
130128 $ typeInstance ->getOptionsIds ($ product ),
131129 $ product
132130 );
133- $ this ->getCatalogRuleProcessor () ->addPriceData ($ selectionCollection );
131+ $ this ->catalogRuleProcessor ->addPriceData ($ selectionCollection );
134132 $ selectionCollection ->addTierPriceData ();
135133
136134 $ this ->options = $ optionCollection ->appendSelections (
@@ -151,10 +149,7 @@ public function getOptions($stripSelection = false)
151149 public function hasOptions ()
152150 {
153151 $ this ->getOptions ();
154- if (empty ($ this ->options ) || !$ this ->getProduct ()->isSalable ()) {
155- return false ;
156- }
157- return true ;
152+ return !(empty ($ this ->options ) || !$ this ->getProduct ()->isSalable ());
158153 }
159154
160155 /**
@@ -255,7 +250,7 @@ private function getSelectionItemData(Product $product, Product $selection)
255250 ->getOptionSelectionAmount ($ selection )
256251 ->getValue ();
257252
258- $ selection = [
253+ return [
259254 'qty ' => $ qty ,
260255 'customQty ' => $ selection ->getSelectionCanChangeQty (),
261256 'optionId ' => $ selection ->getId (),
@@ -275,8 +270,6 @@ private function getSelectionItemData(Product $product, Product $selection)
275270 'name ' => $ selection ->getName (),
276271 'canApplyMsrp ' => false ,
277272 ];
278-
279- return $ selection ;
280273 }
281274
282275 /**
@@ -371,16 +364,16 @@ private function getOptionItemData(Option $option, Product $product, $position)
371364 */
372365 private function getConfigData (Product $ product , array $ options )
373366 {
374- $ isFixedPrice = $ this ->getProduct ()->getPriceType () == \ Magento \ Bundle \ Model \ Product \ Price::PRICE_TYPE_FIXED ;
367+ $ isFixedPrice = $ this ->getProduct ()->getPriceType () == Price::PRICE_TYPE_FIXED ;
375368
376369 $ productAmount = $ product
377370 ->getPriceInfo ()
378- ->getPrice (\ Magento \ Catalog \ Pricing \ Price \ FinalPrice::PRICE_CODE )
371+ ->getPrice (FinalPrice::PRICE_CODE )
379372 ->getPriceWithoutOption ();
380373
381374 $ baseProductAmount = $ product
382375 ->getPriceInfo ()
383- ->getPrice (\ Magento \ Catalog \ Pricing \ Price \ RegularPrice::PRICE_CODE )
376+ ->getPrice (RegularPrice::PRICE_CODE )
384377 ->getAmount ();
385378
386379 $ config = [
0 commit comments