3

I need to link the shipment address to a product, not to an order. Is there an easy way to remove the step from the checkout process and include it to the product page?

I tried to remove the shipment block from the checkout layout, but it still remain on the checkout steps.

Thanks in advance.

4

1 回答 1

2

You must rewrite next files to you module:

  • Block /Checkout/Block/Onepage/Shipping/Method.php
  • Controller /Checkout/controllers/OnepageController.php
  • Model /Checkout/Model/Type/Onepage.php
  • Configuration /Checkout/etc/config.xml

1. Block (Method.php)

class Yourmodule_Checkout_Block_Onepage_Shipping_Method extends Mage_Checkout_Block_Onepage_Shipping_Method
            {
                public function isShow()
                {
                    return false;
                }
            }

2. Controller (OnepageController.php)

require_once 'Mage/Checkout/controllers/OnepageController.php';

class Yourmodule_Checkout_OnepageController extends Mage_Checkout_OnepageController
{
       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'])) {
                $result['goto_section'] = 'payment';
                $result['update_section'] = array(
                    'name' => 'payment-method',
                    'html' => $this->_getPaymentMethodsHtml()
                );
            }
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }
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);
            $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) {

                    $result['goto_section'] = 'payment';
                    $result['update_section'] = array(
                        'name' => 'payment-method',
                        'html' => $this->_getPaymentMethodsHtml()
                    );
                }
                else {
                    $result['goto_section'] = 'shipping';
                }
            }

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

3. Model (Onepage.php)

class Yourmodule_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage
{
    protected function validateOrder()
    {
        $helper = Mage::helper('checkout');
        if ($this->getQuote()->getIsMultiShipping()) {
            Mage::throwException($helper->__('Invalid checkout type.'));
        }

        $addressValidation = $this->getQuote()->getBillingAddress()->validate();
        if ($addressValidation !== true) {
            Mage::throwException($helper->__('Please check billing address information.'));
        }

        if (!($this->getQuote()->getPayment()->getMethod())) {
            Mage::throwException($helper->__('Please select valid payment method.'));
        }
    }
}

4. Configuration (config.xml)

<?xml version="1.0" encoding="UTF-8"?>

<config>
    <modules>
        <Yourmodule_Checkout>
            <version>0.0.2</version>
        </Yourmodule_Checkout>
    </modules>
    <global>
        <models>
            <checkout>
                <rewrite>
                    <type_onepage>Yourmodule_Checkout_Model_Type_Onepage</type_onepage>
                </rewrite>
            </checkout>
        </models>

        <blocks>
            <checkout>
                <rewrite>
                    <onepage_shipping_method>Yourmodule_Checkout_Block_Onepage_Shipping_Method</onepage_shipping_method>
                </rewrite>
            </checkout>
        </blocks>     
    </global>

    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <yourmodule before="Mage_Checkout">Yourmodule_Checkout</yourmodule>
                    </modules>
                </args>
            </checkout>
        </routers>
    </frontend>

</config>

4. Register your module in app/etc/modules/Yourmodule_All.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Yourmodule_Checkout>
            <active>true</active>
            <codePool>local</codePool>
        </Yourmodule_Checkout>
    </modules>
</config>

Good article for you:

1 2 3 4

于 2012-09-01T13:31:56.350 回答