Example #1
0
 /**
  * @magentoDbIsolation disabled
  * @magentoAppIsolation enabled
  * @magentoDataFixture Magento/Catalog/_files/price_row_fixture.php
  */
 public function testProductsUpdate()
 {
     $this->_product->load(1);
     $this->_processor->reindexList([$this->_product->getId()]);
     $categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\CategoryFactory');
     $listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Block\\Product\\ListProduct');
     $category = $categoryFactory->create()->load(9);
     $layer = $listProduct->getLayer();
     $layer->setCurrentCategory($category);
     $productCollection = $layer->getProductCollection();
     $this->assertEquals(1, $productCollection->count());
     /** @var $product \Magento\Catalog\Model\Product */
     foreach ($productCollection as $product) {
         $this->assertEquals($this->_product->getId(), $product->getId());
         $this->assertEquals($this->_product->getPrice(), $product->getPrice());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getPrice()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getPrice');
     if (!$pluginInfo) {
         return parent::getPrice();
     } else {
         return $this->___callPlugins('getPrice', func_get_args(), $pluginInfo);
     }
 }
Example #3
0
 /**
  * @param \Magento\Catalog\Model\Product $product
  */
 private function assertProductInfo($product)
 {
     $data = [1 => ['sku' => 'simple', 'name' => 'Simple Product', 'price' => '10', 'qty' => '1', 'position' => '1'], 21 => ['sku' => 'virtual-product', 'name' => 'Virtual Product', 'price' => '10', 'qty' => '2', 'position' => '2']];
     $productId = $product->getId();
     $this->assertEquals($data[$productId]['sku'], $product->getSku());
     $this->assertEquals($data[$productId]['name'], $product->getName());
     $this->assertEquals($data[$productId]['price'], $product->getPrice());
     $this->assertEquals($data[$productId]['qty'], $product->getQty());
     $this->assertEquals($data[$productId]['position'], $product->getPosition());
 }
Example #4
0
 /**
  * Get base price with apply Group, Tier, Special prises
  *
  * @param Product $product
  * @param float|null $qty
  *
  * @return float
  */
 public function getBasePrice($product, $qty = null)
 {
     $price = (double) $product->getPrice();
     return min($this->_applyGroupPrice($product, $price), $this->_applyTierPrice($product, $qty, $price), $this->_applySpecialPrice($product, $price));
 }
Example #5
0
 /**
  * Get product price including store convertion rate
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param null|string $format
  * @return float|string
  * @deprecated
  */
 public function getProductPrice($product, $format = null)
 {
     try {
         $value = $product->getPrice();
         $value = $format ? $this->priceCurrency->convertAndFormat($value) : $this->priceCurrency->convert($value);
     } catch (\Exception $e) {
         $value = $e->getMessage();
     }
     return $value;
 }
Example #6
0
 /**
  * Get product price including store convertion rate
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param null|string $format
  * @return float|string
  * @deprecated
  */
 public function getProductPrice($product, $format = null)
 {
     try {
         $value = $product->getPrice();
         $value = $this->_storeManager->getStore()->convertPrice($value, $format);
     } catch (\Exception $e) {
         $value = $e->getMessage();
     }
     return $value;
 }
Example #7
0
 /**
  * Retrieve product price
  *
  * @param ModelProduct $product
  * @return float
  */
 public function getPrice($product)
 {
     return $product->getPrice();
 }
Example #8
0
 /**
  * @return float
  */
 public function getPrice()
 {
     return parent::getPrice() * 3;
 }
Example #9
0
 /**
  * Set current attribute to entry (for specified product)
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Gdata\Gshopping\Entry $entry
  * @return \Magento\Framework\Gdata\Gshopping\Entry
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function convertAttribute($product, $entry)
 {
     $entry->cleanTaxes();
     if ($this->_taxData->getConfig()->priceIncludesTax()) {
         return $entry;
     }
     $defaultCustomerTaxClassId = $this->_getDefaultCustomerTaxClassId($product->getStoreId());
     $rates = $this->_taxRateManagement->getRatesByCustomerAndProductTaxClassId($defaultCustomerTaxClassId, $product->getTaxClassId());
     $targetCountry = $this->_config->getTargetCountry($product->getStoreId());
     $ratesTotal = 0;
     foreach ($rates as $rate) {
         $countryId = $rate->getTaxCountryId();
         $postcode = $rate->getTaxPostcode();
         if ($targetCountry == $countryId) {
             $regions = $this->_getRegionsByRegionId($rate->getTaxRegionId(), $postcode);
             $ratesTotal += count($regions);
             if ($ratesTotal > self::RATES_MAX) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('Google shopping only supports %1 tax rates per product', self::RATES_MAX));
             }
             foreach ($regions as $region) {
                 $adjustments = $product->getPriceInfo()->getAdjustments();
                 if (array_key_exists('tax', $adjustments)) {
                     $taxIncluded = true;
                 } else {
                     $taxIncluded = false;
                 }
                 $quoteDetailsItemDataArray = ['code' => $product->getSku(), 'type' => 'product', 'tax_class_key' => [TaxClassKeyInterface::KEY_TYPE => TaxClassKeyInterface::TYPE_ID, TaxClassKeyInterface::KEY_VALUE => $product->getTaxClassId()], 'unit_price' => $product->getPrice(), 'quantity' => 1, 'tax_included' => $taxIncluded, 'short_description' => $product->getName()];
                 $billingAddressDataArray = ['country_id' => $countryId, 'region' => ['region_id' => $rate->getTaxRegionId()], 'postcode' => $postcode];
                 $shippingAddressDataArray = ['country_id' => $countryId, 'region' => ['region_id' => $rate->getTaxRegionId()], 'postcode' => $postcode];
                 $quoteDetailsDataArray = ['billing_address' => $billingAddressDataArray, 'shipping_address' => $shippingAddressDataArray, 'customer_tax_class_key' => [TaxClassKeyInterface::KEY_TYPE => TaxClassKeyInterface::TYPE_ID, TaxClassKeyInterface::KEY_VALUE => $defaultCustomerTaxClassId], 'items' => [$quoteDetailsItemDataArray]];
                 $quoteDetailsObject = $this->_quoteDetailsFactory->create();
                 $this->dataObjectHelper->populateWithArray($quoteDetailsObject, $quoteDetailsDataArray, '\\Magento\\Tax\\Api\\Data\\QuoteDetailsInterface');
                 $taxDetails = $this->_taxCalculationService->calculateTax($quoteDetailsObject, $product->getStoreId());
                 $taxRate = $taxDetails->getTaxAmount() / $taxDetails->getSubtotal() * 100;
                 $entry->addTax(['tax_rate' => $taxRate, 'tax_country' => $countryId, 'tax_region' => $region]);
             }
         }
     }
     return $entry;
 }
 public function testGetPrice()
 {
     $this->assertEmpty($this->_model->getPrice());
     $this->_model->setPrice(10.0);
     $this->assertEquals(10.0, $this->_model->getPrice());
 }