/**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function getCatalogPrice(\Magento\Catalog\Model\Product $product, \Magento\Store\Api\Data\StoreInterface $store = null, $inclTax = false)
 {
     // Workaround to avoid loading stock status by admin's website
     if ($store instanceof \Magento\Store\Api\Data\StoreInterface) {
         $currentStore = $this->storeManager->getStore();
         $this->storeManager->setCurrentStore($store->getId());
     }
     $subProducts = $product->getTypeInstance()->getAssociatedProducts($product);
     if ($store instanceof \Magento\Store\Api\Data\StoreInterface) {
         $this->storeManager->setCurrentStore($currentStore->getId());
     }
     if (!$subProducts) {
         return null;
     }
     $minPrice = null;
     foreach ($subProducts as $subProduct) {
         $subProduct->setWebsiteId($product->getWebsiteId())->setCustomerGroupId($product->getCustomerGroupId());
         if ($subProduct->isSalable()) {
             if ($this->commonPriceModel->getCatalogPrice($subProduct) < $minPrice || $minPrice === null) {
                 $minPrice = $this->commonPriceModel->getCatalogPrice($subProduct);
                 $product->setTaxClassId($subProduct->getTaxClassId());
             }
         }
     }
     return $minPrice;
 }
Example #2
0
 public function testGetCatalogRegularPriceWhenPoolContainsPriceModelForGivenProductType()
 {
     $this->productMock->expects($this->any())->method('getTypeId')->will($this->returnValue('custom_product_type'));
     $this->priceFactoryMock->expects($this->once())->method('create')->with('CustomProduct/Model/CatalogPrice')->will($this->returnValue($this->catalogPriceInterfaceMock));
     $this->catalogPriceInterfaceMock->expects($this->once())->method('getCatalogRegularPrice');
     $this->productMock->expects($this->never())->method('getPrice');
     $this->model->getCatalogRegularPrice($this->productMock);
 }
Example #3
0
 /**
  * Calculate final price
  *
  * @param Product $product
  * @param \Magento\Store\Model\Store $store
  * @param bool $inclTax
  * @param bool $isSalePriceAllowed
  * @return float|null
  */
 private function _getFinalPrice($product, $store, $inclTax, $isSalePriceAllowed)
 {
     // calculate sale_price attribute value
     $salePriceAttribute = $this->getGroupAttributeSalePrice();
     $salePriceMapValue = null;
     $finalPrice = null;
     if (!is_null($salePriceAttribute)) {
         $salePriceMapValue = $salePriceAttribute->getProductAttributeValue($product);
     }
     if (!is_null($salePriceMapValue) && floatval($salePriceMapValue) > 0.0001) {
         $finalPrice = $salePriceMapValue;
     } else {
         if ($isSalePriceAllowed) {
             $finalPrice = $this->catalogPrice->getCatalogPrice($product, $store, $inclTax);
         }
     }
     if ($product->getTypeId() != Product\Type::TYPE_BUNDLE) {
         $finalPrice = $this->_catalogData->getTaxPrice($product, $finalPrice, $inclTax, null, null, null, $product->getStoreId());
     }
     return $finalPrice;
 }