Example #1
0
 public function testGetPriceModel()
 {
     $this->_model->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
     $type = $this->_model->getPriceModel();
     $this->assertInstanceOf('Magento\\Bundle\\Model\\Product\\Price', $type);
     $this->assertSame($type, $this->_model->getPriceModel());
 }
 /**
  * {@inheritdoc}
  */
 public function getPriceModel()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getPriceModel');
     if (!$pluginInfo) {
         return parent::getPriceModel();
     } else {
         return $this->___callPlugins('getPriceModel', func_get_args(), $pluginInfo);
     }
 }
Example #3
0
 /**
  * Get unit/final price for a product model.
  *
  * @param Product $product the product model.
  * @param bool $finalPrice if final price.
  * @param bool $inclTax if tax is to be included.
  *
  * @return float
  */
 protected function _getProductPrice($product, $finalPrice = false, $inclTax = true)
 {
     switch ($product->getTypeId()) {
         // Get the bundle product "from" price.
         case ProductType::TYPE_BUNDLE:
             /** @var BundlePrice $priceModel */
             $priceModel = $product->getPriceModel();
             // todo: from price discount?
             $price = $priceModel->getTotalPrices($product, 'min', $inclTax);
             break;
             // No constant for this value was found (Magento ver. 1.0.0-beta).
             // Get the grouped product "minimal" price.
         // No constant for this value was found (Magento ver. 1.0.0-beta).
         // Get the grouped product "minimal" price.
         case 'grouped':
             /* @var $typeInstance GroupedType */
             $typeInstance = $product->getTypeInstance();
             $associatedProducts = $typeInstance->setStoreFilter($product->getStore(), $product)->getAssociatedProducts($product);
             $cheapestAssociatedProduct = null;
             $minimalPrice = 0;
             foreach ($associatedProducts as $associatedProduct) {
                 /** @var Product $associatedProduct */
                 $tmpPrice = $finalPrice ? $associatedProduct->getFinalPrice() : $associatedProduct->getPrice();
                 if ($minimalPrice === 0 || $minimalPrice > $tmpPrice) {
                     $minimalPrice = $tmpPrice;
                     $cheapestAssociatedProduct = $associatedProduct;
                 }
             }
             $price = $minimalPrice;
             if ($inclTax && $cheapestAssociatedProduct) {
                 $price = $this->_catalogHelper->getTaxPrice($cheapestAssociatedProduct, $price, true);
             }
             break;
             // No constant for this value was found (Magento ver. 1.0.0-beta).
             // The configurable product has the tax already applied in the
             // "final" price, but not in the regular price.
         // No constant for this value was found (Magento ver. 1.0.0-beta).
         // The configurable product has the tax already applied in the
         // "final" price, but not in the regular price.
         case 'configurable':
             if ($finalPrice) {
                 $price = $product->getFinalPrice();
             } elseif ($inclTax) {
                 $price = $this->_catalogHelper->getTaxPrice($product, $product->getPrice(), true);
             } else {
                 $price = $product->getPrice();
             }
             break;
         default:
             $price = $finalPrice ? $product->getFinalPrice() : $product->getPrice();
             if ($inclTax) {
                 $price = $this->_catalogHelper->getTaxPrice($product, $price, true);
             }
             break;
     }
     return $price;
 }
 public function testGetPriceModel()
 {
     $default = $this->_model->getPriceModel();
     $this->assertInstanceOf('Magento\\Catalog\\Model\\Product\\Type\\Price', $default);
     $this->assertSame($default, $this->_model->getPriceModel());
 }