0

特定の商品について、送料を無料にするショッピング カート ルールがあります。配送情報を表示せず、そのような製品の配送方法の選択をバイパスするのは理にかなっています。これを行う簡単な方法はありますか?

4

1 に答える 1

4

これは、拡張モジュールを使用して簡単に実行できます。

/app/etc/modules/YourCompany_SkipShipping.xml

<?xml version="1.0"?>
<config>
    <modules>
        <YourCompany_SkipShipping>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Checkout />
            </depends>
        </YourCompany_SkipShipping>
    </modules>
</config>


/app/code/local/YourCompany/SkipShipping/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <YourCompany_SkipShipping>
            <version>0.0.1</version>
        </YourCompany_SkipShipping>
    </modules>
    <frontend>
        <routers>
            <checkout>
                <modules before="Mage_Checkout">YourCompany_SkipShipping<modules>
            </checkout>
        </routers>
    </frontend>
</config>


/app/code/local/YourCompany/SkipShipping/controllers/OnepageController.php

<?php
include "Mage/Checkout/controller/OnepageController.php"
class YourCompany_SkipShippingMethod_OnepageController 
    extends Mage_Checkout_OnepageController
{
    public function saveBillingAction()
    {
        if ($this->_expireAjax()) {
            return;
        }
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost('billing', array());
            $customerAddressId = $this->getRequest()->getPost('billing_address_id', false);

            if (isset($data['email'])) {
                $data['email'] = trim($data['email']);
            }
            $result = $this->getOnepage()->saveBilling($data, $customerAddressId);

            if (!isset($result['error'])) {
                /* check quote for virtual */
                if ($this->getOnepage()->getQuote()->isVirtual()) {
                    $result['goto_section'] = 'payment';
                    $result['update_section'] = array(
                        'name' => 'payment-method',
                        'html' => $this->_getPaymentMethodsHtml()
                    );
                } elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
                    $method = $this->getAutoShippingMethod($data, $customerAddressId);
                    if (!empty($method)) {
                        $result = $this->getOnepage()->saveShippingMethod($method);
                        if(!$result) {
                            Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array(
                                'request'=>$this->getRequest(),
                                'quote'=>$this->getOnepage()->getQuote()
                            ));
                            $result['goto_section'] = 'payment';
                            $result['update_section'] = array(
                                'name' => 'payment-method',
                                'html' => $this->_getPaymentMethodsHtml()
                            );
                        }
                    } else {
                        $result['goto_section'] = 'shipping_method';
                        $result['update_section'] = array(
                            'name' => 'shipping-method',
                            'html' => $this->_getShippingMethodsHtml()
                        );

                        $result['allow_sections'] = array('shipping');
                        $result['duplicateBillingInfo'] = 'true';
                    }
                } else {
                    $result['goto_section'] = 'shipping';
                }
            }

            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }

    public function saveShippingAction()
    {
        if ($this->_expireAjax()) {
            return;
        }
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost('shipping', array());
            $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
            $result = $this->getOnepage()->saveShipping($data, $customerAddressId);

            if (!isset($result['error'])) {
                $method = $this->getAutoShippingMethod($data, $customerAddressId);
                if (!empty($method)) {
                    if(!$result) {
                        Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array(
                            'request'=>$this->getRequest(),
                            'quote'=>$this->getOnepage()->getQuote()
                        ));
                        $result['goto_section'] = 'payment';
                        $result['update_section'] = array(
                            'name' => 'payment-method',
                            'html' => $this->_getPaymentMethodsHtml()
                        );
                    }                    
                } else {
                    $result['goto_section'] = 'shipping_method';
                    $result['update_section'] = array(
                        'name' => 'shipping-method',
                        'html' => $this->_getShippingMethodsHtml()
                    );
                }
            }
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }

    public function getAutoShippingMethod($data, $customerAddressId)
    {
        // This is where you put your code to process the cart/order for orders that can auto-select shipping method

        // For now, skip
        return '';
    }
}

配送方法の詳細はお任せしますが、わからない場合はコメントを投稿して追加させていただきます。

注意:すべての例はMagento1.5に基づいています

于 2011-09-02T23:04:11.993 に答える