LemonStand Forum: filter shipping options based on quantity of certain products - LemonStand Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

filter shipping options based on quantity of certain products

#1 User is offline   wrinkles 

  • LemonEvangelist
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 100
  • Joined: 29-August 10

Posted 27 April 2012 - 06:51 PM

Shipping is the biggest challenge to set up for my clients. I have a client that requires a different shipping option if more than 6 of a certain product (category) is purchased internationally. How am I to do that without writing a custom module?

Any ideas?

In general, I need a shipping filter module that will filter shipping options on arbitrary conditions. An extreme example:

"If more than ten items of product A are purchased with less than three of items from either of category B or C, to ship to Tanzania, and it's the second or third Tuesday in June, and the customer's name begins with a vowel, then add a 5% shipping surcharge and limit to shipping module XYZ and ABC."

Of course that is extreme, but when I add all the various shipping option requests I get, it is not so far fetched. I need a shipping module with powerful flow control and conditionals that can test for virtually any condition to which the cart has access.

Thanks,

Rick
0

#2 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 4,066
  • Joined: 31-October 09

Posted 01 May 2012 - 02:41 PM

Hi Rick,

Yes, it sounds terrible!

You should use the shop:onFilterShippingOptions event (http://lemonstandapp...goptions_event/) to filter shipping options and maybe shop:onUpdateShippingQuote event (http://lemonstandapp...ingquote_event/) if you want to modify shipping costs. As for the conditions - implementing a visual editor for managing conditions could be a very complex task. We have implemented such an editor our discount engine and it was not easy. But there is a simpler alternative - you can define conditions as PHP strings and eval() them in your module. Then your module could provide a very simple user interface where your client can add new conditions through a form with 2 fields - condition name and condition code. The code could return an array of allowed shipping methods (actually there are many ways to implement it). But in this case your customer will need a programmer to maintain conditions.

Thank you

#3 User is offline   wrinkles 

  • LemonEvangelist
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 100
  • Joined: 29-August 10

Posted 03 May 2012 - 11:43 PM

[Thanks Aleksey,

Yes I know enough PHP to work through one or to conditions. I need to write the module in a way that doesn't become unmanageable after I've added 4 or 5 conditions. I don't even need a form interface, I just want to have comprehensible code.

Currently I have a FilterShippingOptions module with one condition (see below). It works fine, but I'm reluctant to extend it. Do I just add more "elseif" conditions to the foreach option block, or is there a cleaner way to write this, that will help me extend it?

Thanks again for your help!

Rick


<?php

	class FilterShippingOptions_Module extends Core_ModuleBase
	{
		protected function createModuleInfo()
		{
			return new Core_ModuleInfo(
				"Filter Shipping Options",
				"Filters shipping options from shipping methods",
				"Hiranyaloka Web Design" );
		}

		public function subscribeEvents()
    {
      Backend::$events->addEvent('shop:onFilterShippingOptions', $this, 'filter_shipping_options');
    }
    
    public function filter_shipping_options($params)
    {
      $all_category_names = array();
      foreach ($params['order_items'] as $order_item)
      {
      	foreach ($order_item->product->category_list as $this_category)
      		$all_category_names[] = $this_category->url_name;
      }
		// Show shipping_tbd method when Original Paintings is in cart, and remove other options  
		$result = array();
		foreach ($params['options'] as $option)
  	{
	    if ($option->ls_api_code == 'shipping_tbd' && in_array("original-paintings", $all_category_names))
	      $result[] = $option;	    
	    elseif ($option->ls_api_code != 'shipping_tbd' && in_array("original-paintings", $all_category_names))
	      {}    
	    elseif ($option->ls_api_code != 'shipping_tbd')
	      $result[] = $option;	    
	  }
	  return $result;
    }
	}
	
?>



0

#4 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 4,066
  • Joined: 31-October 09

Posted 04 May 2012 - 01:00 PM

Hi Rick,

I can't think of anything better if you want simple conditions written in pure PHP.

Thank you

Share this topic:


Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users