コード例 #1
0
 /**
  * Apply existing method
  *
  * @param MatheusGontijo_EasyShippingRules_Model_Existingmethod $method
  */
 protected function _applyExistingMethod(MatheusGontijo_EasyShippingRules_Model_Existingmethod $method)
 {
     $ratesForApply = $this->_ratesForApply($method->getShippingMethodCodesFormatted());
     if (!$ratesForApply) {
         return;
     }
     foreach ($ratesForApply as $rateKey => $rate) {
         /** @var Mage_Shipping_Model_Rate_Result_Method $rate */
         /**
          * Hide rate according price action
          */
         if ($method->getAction() == MatheusGontijo_EasyShippingRules_Model_Existingmethod::HIDE_ACTION) {
             unset($this->_rates[$rateKey]);
             continue;
         }
         if ($method->getName()) {
             $rate->setName($method->getName());
         }
         if ($method->getName()) {
             $rate->setName($method->getName());
         }
         $price = 0;
         if ($method->getPricePercentage()) {
             $price = $method->getPricePercentage();
         } else {
             /**
              * it makes no sense apply all price conditions
              * because each iteration will replace iteration before.
              * In this case admin user should setting price in method, not in rules
              */
             foreach ($method->getRules() as $rule) {
                 $price = $rule->getPricePercentage();
                 break;
             }
         }
         if ($method->getPriceAction() == MatheusGontijo_EasyShippingRules_Helper_Data::FIXED_PER_ITEM_QTY_PRICE_ACTION) {
             $price = Mage::getSingleton('checkout/cart')->getQuote()->getItemsQty() * $price;
         } elseif ($method->getPriceAction() == MatheusGontijo_EasyShippingRules_Helper_Data::SUBTOTAL_PERCENTAGE_PRICE_ACTION) {
             $price = $this->_getSubtotal() * ($price / 100);
         } elseif ($method->getPriceAction() == MatheusGontijo_EasyShippingRules_Helper_Data::RATE_PERCENTAGE_PRICE_ACTION) {
             $price = $rate->getPrice() * ($price / 100);
         }
         switch ($method->getAction()) {
             case MatheusGontijo_EasyShippingRules_Model_Existingmethod::OVERWRITE_ACTION:
                 $rate->setPrice($price);
                 break;
             case MatheusGontijo_EasyShippingRules_Model_Existingmethod::DISCOUNT_ACTION:
                 $discountPrice = max($rate->getPrice() - $price, 0);
                 $rate->setPrice($discountPrice);
                 break;
             case MatheusGontijo_EasyShippingRules_Model_Existingmethod::SURCHARGE_ACTION:
                 $rate->setPrice($rate->getPrice() + $price);
                 break;
         }
     }
 }
コード例 #2
0
 /**
  * Add existing method filter
  *
  * @param MatheusGontijo_EasyShippingRules_Model_Existingmethod $method
  *
  * @return MatheusGontijo_EasyShippingRules_Model_Resource_Rule_Collection
  */
 public function addExistingMethodFilter(MatheusGontijo_EasyShippingRules_Model_Existingmethod $method)
 {
     $read = $this->getResource()->getReadConnection();
     $this->getSelect()->join(array('existingmethod_rule' => $this->getTable('easyshippingrules/existing_method_rule')), $read->quoteInto('main_table.easyshippingrules_rule_id = existingmethod_rule.easyshippingrules_rule_id ' . 'AND existingmethod_rule.easyshippingrules_existing_method_id = ?', $method->getId()), array());
     return $this;
 }