0

im struggling where with a issue, i create a custom shipping module, based on this envato tutorial url

The problem is that that when i create a cart rule, and one the condition select my custom shipping method, the coupon it doesnt work, i try to call in my Carrier class the method request->getFreeShipping() of the shipping module, but i keep getting false, the extension works fine, if i remove the condition of the specific custom shipping method it the method brings true.

My code:

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Envato_Customshippingmethod>
            <version>1.0</version>
        </Envato_Customshippingmethod>
    </modules>
    <global>
        <models>
            <envato_customshippingmethod>
                <class>Envato_Customshippingmethod_Model</class>
            </envato_customshippingmethod>
        </models>
        <helpers>
            <envato_customshippingmethod>
                <class>Envato_Customshippingmethod_Helper</class>
            </envato_customshippingmethod>
        </helpers>
    </global>
    <default>
        <carriers>
            <envato_customshippingmethod>
                <active>1</active>
                <sallowspecific>1</sallowspecific>
                <model>envato_customshippingmethod/demo</model>
                <name>Demo Shipping Method One</name>
                <price>10.00</price>
                <title>Demo Shipping Method</title>
            </envato_customshippingmethod>
        </carriers>
    </default>
</config>

system.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <sections>
        <carriers>
            <groups>
                <envato_customshippingmethod translate="label">
                    <label>Envato Demo Shipping Method</label>
                    <sort_order>1</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>0</show_in_website>
                    <show_in_store>0</show_in_store>
                    <fields>
                        <active translate="label">
                            <label>Enabled</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </active>
                        <title translate="label">
                            <label>Shipping Method Name</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>20</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </title>
                        <sallowspecific translate="label">
                            <label>For selected countries only</label>
                            <frontend_type>select</frontend_type>
                            <frontend_class>shipping-applicable-country</frontend_class>
                            <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
                            <sort_order>30</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </sallowspecific>
                        <specificcountry translate="label">
                            <label>Ship to Specific Countries</label>
                            <frontend_type>multiselect</frontend_type>
                            <sort_order>31</sort_order>
                            <source_model>adminhtml/system_config_source_country</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                            <can_be_empty>1</can_be_empty>
                        </specificcountry>
                    </fields>
                </envato_customshippingmethod>
            </groups>
        </carriers>
    </sections>
</config>

Demo.php

<?php
// app/code/local/Envato/Customshippingmethod/Model
class Envato_Customshippingmethod_Model_Demo
    extends Mage_Shipping_Model_Carrier_Abstract
    implements Mage_Shipping_Model_Carrier_Interface
{
    protected $_code = 'envato_customshippingmethod';

    public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    {

        //var_dump($request->getFreeShipping());die;
        $result = Mage::getModel('shipping/rate_result');
        $result->append($this->_getDefaultRate());

        return $result;
    }

    public function getAllowedMethods()
    {
        return array(
            'envato_customshippingmethod' => $this->getConfigData('name'),
        );
    }

    protected function _getDefaultRate()
    {
        $rate = Mage::getModel('shipping/rate_result_method');

        $rate->setCarrier($this->_code);
        $rate->setCarrierTitle($this->getConfigData('title'));
        $rate->setMethod($this->_code);
        $rate->setMethodTitle($this->getConfigData('name'));
        $rate->setPrice($this->getConfigData('price'));
        $rate->setCost(0);

        return $rate;
    }
}

The cart rule im not posting the image because is working fine, only stops working when i add the condition for a specific shipping method.

Note: im using Magento ver. 1.9.3.2

Apreciate for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.