كيفية تمكين/تعطيل طريقة الشحن بناءً على المجموع الفرعي للطلب؟

magento.stackexchange https://magento.stackexchange.com//questions/86305

سؤال

أنا أتعلم استخدام Magento وأحاول إنشاء طريقة شحن تظهر فقط عندما يتجاوز الإجمالي الفرعي لعربة التسوق 100 دولار.

انا حاولت getSubTotal() فى مهمة collectRates(), ، ثم return false إذا كانت قيمة الإرجاع أصغر من 100.ومع ذلك، فإنه يعود دائما 0.أعتقد أنه لم يتم حسابه في تلك الخطوة، فهل هذا صحيح؟

وهل هناك طريقة أخرى يمكنني من خلالها أن أفعل ما أريد؟

الرجاء المساعدة...شكرا جزيلا!

هل كانت مفيدة؟

المحلول

لك collectRates يجب أن تبدو الطريقة هكذا

public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
    //if method is disabled
    if (!$this->getConfigFlag('active')) {
        return false;
    }

    if ($request->getPackageValue() < 100) {
        return false;
    }
    /** @var Mage_Shipping_Model_Rate_Result $result */
    $result = Mage::getModel('shipping/rate_result');
    $method = Mage::getModel('shipping/rate_result_method');
    $method->setCarrier($this->_code); //add here the payment method code
    $method->setCarrierTitle($this->getConfigData('title')); //or you can add any title if it's not configurable
    $method->setPrice(your shiping cost here);
    $result->append($method);
    return $result;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top