Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BundleSelectionPrice.php
Go to the documentation of this file.
1 <?php
7 
16 
24 {
28  const PRICE_CODE = 'bundle_selection';
29 
33  protected $bundleProduct;
34 
40  protected $eventManager;
41 
46 
50  protected $useRegularPrice;
51 
55  protected $selection;
56 
62  protected $excludeAdjustment = null;
63 
75  public function __construct(
76  Product $saleableItem,
77  $quantity,
83  $useRegularPrice = false,
84  $excludeAdjustment = null
85  ) {
86  parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
87  $this->bundleProduct = $bundleProduct;
88  $this->eventManager = $eventManager;
89  $this->discountCalculator = $discountCalculator;
90  $this->useRegularPrice = $useRegularPrice;
91  $this->selection = $saleableItem;
92  $this->excludeAdjustment = $excludeAdjustment;
93  }
94 
100  public function getValue()
101  {
102  if (null !== $this->value) {
103  return $this->value;
104  }
106  $bundleSelectionKey = 'bundle-selection-'
107  . ($this->useRegularPrice ? 'regular-' : '')
108  . 'value-'
109  . $product->getSelectionId();
110  if ($product->hasData($bundleSelectionKey)) {
111  return $product->getData($bundleSelectionKey);
112  }
113 
114  $priceCode = $this->useRegularPrice ? BundleRegularPrice::PRICE_CODE : FinalPrice::PRICE_CODE;
115  if ($this->bundleProduct->getPriceType() == Price::PRICE_TYPE_DYNAMIC) {
116  // just return whatever the product's value is
117  $value = $this->priceInfo
118  ->getPrice($priceCode)
119  ->getValue();
120  } else {
121  // don't multiply by quantity. Instead just keep as quantity = 1
122  $selectionPriceValue = $this->selection->getSelectionPriceValue();
123  if ($this->product->getSelectionPriceType()) {
124  // calculate price for selection type percent
125  $price = $this->bundleProduct->getPriceInfo()
127  ->getValue();
129  $product->setFinalPrice($price);
130  $this->eventManager->dispatch(
131  'catalog_product_get_final_price',
132  ['product' => $product, 'qty' => $this->bundleProduct->getQty()]
133  );
134  $price = $this->useRegularPrice ? $product->getData('price') : $product->getData('final_price');
135  $value = $price * ($selectionPriceValue / 100);
136  } else {
137  // calculate price for selection type fixed
138  $value = $this->priceCurrency->convert($selectionPriceValue);
139  }
140  }
141  if (!$this->useRegularPrice) {
142  $value = $this->discountCalculator->calculateDiscount($this->bundleProduct, $value);
143  }
144  $this->value = $this->priceCurrency->round($value);
145  $product->setData($bundleSelectionKey, $this->value);
146 
147  return $this->value;
148  }
149 
155  public function getAmount()
156  {
158  $bundleSelectionKey = 'bundle-selection'
159  . ($this->useRegularPrice ? 'regular-' : '')
160  . '-amount-'
161  . $product->getSelectionId();
162  if ($product->hasData($bundleSelectionKey)) {
163  return $product->getData($bundleSelectionKey);
164  }
165  $value = $this->getValue();
166  if (!isset($this->amount[$value])) {
167  $exclude = null;
168  if ($this->getProduct()->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
169  $exclude = $this->excludeAdjustment;
170  }
171  $this->amount[$value] = $this->calculator->getAmount(
172  $value,
173  $this->getProduct(),
174  $exclude
175  );
176  $product->setData($bundleSelectionKey, $this->amount[$value]);
177  }
178 
179  return $this->amount[$value];
180  }
181 
185  public function getProduct()
186  {
187  if ($this->bundleProduct->getPriceType() == Price::PRICE_TYPE_DYNAMIC) {
188  return parent::getProduct();
189  }
190  return $this->bundleProduct;
191  }
192 }
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9
if( $block->displayPriceExclTax()||$block->displayBothPrices())(__('Excl. Tax')) ?>"> <?php if ($block -> displayPriceWithWeeeDetails()): ?> <span class="cart-tax-total" data-mage-init=' Magento Weee Helper Data Magento Weee Helper Data title amount
Definition: unit.phtml:68
$price
__construct(Product $saleableItem, $quantity, CalculatorInterface $calculator, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, SaleableInterface $bundleProduct, ManagerInterface $eventManager, DiscountCalculator $discountCalculator, $useRegularPrice=false, $excludeAdjustment=null)