Aldar Posted September 10, 2016 Share Posted September 10, 2016 (edited) HiI'm currently trying to figure out the best way to implement this idea.What I want to achieve is to make only certain carriers available when (non registered) customers make a purchase for company by filling "Company" and "VAT number" fields in quick order. At the moment I am not sure if this should be done Overriding Cart class method "getDeliveryOptionList()". Creating a custom Carrier module. Modifying template file. Anybody has suggestions? Aldar Edited September 10, 2016 by Aldar (see edit history) Link to comment Share on other sites More sharing options...
Aldar Posted September 10, 2016 Author Share Posted September 10, 2016 (edited) I think I figured it out. I went for the override method and although I'm not sure it is the best solution but at least it's short and it's working. Sure you could make delivery method ID (sort of) to be configurable but for sake of this example I left it as static. class Cart extends CartCore { public function getDeliveryOptionList(Country $default_country = null, $flush = false) { $option_list = parent::getDeliveryOptionList($default_country, $flush); // get delivery address ID $id_address_delivery = Context::getContext()->cart->id_address_delivery; // Get address detail data by ID $address_data = Address::initialize($id_address_delivery); if ($address_data->vat_number == '') { // remove the carrier that is meant only for business customers unset($option_list[key($option_list)]['3,']); } else { // remove the carrier that is meant only for private customers unset($option_list[key($option_list)]['4,']); } return $option_list; } } Edited September 10, 2016 by Aldar (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now