/** * Get the price value for one of selection product * * @return bool|float */ public function getValue() { if (null !== $this->value) { return $this->value; } $priceCode = $this->useRegularPrice ? BundleRegularPrice::PRICE_CODE : FinalPrice::PRICE_CODE; if ($this->bundleProduct->getPriceType() == Price::PRICE_TYPE_DYNAMIC) { // just return whatever the product's value is $value = $this->priceInfo->getPrice($priceCode)->getValue(); } else { // don't multiply by quantity. Instead just keep as quantity = 1 $selectionPriceValue = $this->selection->getSelectionPriceValue(); 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', ['product' => $product, 'qty' => $this->bundleProduct->getQty()]); $value = $product->getData('final_price') * ($selectionPriceValue / 100); } else { // calculate price for selection type fixed $value = $this->priceCurrency->convert($selectionPriceValue) * $this->quantity; } } if (!$this->useRegularPrice) { $value = $this->discountCalculator->calculateDiscount($this->bundleProduct, $value); } $this->value = $this->priceCurrency->round($value); return $this->value; }
/** * @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()); }
/** * 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; }
/** * Retrieve Qty from item * * @param \Magento\Wishlist\Model\Item|\Magento\Catalog\Model\Product $item * @return float */ public function getQty($item) { $qty = $item->getQty() * 1; if (!$qty) { $qty = 1; } return $qty; }
/** * Retrieve params for updating product in wishlist * * @param \Magento\Catalog\Model\Product|\Magento\Wishlist\Model\Item $item * * @return string|false */ public function getUpdateParams($item) { $itemId = null; if ($item instanceof \Magento\Catalog\Model\Product) { $itemId = $item->getWishlistItemId(); $productId = $item->getId(); } if ($item instanceof \Magento\Wishlist\Model\Item) { $itemId = $item->getId(); $productId = $item->getProduct()->getId(); } $url = $this->_getUrl('wishlist/index/updateItemOptions'); if ($itemId) { $params = ['id' => $itemId, 'product' => $productId, 'qty' => $item->getQty()]; return $this->_postDataHelper->getPostData($url, $params); } return false; }
/** * Test for get qty */ public function testGetQty() { $this->model->setQty(1); $this->assertEquals(1, $this->model->getQty()); }
/** * {@inheritdoc} */ public function convert(\Magento\Catalog\Model\Product $product) { return [ProductLink::TYPE => $product->getTypeId(), ProductLink::SKU => $product->getSku(), ProductLink::POSITION => $product->getPosition(), ProductLink::CUSTOM_ATTRIBUTES_KEY => [[AttributeValue::ATTRIBUTE_CODE => 'qty', AttributeValue::VALUE => $product->getQty()]]]; }
/** * {@inheritdoc} */ public function convert(\Magento\Catalog\Model\Product $product) { return ['type' => $product->getTypeId(), 'sku' => $product->getSku(), 'position' => $product->getPosition(), 'custom_attributes' => [['attribute_code' => 'qty', 'value' => $product->getQty()]]]; }
/** * {@inheritdoc} */ public function getQty() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getQty'); if (!$pluginInfo) { return parent::getQty(); } else { return $this->___callPlugins('getQty', func_get_args(), $pluginInfo); } }