Jump to content

Make only certain carriers available if VAT number is entered


Aldar

Recommended Posts

Hi

I'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

  1. Overriding Cart class method "getDeliveryOptionList()".
  2. Creating a custom Carrier module.
  3. Modifying template file.
     

Anybody has suggestions?

 

 

Aldar

Edited by Aldar (see edit history)
Link to comment
Share on other sites

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 by Aldar (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...