Example #1
0
 /**
  * @param Product $product
  * @param Product $bundle
  * @return Metadata
  */
 public function createDataFromModel(Product $product, Product $bundle)
 {
     $selectionPriceType = $selectionPrice = null;
     /** @var \Magento\Bundle\Model\Selection $product */
     if ($bundle->getPriceType()) {
         $selectionPriceType = $product->getSelectionPriceType();
         $selectionPrice = $product->getSelectionPriceValue();
     }
     $this->builder->populateWithArray($product->getData())->setDefault($product->getIsDefault())->setQty($product->getSelectionQty())->setDefined($product->getSelectionCanChangeQty())->setPrice($selectionPrice)->setPriceType($selectionPriceType);
     return $this->builder->create();
 }
 /**
  * @param \Magento\Catalog\Model\Product $selection
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Bundle\Api\Data\LinkInterface
  */
 private function buildLink(\Magento\Catalog\Model\Product $selection, \Magento\Catalog\Model\Product $product)
 {
     $selectionPriceType = $selectionPrice = null;
     /** @var \Magento\Bundle\Model\Selection $product */
     if ($product->getPriceType()) {
         $selectionPriceType = $selection->getSelectionPriceType();
         $selectionPrice = $selection->getSelectionPriceValue();
     }
     /** @var \Magento\Bundle\Api\Data\LinkInterface $link */
     $link = $this->linkFactory->create();
     $this->dataObjectHelper->populateWithArray($link, $selection->getData(), '\\Magento\\Bundle\\Api\\Data\\LinkInterface');
     $link->setIsDefault($selection->getIsDefault())->setQty($selection->getSelectionQty())->setIsDefined($selection->getSelectionCanChangeQty())->setPrice($selectionPrice)->setPriceType($selectionPriceType);
     return $link;
 }
Example #3
0
 /**
  * Calculate final price of selection
  * with take into account tier price
  *
  * @param  \Magento\Catalog\Model\Product $bundleProduct
  * @param  \Magento\Catalog\Model\Product $selectionProduct
  * @param  float                    $bundleQty
  * @param  float                    $selectionQty
  * @param  bool                       $multiplyQty
  * @param  bool                       $takeTierPrice
  * @return float
  */
 public function getSelectionFinalTotalPrice($bundleProduct, $selectionProduct, $bundleQty, $selectionQty, $multiplyQty = true, $takeTierPrice = true)
 {
     if (null === $bundleQty) {
         $bundleQty = 1.0;
     }
     if ($selectionQty === null) {
         $selectionQty = $selectionProduct->getSelectionQty();
     }
     if ($bundleProduct->getPriceType() == self::PRICE_TYPE_DYNAMIC) {
         $price = $selectionProduct->getFinalPrice($takeTierPrice ? $selectionQty : 1);
     } else {
         if ($selectionProduct->getSelectionPriceType()) {
             // percent
             $product = clone $bundleProduct;
             $product->setFinalPrice($this->getPrice($product));
             $this->_eventManager->dispatch('catalog_product_get_final_price', ['product' => $product, 'qty' => $bundleQty]);
             $price = $product->getData('final_price') * ($selectionProduct->getSelectionPriceValue() / 100);
         } else {
             // fixed
             $price = $selectionProduct->getSelectionPriceValue();
         }
     }
     if ($multiplyQty) {
         $price *= $selectionQty;
     }
     return min($price, $this->_applyGroupPrice($bundleProduct, $price), $this->_applyTierPrice($bundleProduct, $bundleQty, $price), $this->_applySpecialPrice($bundleProduct, $price));
 }
Example #4
0
 /**
  * Get formed data from option selection item
  *
  * @param Product $product
  * @param Product $selection
  * @return array
  */
 private function getSelectionItemData(Product $product, Product $selection)
 {
     $qty = $selection->getSelectionQty() * 1 ?: '1';
     $optionPriceAmount = $product->getPriceInfo()->getPrice('bundle_option')->getOptionSelectionAmount($selection);
     $finalPrice = $optionPriceAmount->getValue();
     $basePrice = $optionPriceAmount->getBaseAmount();
     $selection = ['qty' => $qty, 'customQty' => $selection->getSelectionCanChangeQty(), 'optionId' => $selection->getId(), 'prices' => ['oldPrice' => ['amount' => $basePrice], 'basePrice' => ['amount' => $basePrice], 'finalPrice' => ['amount' => $finalPrice]], 'priceType' => $selection->getSelectionPriceType(), 'tierPrice' => $this->getTierPrices($product, $selection), 'name' => $selection->getName(), 'canApplyMsrp' => false];
     return $selection;
 }