Thursday 15 January 2015

rewrite - Magento Overwriting Block -



rewrite - Magento Overwriting Block -

moved here: https://magento.stackexchange.com/questions/42434/overwriting-core-shipping-block

im working on magento job , been while since have dabbled in dark arts. im writing little bit of script override shipping methods on checkout screen. have excuse mediocrity in code said been while.

so have 2 files:

app/code/local/clarkstudios/shipmentfilter/etc/config.xml

<global> <blocks> <checkout> <rewrite> <onepage_shipping_method_available>clarkstudios_shipmentfilter_block_onepage_shipping_method_available</onepage_shipping_method_available> </rewrite> </checkout> </blocks> </global>

app/code/local/clarkstudios/shipmentfilter/block/onepage/shipping/method/available.php

class clarkstudios_shipmentfilter_block_onepage_shipping_method_available extends mage_checkout_block_onepage_shipping_method_available { public function getshippingrates() { die('hahahahahah!'); $rates = parent::getshippingrates(); $two_kg_array = array('au','us','ca','br','ve'); $quote = mage::getsingleton('checkout/session')->getquote(); $shipping_country = $this->getquote()->getshippingaddress()->getcountry(); $weight = $quote->getshippingaddress()->getweight(); if( in_array( $shipping_country, $two_kg_array ) && $weight > 2 ) { $rates = array(); } if( !in_array( $shipping_country, $two_kg_array ) && $weight > 30 ) { $rates = array(); } homecoming $rates; } }

i cant seem die fire says magento not recognising block rewrite. have done fundamentally wrong here hand held in right direction much appreciated.

i should point out trying alter shipping methods appear on 1 page checkout page based on weight of cart. starters want fire die function know working. have flushed cache also.

steve

you have missed class in config.xml file. config.xml should be,

<?xml version="1.0"?> <config> <modules> <clarkstudios_shipmentfilter> <version>0.1.0</version> </clarkstudios_shipmentfilter> </modules> <global> <helpers> <shipmentfilter> <class>clarkstudios_shipmentfilter_helper</class> </shipmentfilter> </helpers> <blocks> <shipmentfilter> <class>clarkstudios_shipmentfilter_block</class> </shipmentfilter> <checkout> <rewrite> <onepage_shipping_method_available>clarkstudios_shipmentfilter_block_checkout_onepage_shipping_method_available</onepage_shipping_method_available> </rewrite> </checkout> </blocks> </global> </config>

and, missed checkout directory. directory construction should be,

app/code/local/clarkstudios/shipmentfilter/block/checkout/onepage/shipping/method/available.php

so class should be,

<?php class clarkstudios_shipmentfilter_block_checkout_onepage_shipping_method_available extends mage_checkout_block_onepage_shipping_method_available { }

i have added helper in config.xml. helper should be, helper/data.php

<?php class clarkstudios_shipmentfilter_helper_data extends mage_core_helper_abstract { }

finally overwriting onepage checkout. if goes wrong cant move next level, (i mean didn't messages) dont utilize die(). print value or something.

magento rewrite block shipping

No comments:

Post a Comment