Odd value for "limit" needed

  • Posts: 2143
  • Thank you received: 747
9 years 2 months ago #215148

-- url of the page with the problem -- : local
-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.4.4
-- PHP version -- : 5.5.3

Hi again,

I notice that 2.6.0 came out within the last very few hours... wow, congrats - will be an interesting one, I'm sure! Anyway, the changelog doesn't say anything about limits, so here I am:

I guess I need an odd 10 months limit on some products: it's Emerald subscriptions valid for 1 year, but renewal/repurchasing must be possible from 2 months before expiry.

The attachment shows what I've set up now, and that does the job - but for the whole year. Then I found the function _checkQuantity in classes/cart.php and the lines

$baseDates = array(
	0 => 0,
	1 => mktime(0,0,0,1,1,$d['year']),
	2 => mktime(0,0,0,$d['mon']-(($d['mon']-1)%4),1,$d['year']),
	3 => mktime(0,0,0,$d['mon'],1,$d['year']),
	4 => mktime(0,0,0,$d['mon'],$d['mday']-$d['wday'],$d['year']),
	5 => mktime(0,0,0,$d['mon'],$d['mday'],$d['year']),
	6 => -1
);

There's only this one period of limit in this case, so I'd be fine with modding e.g. case 3 to make it not 1 month but 10, then change my setting for period to "Monthly". But I'm lost with the "math", and even only 1 month is an awful long time for trial & error, haha...
So, it'd be great if you could give me a reliable hint on what exactly to change. Is it as simple as replacing the 1 with a 10 in case 3, then selecting "Monthly" in the backend?

Thanks a ton!


Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )
Attachments:
Last edit: 9 years 2 months ago by lousyfool.

Please Log in or Create an account to join the conversation.

  • Posts: 82909
  • Thank you received: 13379
  • MODERATOR
9 years 2 months ago #215165

Hi,

I would recommend against modifying directly the _checkQuantity function. It's not well adapted to what you want and you'll loose your changes on each update.
Rather than doing that, you could instead create a small hikashop plugin, implementing the trigger onAfterProductQuantityCheck(&$product, &$wantedQuantity,&$quantity, &$cartContent, &$cart_product_id_for_product, &$displayErrors)
That way, you can really have your custom check exactly the way you want it and you won't loose your changes when you update.

The following user(s) said Thank You: lousyfool

Please Log in or Create an account to join the conversation.

  • Posts: 2143
  • Thank you received: 747
9 years 2 months ago #215188

Thanks Nicolas,

Of course, "hacking" the core file isn't ideal, but I'd have my way of keeping track of those very few cases.

A plugin as recommended by you may be small in size, but likely too big in complexity for my little knowledge of PHP. Plus, in the dev docs the trigger onAfterProductQuantityCheck is not mentioned/documented.

Well, one can't have it all, it seems... ;)


Need help with customisations of layouts, style or other site development? PM me!
(Don't forget to turn on "E-mail notification of new messages" )

Please Log in or Create an account to join the conversation.

Time to create page: 0.059 seconds
Powered by Kunena Forum