/** * prepare price * * @return Shopgate_Model_Catalog_Price */ protected function preparePrice() { $priceItem = new Shopgate_Model_Catalog_Price(); /** * set the price type */ $priceItem->setType(Configuration::get('SHOPGATE_EXPORT_PRICE_TYPE') ? Configuration::get('SHOPGATE_EXPORT_PRICE_TYPE') : Shopgate_Model_Catalog_Price::DEFAULT_PRICE_TYPE_NET); /** @var $this ->item ProductCore */ $priceItem->setPrice($this->getItemPrice($this->currentProduct->id, null, $this->getUseTax())); if ($this->currentProduct->wholesale_price != 0) { $priceItem->setCost($this->convertPrice($this->currentProduct->wholesale_price)); } $priceItem->setMinimumOrderAmount($this->currentProduct->minimal_quantity > 1 ? $this->currentProduct->minimal_quantity : 0); if ($this->currentProduct->unit_price != 0) { $basePrice = $this->currentProduct->unit_price; if ($this->getUseTax()) { $basePrice = $basePrice + $basePrice * $this->currentProduct->tax_rate / 100; } $basePrice = number_format($basePrice, 2); if ($this->currentProduct->unity != '') { $priceItem->setBasePrice(sprintf('%s %s / %s', $basePrice, $this->getPlugin()->getContext()->currency->iso_code, $this->currentProduct->unity)); } else { $priceItem->setBasePrice(sprintf('%s %s', $basePrice, $this->getPlugin()->getContext()->currency->iso_code)); } } $priceItem->setSalePrice($this->getItemPrice($this->currentProduct->id, null, $this->getUseTax(), true)); /** * tier prices */ foreach ($this->getTierPrices($priceItem, $this->currentProduct->id) as $tierPriceRule) { $priceItem->addTierPriceGroup($tierPriceRule); } return $priceItem; }
/** * set price */ public function setPrice() { $useParent = false; if (Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_USE_ROOT_PRICES) && $this->_parent != null && $this->_parent->isConfigurable()) { $useParent = true; } $price = $useParent ? $this->_parent->getPrice() : $this->item->getPrice(); if (Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_USE_PRICE_INDEX_ON_EXPORT)) { $index = Mage::getModel('catalog/product_indexer_price'); if ($this->item->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) { $finalPrice = $useParent ? $index->load($this->_parent->getId())->getMinPrice() : $index->load($this->item->getId())->getMinPrice(); } else { $finalPrice = $useParent ? $index->load($this->_parent->getId())->getFinalPrice() : $index->load($this->item->getId())->getFinalPrice(); } } else { $rulePrice = Mage::helper("shopgate/export")->calcProductPriceRule($useParent ? $this->_parent : $this->item); $finalPrice = $useParent ? $this->_parent->getFinalPrice() : $this->item->getFinalPrice(); if ($rulePrice && $rulePrice < $finalPrice) { $finalPrice = $rulePrice; } } if ($finalPrice <= 0) { $rulePrice = Mage::helper("shopgate/export")->calcProductPriceRule($this->item); $finalPrice = $this->item->getFinalPrice(); if ($rulePrice && $rulePrice < $finalPrice) { $finalPrice = $rulePrice; } } if (null != $this->_parent && $this->_parent->isConfigurable() && $useParent) { $totalOffset = 0; $totalPercentage = 0; $superAttributes = $this->_parent->getTypeInstance(true)->getConfigurableAttributes($this->_parent); foreach ($superAttributes as $superAttribute) { $code = $superAttribute->getProductAttribute()->getAttributeCode(); $index = $this->item->getData($code); $isPercent = false; if ($superAttribute->hasData('prices')) { foreach ($superAttribute->getPrices() as $saPrice) { if ($index == $saPrice["value_index"]) { if ($saPrice["is_percent"]) { $totalPercentage += $saPrice["pricing_value"]; $isPercent = true; } else { $totalOffset += $saPrice["pricing_value"]; } break; } } } } if ($price == $this->_parent->getPrice()) { $additionalPrice = $price * $totalPercentage / 100; $additionalPrice += $totalOffset; $this->_parent->setConfigurablePrice($additionalPrice, $isPercent); $this->_parent->setParentId(true); Mage::dispatchEvent('catalog_product_type_configurable_price', array('product' => $this->_parent)); $calculatedPrices = $this->_parent->getConfigurablePrice(); $price += $calculatedPrices; $finalPrice += $calculatedPrices; } } $priceModel = new Shopgate_Model_Catalog_Price(); if (Mage::getConfig()->getModuleConfig('DerModPro_BasePrice')->is('active', 'true') && Mage::getStoreConfig('catalog/baseprice/disable_ext') == 0) { $format = "{{baseprice}} / {{reference_amount}} {{reference_unit_short}}"; $basePrice = Mage::helper("baseprice")->getBasePriceLabel($this->item, $format); $basePrice = strip_tags($basePrice); $basePrice = htmlentities($basePrice, null, "UTF-8"); $priceModel->setBasePrice($basePrice); } $isGross = Mage::getStoreConfig(self::CONFIG_XML_PATH_PRICE_INCLUDES_TAX, $this->_getConfig()->getStoreViewId()); if ($this->item->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $this->item->getPriceType() == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) { $minimalPrice = Mage::helper('shopgate/config')->getIsMagentoVersionLower15() ? Mage::getModel('bundle/product_price')->getPrices($this->item, 'min') : Mage::getModel('bundle/product_price')->getPricesDependingOnTax($this->item, 'min', (bool) $isGross); $price = $minimalPrice; } $priceModel->setPrice($this->_formatPrice($price)); $priceModel->setCost($this->_formatPrice($this->item->getCost())); $priceModel->setSalePrice($this->_formatPrice($finalPrice)); $priceModel->setMsrp($this->_formatPrice($this->item->getMsrp())); if ($isGross) { $priceModel->setType(Shopgate_Model_Catalog_Price::DEFAULT_PRICE_TYPE_GROSS); } else { $priceModel->setType(Shopgate_Model_Catalog_Price::DEFAULT_PRICE_TYPE_NET); } $this->_createTierPriceNode($priceModel); $this->_createGroupPriceNode($priceModel); parent::setPrice($priceModel); }