Rimuovere le fasi di spedizione in Pagamento Onepage


14

Sto usando CE 1.9.1.0.

Sto cercando di rimuovere i passaggi relativi alle informazioni sulla spedizione e al metodo di spedizione dal pagamento on-page, ma senza successo.

Forse qualcuno potrebbe aiutarmi o indicarmi la giusta direzione?



Il link sopra è per il checkout onstep.
Inrsaurabh,

Risposte:


33

Ecco cosa ho fatto.
Ho rimosso il passaggio di spedizione e utilizzato un metodo di spedizione predefinito che so sarà sempre disponibile.
Non sono sicuro se questo è ciò di cui hai bisogno, ma puoi almeno usarlo come punto di partenza.
Ecco la mia idea
Ho creato un nuovo modulo con un'impostazione enable/disabledi configurazione del passaggio di spedizione, in modo da poter riattivare il passaggio di spedizione dalla system->configurationsezione.

Quindi crea il modulo StackExchange_Checkout.
Avrai bisogno dei seguenti file.

app/etc/modules/StackExchange_Checkout.xml - il file di dichiarazione

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

app/code/local/StackExchange/Checkout/etc/config.xml- il file di configurazione in cui si definiscono i modelli, i blocchi e si riscrive il blocco di checkout della pagina. Inoltre imposta un metodo di spedizione predefinito.

<?xml version="1.0"?>
<config>
    <modules>
        <StackExchange_Checkout>
            <version>0.0.1</version>
        </StackExchange_Checkout>
    </modules>
    <global>
        <blocks>
            <checkout>
                <rewrite>
                    <onepage>StackExchange_Checkout_Block_Onepage</onepage><!-- rewrite the onepage chackout block -->
                </rewrite>
            </checkout>
        </blocks>
        <helpers>
            <stackexchange_checkout>
                <class>StackExchange_Checkout_Helper</class>
            </stackexchange_checkout>
        </helpers>
        <models>
            <stackexchange_checkout>
                <class>StackExchange_Checkout_Model</class>
            </stackexchange_checkout>
        </models>
    </global>
    <default>
        <checkout>
            <options>
                <hide_shipping>1</hide_shipping>
                <default_shipping>tablerate_bestway</default_shipping><!-- set the default shipping method code -->
            </options>
        </checkout>
    </default>
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <StackExchange_Checkout before="Mage_Checkout">StackExchange_Checkout</StackExchange_Checkout>
                    </modules>
                </args>
            </checkout>
        </routers>
        <translate>
            <modules>
                <StackExchange_Checkout>
                    <files>
                        <default>StackExchange_Checkout.csv</default>
                    </files>
                </StackExchange_Checkout>
            </modules>
        </translate>
    </frontend>
</config>

app/code/local/StackExchange/Checkout/etc/system.xml - il file di sistema che posiziona il flag abilitato / disabilitato per la fase di spedizione

<?xml version="1.0"?>
<config>
    <sections>
        <checkout>
            <groups>
                <options>
                    <fields>
                        <hide_shipping translate="label" module="stackexchange_checkout">
                            <label>Hide shipping method step</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>100</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </hide_shipping>
                        <default_shipping translate="label" module="stackexchange_checkout">
                            <label>Default shipping method code</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>110</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </default_shipping>
                    </fields>
                </options>
            </groups>
        </checkout>
    </sections>
</config>

app/code/local/StackExchange/Checkout/Helper/Data.php - l'helper che verifica se la fase di spedizione deve essere disabilitata

<?php
class StackExchange_Checkout_Helper_Data extends Mage_Core_Helper_Abstract 
{
    const XML_HIDE_SHIPPING_PATH = 'checkout/options/hide_shipping';
    const XML_DEFAULT_SHIPPING_PATH = 'checkout/options/default_shipping';
    public function getHideShipping()
    {
        if (!Mage::getStoreConfigFlag(self::XML_HIDE_SHIPPING_PATH)){
            return false;
        }
        if (!$this->getDefaultShippingMethod()){
            return false;
        }
        return true;
    }
    public function getDefaultShippingMethod()
    {
        return Mage::getStoreConfig(self::XML_DEFAULT_SHIPPING_PATH);
    }
}

app/code/local/StackExchange/Checkout/Block/Onepage.php - il blocco di cassa sovrascritto

<?php
class StackExchange_Checkout_Block_Onepage extends Mage_Checkout_Block_Onepage 
{
    protected function _getStepCodes()
    {
        if (!Mage::helper('stackexchange_checkout')->getHideShipping()){
            return parent::_getStepCodes();
        }
        return array_diff(parent::_getStepCodes(), array('shipping_method'));
    }
}

app/code/local/StackExchange/Checkout/controllers/OnepageController.php - ignora il controller onepage per impostare automaticamente il metodo di spedizione predefinito.

<?php
require 'Mage/Checkout/controllers/OnepageController.php';
class StackExchange_Checkout_OnepageController extends Mage_Checkout_OnepageController
{
    public function saveBillingAction()
    {
        if (!Mage::helper('stackexchange_checkout')->getHideShipping()){
            parent::saveBillingAction();
            return;
        }

        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) {
                    //add default shipping method
                    $data = Mage::helper('stackexchange_checkout')->getDefaultShippingMethod();
                    $result = $this->getOnepage()->saveShippingMethod($data);
                    $this->getOnepage()->getQuote()->save();
                    /*
                    $result will have erro data if shipping method is empty
                    */
                    if(!$result) {
                        Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method',
                            array('request'=>$this->getRequest(),
                                'quote'=>$this->getOnepage()->getQuote()));
                        $this->getOnepage()->getQuote()->collectTotals();
                        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

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


                    $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 (!Mage::helper('stackexchange_checkout')->getHideShipping()){
            parent::saveShippingAction();
            return;
        }
        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);

            $data = Mage::helper('stackexchange_checkout')->getDefaultShippingMethod();
            $result = $this->getOnepage()->saveShippingMethod($data);
            $this->getOnepage()->getQuote()->save();

            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));
        }
    }
}

Svuota la cache e il gioco è fatto.


Ho appena implementato questo, ma ricevi un messaggio che mi dice che il mio metodo di spedizione non è valido?
Vince Pettit,

@VincePettit. Nella risposta ho indicato che ho usato come metodo di spedizione predefinito sempre disponibile nel mio caso. Forse il metodo di spedizione che usi non è sempre disponibile.
Marius

Come disabilitare le informazioni di spedizione?
Magento 2

@Manojkothari Non lo so.
Marius

@Manojkothari se aggiungi un prodotto come informazioni di spedizione del prodotto virtuale e la selezione della spedizione non apparirà
Butterfly,

7

Rendi il tuo prodotto come Prodotto virtuale e verrà rimosso automaticamente.


1
Nota che in questo caso dovrai cambiare tutti i prodotti sul sito in virtuali, il che è un lavoro folle e funzionerà che probabilmente causerà problemi con altri processi Magento standard.
David Manners,

2
Idealmente è la cosa giusta da fare se non si desidera raccogliere le informazioni di spedizione perché questo è il prodotto virtuale a cui si
rivolge

Questo vale anche per i prodotti scaricabili. Vedi qui .
cambio rapido

7

Ho una soluzione migliore di quella di @marius che non necessita di riscritture.

Devi ancora creare un modulo personale, ci sono tonnellate di tutorial per questo, quindi non lo spiegherò qui. Devi creare un osservatore e attivarlo tramite il config.xml. Potrebbe essere necessario adattare il modelloapp/design/frontend/base/default/template/checkout/onepage.phtml

Nel tuo config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Namepace_Module>
            <version>1.0.0</version>
        </Namepace_Module>
    </modules>

    ....

    <frontend>
        <events>
            <controller_action_postdispatch_checkout_onepage_saveBilling>
                <observers>
                    <namespace_module_skip_shipping_method>
                        <type>singleton</type>
                        <class>namespace_module/observer</class>
                        <method>controllerActionPostdispatchCheckoutOnepageSaveBilling</method>
                    </namespace_module_skip_shipping_method>
                </observers>
            </controller_action_postdispatch_checkout_onepage_saveBilling>

            <controller_action_postdispatch_checkout_onepage_saveShipping>
                <observers>
                    <namespace_module_skip_shipping_method>
                        <type>singleton</type>
                        <class>namespace_module/observer</class>
                        <method>controllerActionPostdispatchCheckoutOnepageSaveBilling</method>
                    </namespace_module_skip_shipping_method>
                </observers>
            </controller_action_postdispatch_checkout_onepage_saveShipping>
        </events>
    </frontend>
</config>

Nel tuo Model/Observer.php

class Namepsace_Module_Model_Observer {
/**
     * @param Varien_Event_Observer $observer
     */
    public function controllerActionPostdispatchCheckoutOnepageSaveBilling(Varien_Event_Observer $observer)
    {
        if (!Mage::helper('namespace_module')->skipShippingMethod()) {
            return;
        }

        /* @var $controller Mage_Checkout_OnepageController */
        $controller = $observer->getEvent()->getControllerAction();
        $response = Mage::app()->getFrontController()->getResponse()->getBody(true);

        if (!isset($response['default'])) {
            return;
        }

        $response = Mage::helper('core')->jsonDecode($response['default']);

        if ($response['goto_section'] == 'shipping_method') {
            $response['goto_section'] = 'payment';
            $response['update_section'] = array(
                'name' => 'payment-method',
                'html' => $this->_getPaymentMethodsHtml()
            );

            $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
        }
    }

    /**
     * @return string
     * @throws Mage_Core_Exception
     */
    protected function _getPaymentMethodsHtml()
    {
        $layout = Mage::getModel('core/layout');
        $update = $layout->getUpdate();
        $update->load('checkout_onepage_paymentmethod');
        $layout->generateXml();
        $layout->generateBlocks();

        return $layout->getOutput();
    }
}

sembra meno complicato. C'è un modo per verificare se esiste più di un metodo di spedizione e saltare il passaggio solo se è uno?
Bernhard Prange,

Puoi dare il codice completo con spiegazione?
Prashant Patil,

-4

Stavo cercando una soluzione più semplice da qualche giorno perché non volevo fare casini con i file core di mage. Quindi, ho trovato la mia soluzione.

Ispeziona il div del metodo di spedizione e individua il file css. Nel mio caso il file era a

"Pub / static / frontend / myTheme / THEMENAME / it_IT / css / porcile-m.css"

dopo di che ho sovrascritto l'attuale CSS, ovviamente ho fatto un backup del mio file originale.

css:

.step-title, .totals.shipping.incl {display: none! important;} # checkout-shipping-method-load {display: none! important;}

Inoltre, vorrei sapere se alcuni file sono efficaci con questo metodo. Fino ad ora non ho riscontrato alcun problema.


1
Questo file viene generato automaticamente dalla distribuzione di file statici Magentos. Le modifiche andranno perse non appena i file verranno nuovamente generati.
Fabian Schmengler,

2
questa non è una domanda di Magento 2
Jalpesh Patel,
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.