예제 #1
0
 /**
  * returns an array of Shopgate_Model_Catalog_TierPrice
  *
  * @param Shopgate_Model_Catalog_Price $priceItem
  * @param int $itemId
  * @param int $variantId
  * @return array of Shopgate_Model_Catalog_TierPrice
  */
 protected function getTierPrices($priceItem, $itemId, $variantId = null)
 {
     $tierPriceRules = array();
     $tierPrices = $this->getTierPricesFromDb($itemId);
     if (version_compare(_PS_VERSION_, '1.5.0.5', '<=')) {
         $shopId = $this->getPlugin()->getContext()->shop->getID();
     } else {
         $shopId = $this->getPlugin()->getContext()->shop->getContextShopID();
     }
     if (is_array($tierPrices)) {
         $overallValidRuleWithQuantityOneAvailable = false;
         $visitorRuleWithQuantityOneAvailable = false;
         foreach ($tierPrices as $tierPrice) {
             if ($tierPrice['from_quantity'] == 1 && $tierPrice['id_group'] == 1) {
                 $visitorRuleWithQuantityOneAvailable = true;
             }
             if ($tierPrice['from_quantity'] == 1 && $tierPrice['id_group'] == 0) {
                 $overallValidRuleWithQuantityOneAvailable = true;
             }
         }
         $customerGroups = array();
         if ($visitorRuleWithQuantityOneAvailable && $overallValidRuleWithQuantityOneAvailable) {
             $customerGroups = Group::getGroups(Configuration::get('SHOPGATE_LANGUAGE_ID'), $this->getPlugin()->getContext()->shop->id ? $this->getPlugin()->getContext()->shop->id : false);
         }
         foreach ($tierPrices as $tierPrice) {
             if ($tierPrice['from_quantity'] == 1 && $tierPrice['id_group'] == 0 && !$visitorRuleWithQuantityOneAvailable) {
                 /*
                  * In case the tier price starts from quantity 1 and the discount is available for all user this should be ignored as tier price because its already honoured as sale price
                  * Exception: There is a default/Visitor rule!
                  */
                 continue;
             }
             if (($validFrom = strtotime($tierPrice['from'])) >= 0 && time() <= $validFrom) {
                 /*
                  * the discount is valid from a specific date but the date is still in the future => ignore this rule
                  */
                 continue;
             }
             if (($validTo = strtotime($tierPrice['to'])) >= 0 && time() >= $validTo) {
                 /*
                  * the discount is valid to a specific date but the date is in the past => ignore this rule
                  */
                 continue;
             }
             if (!empty($tierPrice['id_currency']) && $tierPrice['id_currency'] != $this->getPlugin()->getContext()->currency->iso_code) {
                 /*
                  * the discount is only valid for one specific currency and we are not exporting this specific currency
                  */
                 continue;
             }
             /*
              * hack for Prestashop versions >= 1.5.0.15. for more details see: file: classes/SpecificPrice.php method: getSpecificPrice()
              * Since 1.5.0.15 Prestashop uses in case PS_QTY_DISCOUNT_ON_COMBINATION is set to 0 (default) the cart quantity for finding the correct price.
              */
             Configuration::set('PS_QTY_DISCOUNT_ON_COMBINATION', 1);
             $finalPrice = $this->getItemPrice($itemId, $variantId, $this->getUseTax(), true, (int) $tierPrice['from_quantity']);
             $tierPriceItem = new Shopgate_Model_Catalog_TierPrice();
             $tierPriceItem->setFromQuantity($tierPrice['from_quantity']);
             $tierPriceItem->setReductionType(Shopgate_Model_Catalog_TierPrice::DEFAULT_TIER_PRICE_TYPE_FIXED);
             if (array_key_exists('id_group', $tierPrice) && $tierPrice['id_group'] != 0) {
                 $tierPriceItem->setCustomerGroupUid($tierPrice['id_group']);
                 if (version_compare(_PS_VERSION_, '1.4.0.17', '<')) {
                     /*
                      * We don't support customer group related prices in versions lower then 1.4.0.17
                      * because there is no proper way to let the shopping cart solution calculate the price
                      */
                     continue;
                 } else {
                     $finalPrice = $this->calculateCustomerGroupPrice($shopId, $itemId, $variantId, $tierPrice['id_group'], (int) $tierPrice['from_quantity']);
                 }
             }
             if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && $tierPrice['from_quantity'] == 1 && $tierPrice['id_group'] == 0 && $visitorRuleWithQuantityOneAvailable) {
                 /**
                  * customer groups have changed since 1.5.0.1. The customer group with id = 1 is called "Visitor"
                  * and must be - with a quantity of 1 and in combination with another general rule thats also quantity of 1 - treated in a special way.
                  *
                  * The one rule must be split off in separate rules for each customer group except the Visitor rule
                  */
                 $tierPriceItemCache = $tierPriceItem;
                 foreach ($customerGroups as $customerGroup) {
                     if ($customerGroup['id_group'] == 1) {
                         /**
                          * skip Visitor price rule
                          */
                         continue;
                     }
                     $tierPriceItem = clone $tierPriceItemCache;
                     $tierPriceItem->setCustomerGroupUid($customerGroup['id_group']);
                     $finalPrice = $this->calculateCustomerGroupPrice($shopId, $itemId, $variantId, $customerGroup['id_group'], (int) $tierPrice['from_quantity']);
                     $this->addTierPriceRule($priceItem->getSalePrice() - $finalPrice, $tierPriceItem, $tierPriceRules);
                 }
                 continue;
             }
             $this->addTierPriceRule($priceItem->getSalePrice() - $finalPrice, $tierPriceItem, $tierPriceRules);
         }
     }
     return $tierPriceRules;
 }
예제 #2
0
파일: Xml.php 프로젝트: buttasg/cowgirlk
 /**
  * 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);
 }