示例#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
 /**
  * @param $price Shopgate_Model_Catalog_Price
  */
 protected function _createGroupPriceNode(&$price)
 {
     foreach ($this->item->getData('group_price') as $group) {
         if (($group['website_id'] == Mage::app()->getStore()->getWebsiteId() || $group['website_id'] == 0) && $price->getSalePrice() > $group['website_price']) {
             $tierPrice = new Shopgate_Model_Catalog_TierPrice();
             $tierPrice->setFromQuantity(1);
             $tierPrice->setReduction($price->getSalePrice() - $group['website_price']);
             $tierPrice->setReductionType(Shopgate_Model_Catalog_TierPrice::DEFAULT_TIER_PRICE_TYPE_FIXED);
             $tierPrice->setCustomerGroupUid($group['cust_group']);
             if ($this->item->isSuper() && Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_USE_ROOT_PRICES)) {
                 $tierPrice->setAggregateChildren(true);
             }
             $price->addTierPriceGroup($tierPrice);
         }
     }
 }