LemonStand Forum: Discount cheapest/priciest item - LemonStand Forum

Jump to content

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

Discount cheapest/priciest item

#1 User is offline   Phil 

  • Lemonholic
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 228
  • Joined: 13-January 10
  • LocationCumberland, BC, Canada

Posted 30 August 2010 - 02:35 PM

Is it possible to discount a specific item based on some dynamic criteria such as "cheapest or most expensive x items"? Client is wanting to do "Buy one get 50% off one item" and would like the 50% to come off the cheapest item. What's the best way to go about doing this?

Thanks,

Phil

This post has been edited by pnomolos: 30 August 2010 - 02:35 PM

0

#2 User is offline   Aleksey 

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

Posted 31 August 2010 - 04:19 PM

Hi, Phil!

The best way for this case is developing a custom discount action. This topic is not documented, but the task is not very complicated. It is similar to creating payment or shipping modules. Discount actions are simple classes inherited from the Shop_CartRuleActionBase. They should be placed to the /modules/shop/price_rule_actions directory. Inside the action class you can build the action configuration user interface (add controls to the form), and process the eval_discount request. You can use the Shop_CartProductPercent_Action class as a template and extend it with the feature you need.

As far as I understand you only need to make an additional filter inside the action. The list of cart items is available inside the eval_discount() method, so you can find the cheapest item in the cart and ignore others. Also, there is the is_active_for_product() condition (line 61), which checks whether a current cart item satisfies the Product Filter settings. The code is rather simple.

Let me know if you need help with this.

Thank you

#3 User is offline   Phil 

  • Lemonholic
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 228
  • Joined: 13-January 10
  • LocationCumberland, BC, Canada

Posted 08 September 2010 - 05:17 PM

Hi Aleksey,

I'm working on this, and the way that the discount is shown on the cart page is very unintuitive. It shows the discount for each product as if it was applying to each one.

For example:
if 3 products are a total of 3 dollars, and the total discount for those 3 products is 50 cents. $item->total_discount() returns a little under 17 cents, which is .50/3.

Is there any way to get a more intuitive display of the discount (I'd prefer to get the .50, personally) without resorting to $item->total_discount() * $item->quantity()?

This post has been edited by pnomolos: 08 September 2010 - 05:18 PM

0

#4 User is offline   Aleksey 

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

Posted 08 September 2010 - 06:16 PM

Hi, Phil!

The total_discount() method returns a discount per 1 item. You can display a total discount value with $item->total_discount() * $item->quantity(). Does it not work for you?

Thanks

#5 User is offline   Phil 

  • Lemonholic
  • PipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 228
  • Joined: 13-January 10
  • LocationCumberland, BC, Canada

Posted 08 September 2010 - 06:48 PM

Hi Aleksey,

That works, I just thought there may be some more elegant way of displaying it :)

Thanks,

Phil
0

#6 User is offline   Aleksey 

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

Posted 08 September 2010 - 07:07 PM

I added this request to the list. We will extend the cart item class with a corresponding method.

Thanks!

Share this topic:


Page 1 of 1

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