/** * prepare children * * @return array */ protected function prepareChildren() { $result = array(); if ($this->currentProduct->hasAttributes()) { $combinationImages = $this->currentProduct->getCombinationImages($this->getPlugin()->getLanguageId()); // this function exists until the newest version (actual 1.6.0.14). // cause of the typo the function getAttributeCombinaisons is a wrapper function for getAttributeCombinations. $attributes = $this->currentProduct->getAttributeCombinaisons($this->getPlugin()->getLanguageId()); $combinations = array(); $attribute_groups = array(); foreach ($attributes as $a) { $combinations[$a['id_product_attribute']][$a['id_attribute_group']] = $a; $attribute_groups[$a['id_attribute_group']] = $a['group_name']; } foreach ($combinations as $combination) { $childProduct = (object) current($combination); /** * global info */ $childItemItem = new Shopgate_Model_Catalog_Product(); $childItemItem->setIsChild(true); $childItemItem->setUid(sprintf(ShopgateItemsItem::DEFAULT_ITEM_ATTRIBUTE_DIVIDER_PATTERN, $this->currentProduct->id, $childProduct->id_product_attribute)); /** * id default child */ if ($childProduct->default_on == 1) { $childItemItem->setIsDefaultChild(true); } /** * price */ $priceItem = new Shopgate_Model_Catalog_Price(); if ($childProduct->wholesale_price > 0 && $childProduct->wholesale_price != $this->currentProduct->wholesale_price) { /** * setCost */ $priceItem->setCost($this->convertPrice($childProduct->wholesale_price)); } if ($childProduct->minimal_quantity > 1) { $priceItem->setMinimumOrderAmount($childProduct->minimal_quantity); } /** * base price */ if ($this->currentProduct->unit_price != 0) { if (isset($childProduct->unit_price_impact) && $childProduct->unit_price_impact != 0) { $productPrice = $this->getItemPrice($this->currentProduct->id, $childProduct->id_product_attribute, true); $basePrice = $productPrice / $this->currentProduct->unit_price_ratio + $childProduct->unit_price_impact; if (!$this->getUseTax()) { $basePrice /= ($this->currentProduct->tax_rate + 100) / 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->setPrice($this->getItemPrice($this->currentProduct->id, $childProduct->id_product_attribute, $this->getUseTax())); $priceItem->setSalePrice($this->getItemPrice($this->currentProduct->id, $childProduct->id_product_attribute, $this->getUseTax(), true)); $childItemItem->setPrice($priceItem); /** * tier prices */ foreach ($this->getTierPrices($priceItem, $this->currentProduct->id, $childProduct->id_product_attribute) as $tierPriceRule) { $priceItem->addTierPriceGroup($tierPriceRule); } /** * tax class */ $childItemItem->setTaxClass($this->prepareTaxClass()); /** * stock */ $stockItem = new Shopgate_Model_Catalog_Stock(); $stockItem->setStockQuantity($childProduct->quantity); $stockItem->setMinimumOrderQuantity($childProduct->minimal_quantity > 1 ? $childProduct->minimal_quantity : 0); /* * needs to be set, because an internal function of Prestashop (Product::checkQty) needs to know what attribute is set */ $this->currentProduct->id_product_attribute = $childProduct->id_product_attribute; /* * we need to check this for each child because of the different stock quantity a attribute can have */ $stockItem->setIsSaleable($this->prepareIsSaleable($this->currentProduct, $stockItem->getStockQuantity())); $stockItem->setAvailabilityText($this->prepareAvailableText($stockItem->getIsSaleable(), $stockItem->getStockQuantity(), $this->currentProduct->out_of_stock)); $childItemItem->setStock($stockItem); /** * identifiers */ foreach ($this->prepareIdentifiers($childProduct) as $identifier) { $childItemItem->addIdentifier($identifier); } /** * attribute */ foreach ($combination as $combinationItem) { $attributeItem = new Shopgate_Model_Catalog_Attribute(); $attributeItem->setGroupUid($combinationItem['id_attribute_group']); $attributeItem->setUid($combinationItem['id_attribute']); $attributeItem->setLabel($combinationItem['attribute_name']); $childItemItem->addAttribute($attributeItem); } /** * images */ if (is_array($combinationImages) && array_key_exists($childProduct->id_product_attribute, $combinationImages)) { foreach ($this->prepareImages($combinationImages[$childProduct->id_product_attribute]) as $image) { $childItemItem->addImage($image); } } $result[] = $childItemItem; } } return $result; }
public function setPrice() { parent::setPrice($this->getAdditionalInfo('price')); }
/** * 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); }