/**
  * @return SaleableInterface
  */
 public function getProduct()
 {
     if ($this->bundleProduct->getPriceType() == Price::PRICE_TYPE_DYNAMIC) {
         return parent::getProduct();
     } else {
         return $this->bundleProduct;
     }
 }
 /**
  * @param \Magento\Catalog\Model\Product\Attribute\Backend\Price $subject
  * @param \Closure $proceed
  * @param \Magento\Catalog\Model\Product|\Magento\Framework\Object $object
  * @return bool
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundValidate(\Magento\Catalog\Model\Product\Attribute\Backend\Price $subject, \Closure $proceed, $object)
 {
     if ($object instanceof \Magento\Catalog\Model\Product && $object->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE && $object->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
         return true;
     } else {
         return $proceed($object);
     }
 }
Example #3
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();
 }
Example #4
0
 /**
  * Get the price value for one of selection product
  *
  * @return bool|float
  */
 public function getValue()
 {
     if (null !== $this->value) {
         return $this->value;
     }
     if ($this->bundleProduct->getPriceType() == Price::PRICE_TYPE_DYNAMIC) {
         $value = $this->priceInfo->getPrice(FinalPrice::PRICE_CODE)->getValue();
     } else {
         if ($this->product->getSelectionPriceType()) {
             // calculate price for selection type percent
             $price = $this->bundleProduct->getPriceInfo()->getPrice(CatalogPrice\RegularPrice::PRICE_CODE)->getValue();
             $product = clone $this->bundleProduct;
             $product->setFinalPrice($price);
             $this->eventManager->dispatch('catalog_product_get_final_price', array('product' => $product, 'qty' => $this->bundleProduct->getQty()));
             $value = $product->getData('final_price') * ($this->product->getSelectionPriceValue() / 100);
         } else {
             // calculate price for selection type fixed
             $value = $this->product->getSelectionPriceValue() * $this->quantity;
         }
     }
     $this->value = $this->discountCalculator->calculateDiscount($this->bundleProduct, $value);
     return $this->value;
 }
Example #5
0
 /**
  * Disable MAP if it's bundle with dynamic price type
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return $this
  */
 public function beforeSave($product)
 {
     if (!$product instanceof \Magento\Catalog\Model\Product || $product->getTypeId() != \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE || $product->getPriceType() != \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
         return parent::beforeSave($product);
     }
     parent::beforeSave($product);
     $attributeCode = $this->getAttribute()->getName();
     $value = $product->getData($attributeCode);
     if (empty($value)) {
         $value = $this->_catalogData->isMsrpApplyToAll();
     }
     if ($value) {
         $product->setData($attributeCode, 0);
     }
     return $this;
 }
Example #6
0
 /**
  * Setting Bundle Items Data to product for father processing
  *
  * @param \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $subject
  * @param \Magento\Catalog\Model\Product $product
  *
  * @return \Magento\Catalog\Model\Product
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function afterInitialize(\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $subject, \Magento\Catalog\Model\Product $product)
 {
     if (($items = $this->request->getPost('bundle_options')) && !$product->getCompositeReadonly()) {
         $product->setBundleOptionsData($items);
     }
     if (($selections = $this->request->getPost('bundle_selections')) && !$product->getCompositeReadonly()) {
         $product->setBundleSelectionsData($selections);
     }
     if ($product->getPriceType() == '0' && !$product->getOptionsReadonly()) {
         $product->setCanSaveCustomOptions(true);
         if ($customOptions = $product->getProductOptions()) {
             foreach (array_keys($customOptions) as $key) {
                 $customOptions[$key]['is_delete'] = 1;
             }
             $product->setProductOptions($customOptions);
         }
     }
     $product->setCanSaveBundleSelections((bool) $this->request->getPost('affect_bundle_product_selections') && !$product->getCompositeReadonly());
     return $product;
 }
 /**
  * @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;
 }
 /**
  * @param \Magento\Catalog\Model\Product $product
  * @return void
  */
 protected function processDynamicOptionsData(\Magento\Catalog\Model\Product $product)
 {
     if ((int) $product->getPriceType() !== \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
         return;
     }
     if ($product->getOptionsReadonly()) {
         return;
     }
     $product->setCanSaveCustomOptions(true);
     $customOptions = $product->getProductOptions();
     if (!$customOptions) {
         return;
     }
     foreach (array_keys($customOptions) as $key) {
         $customOptions[$key]['is_delete'] = 1;
     }
     $newOptions = $product->getOptions();
     foreach ($customOptions as $customOptionData) {
         if ((bool) $customOptionData['is_delete']) {
             continue;
         }
         $customOption = $this->customOptionFactory->create(['data' => $customOptionData]);
         $customOption->setProductSku($product->getSku());
         $customOption->setOptionId(null);
         $newOptions[] = $customOption;
     }
     $product->setOptions($newOptions);
 }
Example #9
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 #10
0
 /**
  * Calculate amount for bundle product with all selection prices
  *
  * @param float $basePriceValue
  * @param Product $bundleProduct
  * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $selectionPriceList
  * @param null|string $exclude
  * @return \Magento\Framework\Pricing\Amount\AmountInterface
  */
 public function calculateBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude = null)
 {
     if ($bundleProduct->getPriceType() == Price::PRICE_TYPE_FIXED) {
         return $this->calculateFixedBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude);
     } else {
         return $this->calculateDynamicBundleAmount($basePriceValue, $bundleProduct, $selectionPriceList, $exclude);
     }
 }
Example #11
0
 /**
  * Get formed config data from calculated options data
  *
  * @param Product $product
  * @param array $options
  * @return array
  */
 private function getConfigData(Product $product, array $options)
 {
     $isFixedPrice = $this->getProduct()->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED;
     $productAmount = $product->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)->getPriceWithoutOption();
     $baseProductAmount = $product->getPriceInfo()->getPrice(\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE)->getAmount();
     $config = ['options' => $options, 'selected' => $this->selectedOptions, 'bundleId' => $product->getId(), 'priceFormat' => $this->localeFormat->getPriceFormat(), 'prices' => ['oldPrice' => ['amount' => $isFixedPrice ? $baseProductAmount->getValue() : 0], 'basePrice' => ['amount' => $isFixedPrice ? $productAmount->getBaseAmount() : 0], 'finalPrice' => ['amount' => $isFixedPrice ? $productAmount->getValue() : 0]], 'priceType' => $product->getPriceType(), 'isFixedPrice' => $isFixedPrice];
     return $config;
 }