各地区的Magento运输方式

时间:2014-07-15 00:11:27

标签: php magento methods shipping

我试图使运输方法依赖于地区/州。 我看看app / code / core / Mage / Shipping /我认为可能需要3个文件来实现: etc / system.xml - 包含配置:

  223                              <show_in_store>0</show_in_store>
  224                          </sallowspecific>
  225:                         <specificcountry translate="label">
  226                              <label>Ship to Specific Countries</label>
  227                              <frontend_type>multiselect</frontend_type>
  ...
  232                              <show_in_store>0</show_in_store>
  233                              <can_be_empty>1</can_be_empty>
  234:                         </specificcountry>
  235                          <showmethod translate="label">
  236                              <label>Show Method if Not Applicable</label>
  ...
  312                              <show_in_store>0</show_in_store>
  313                          </sallowspecific>
  314:                         <specificcountry translate="label">
  315                              <label>Ship to Specific Countries</label>
  316                              <frontend_type>multiselect</frontend_type>
  ...
  321                              <show_in_store>0</show_in_store>
  322                              <can_be_empty>1</can_be_empty>
  323:                         </specificcountry>
  324                          <showmethod translate="label">
  325                              <label>Show Method if Not Applicable</label>
  ...
  445                              <show_in_store>0</show_in_store>
  446                          </sallowspecific>
  447:                         <specificcountry translate="label">
  448                              <label>Ship to Specific Countries</label>
  449                              <frontend_type>multiselect</frontend_type>
  ...
  454                              <show_in_store>0</show_in_store>
  455                              <can_be_empty>1</can_be_empty>
  456:                         </specificcountry>
  457                          <showmethod translate="label">
  458                              <label>Show Method if Not Applicable</label>

另一个档案: 型号/运营商/ Abstract.php

/**
 * Return delivery confirmation types of carrier
 *
 * @param Varien_Object|null $params
 * @return array
 */
public function getDeliveryConfirmationTypes(Varien_Object $params = null)
{
    return array();
}

public function checkAvailableShipCountries(Mage_Shipping_Model_Rate_Request $request)
{
    $speCountriesAllow = $this->getConfigData('sallowspecific');
    /*
    * for specific countries, the flag will be 1
    */
    if ($speCountriesAllow && $speCountriesAllow == 1){
         $showMethod = $this->getConfigData('showmethod');
         $availableCountries = array();
         if($this->getConfigData('specificcountry')) {
            $availableCountries = explode(',',$this->getConfigData('specificcountry'));
         }
         if ($availableCountries && in_array($request->getDestCountryId(), $availableCountries)) {
             return $this;
         } elseif ($showMethod && (!$availableCountries || ($availableCountries
             && !in_array($request->getDestCountryId(), $availableCountries)))
         ){
               $error = Mage::getModel('shipping/rate_result_error');
               $error->setCarrier($this->_code);
               $error->setCarrierTitle($this->getConfigData('title'));
               $errorMsg = $this->getConfigData('specificerrmsg');
               $error->setErrorMessage($errorMsg ? $errorMsg : Mage::helper('shipping')->__('The shipping module is not available for selected delivery country.'));
               return $error;
         } else {
             /*
            * The admin set not to show the shipping module if the devliery country is not within specific countries
            */
            return false;
         }
    }
    return $this;
}

最后一个: 型号/ Shipping.php

/**
 * Collect rates of given carrier
 *
 * @param string                           $carrierCode
 * @param Mage_Shipping_Model_Rate_Request $request
 * @return Mage_Shipping_Model_Shipping
 */
public function collectCarrierRates($carrierCode, $request)
{
    /* @var $carrier Mage_Shipping_Model_Carrier_Abstract */
    $carrier = $this->getCarrierByCode($carrierCode, $request->getStoreId());
    if (!$carrier) {
        return $this;
    }
    $carrier->setActiveFlag($this->_availabilityConfigField);
    $result = $carrier->checkAvailableShipCountries($request);
    if (false !== $result && !($result instanceof Mage_Shipping_Model_Rate_Result_Error)) {
        $result = $carrier->proccessAdditionalValidation($request);
    }

我想我需要以某种方式更改Mage_Shipping_Model_Carrier,$ availableCountries和&#39;特定国家/地区&#39;在地区,但我需要一些帮助。 我知道我不应该编辑核心文件,所以我想如果我能弄清楚如何按地区制作运输方法,我会把更改放到本地文件夹中。

1 个答案:

答案 0 :(得分:0)

您的任务=&gt;“使运输方式取决于地区/州”。

无需更改核心文件即可实现此目的。你的帖子不是很清楚。但是,据我所知,在结账过程中,您需要根据所选的运输国家/地区,正确地提出不同的运输方式/价格。

请参阅我的回答:Magento Price of delivery should vary on country. How can I do that?

一旦你掌握了管理csv结构的运输目的,我相信一切都会很简单。