Frage

Ich habe ein neues Versandmethodemodul für meinen Magento Store hinzugefügt. Mit diesem Modul kann der Benutzer die Versandraten basierend auf dem Land des Versandadresses festlegen.
Ich habe einen Beobachter über die Kundenversandadresse hinzugefügt, die nach dem Code liegt. Im config.xml Ich habe eine neue Veranstaltung hinzugefügt.

<events>
             <checkout_controller_onepage_save_shipping_address_after>
                <observers>
                    <zones>
                        <type>model</type>
                        <class>zones/observer</class>
                        <method>getShippingMethods</method>
                    </zones>
                </observers>
            </checkout_controller_onepage_save_shipping_address_after>
        </events>

Danach habe ich das Ereignis eingegeben OnepageController > SaveShipping Methode wie,

Mage::dispatchEvent('checkout_controller_onepage_save_shipping_address_after', array('page' => $model, 'request' => $this->getRequest()));

Dies ruft den Beobachter an, wenn ich meine Versandadresse speichere. Aber ich habe keine Ahnung, wie ich die Gebühr für die Versandmethode gemäß dem Länder der Versandadresse ändern soll.
Ich habe diesen Thread verwendet http://www.opencart60s.com/magento/changing-or-sshipping-price-on-fly-from-event-or-observer--magento.html-13407.html Um die Versandkosten zu ändern. Aber ohne Erfolg.
Ich muss meinen Versandpauschalrate gemäß dem Land ändern.
Ich habe das Modul bereits erstellt, mit dem die Details des Landes und der Versandrate gespeichert werden. Ich kann den Versandrate mit diesem Modul erhalten. Jetzt muss ich nur noch den Pauschalsatz mit dem benutzerdefinierten Versandratewert aktualisieren. Bitte helfen Sie mir, meinen Pauschalsatz gemäß dem Ländercode festzulegen. Vielen Dank..

War es hilfreich?

Lösung

Ich habe die Lösung aus diesem Link hier gefunden: http://www.magentocommerce.com/boards/viewthread/316685/
In meinem Beobachter habe ich den folgenden Code hinzugefügt, um meine Versandraten gemäß Länderauswahl in der Versandadresse zu ändern.

class Pnk_Zones_Model_Observer
{
    public function getShippingMethods($observer)
    {
        $session = Mage::getSingleton('checkout/session');
        $quote=Mage::getSingleton('checkout/session')->getQuote();
        $quoteid=$quote->getId(); 
        if($quoteid) {                    
        try{
                $address=$quote->getShippingAddress();
                if($address->getAddressType()=='shipping'){
            //    echo '<pre>'; print_r($events->getQuoteAddress()->getData()); exit;
                //$price=40;
                $countryId = $address->getCountry();
                //Code to get Shipping rate from my zone module //
                $shippingRateCollection = Mage::getModel('zones/zones')->getCollection();
                $shippingRateCollection->addFieldToSelect('*');
                $shippingRateCollection->getSelect()->where("find_in_set('".$countryId."', `countries`)");


                foreach ($shippingRateCollection as $shipping){
                    $price = $shipping->getShippingRate();
                }
//              echo "Price = ".$price;
                // Find if our shipping has been included.
                $rates = $address->collectShippingRates()
                         ->getGroupedAllShippingRates();

                foreach ($rates as $carrier) {
                    foreach ($carrier as $rate) {
                        // Check with your custom shipping method code
                if($rate->getCode() == 'zones'){
                            $rate->setPrice($price);
                            $rate->save();
               }
                    }
                }
                    $this->collectTotals($quote,$price);
                }            
                $quote->collectTotals();
            } catch (Exception $e) {            
                Mage::logException($e);
                $response['error'] = $e->getMessage();
            }
        }
    }   

    public function collectTotals($quote,$price){
        $quoteid=$quote->getId(); 
        $shippingcode='freeshipping_freeshipping';
        if($quoteid) {                    
                try{
                $quote->setSubtotal(0);
                $quote->setBaseSubtotal(0);
                $quote->setSubtotalWithDiscount(0);
                $quote->setBaseSubtotalWithDiscount(0);
                $quote->setGrandTotal(0);
                $quote->setBaseGrandTotal(0);

                $quote->getShippingAddress()->setShippingMethod($shippingcode)/* ->collectTotals() */->save();
                $quote->save();
                foreach ($quote->getAllAddresses() as $address) {
                    $address->setSubtotal(0);
                    $address->setBaseSubtotal(0);

                    $address->setGrandTotal(0);
                    $address->setBaseGrandTotal(0);

                    $address->collectTotals();

                    $quote->setSubtotal((float) $quote->getSubtotal() + $address->getSubtotal());
                    $quote->setBaseSubtotal((float) $quote->getBaseSubtotal() + $address->getBaseSubtotal());

                    $quote->setSubtotalWithDiscount(
                        (float) $quote->getSubtotalWithDiscount() + $address->getSubtotalWithDiscount()
                    );
                    $quote->setBaseSubtotalWithDiscount(
                        (float) $quote->getBaseSubtotalWithDiscount() + $address->getBaseSubtotalWithDiscount()
                    );

                    $quote->setGrandTotal((float) $quote->getGrandTotal() + $address->getGrandTotal());
                    $quote->setBaseGrandTotal((float) $quote->getBaseGrandTotal() + $address->getBaseGrandTotal());

                    $address->setShippingAmount($price);
                    $address->setBaseShippingAmount($price);
                    $address->save();
                }

                    $response['message'] = 'Succcess';
                } catch (Exception $e) {            
                        Mage::logException($e);
                        $response['error'] = $e->getMessage();
                 }
        }
    }

}

Andere Tipps

Thebod hat ein Modul erstellt, das dies für Sie tut, könnte helfen:https://github.com/thebod/thebod_shippingrate

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top