Jump to content

Products available to add to cart depending on the day of the week


cipraen

Recommended Posts

Hi,

 

I've been looking for a module to do this but couldn't find anything remotly close. Maybe someone can point me in the right direction.

 

I have a food shop that sales specific products each day.

 

So:

- on Monday there is product A

- on Tuesday there is produscts B

- on Wednesday there is product C

- on Thursday there is product D

- on Friday there is product E

There are no products for Saturday or Sunday.

 

Now, each day you can only order products for the next day (days). So if today is Monday, the user will be able to add to cart products B, C, D or E.

If it's Thursday, than you can only add to cart product E.

If it's Friday, Saturday or Sunday than you have all products at your disposal.

 

I did implement this in php when the website was running on wordpress, but since I'm new to prestashop I'm not really sure how I can do this.

 

Thanks

Link to comment
Share on other sites

There'll be a fair bit of work involved in that, if you want it to be (relatively) foolproof anyhow.

 

First you'll want to add on a new field to the admin so that you can mark off what days they're available, bit tricky if it's your first time doing so, but not too bad, should be plenty of guides for that. It involves making an override of the adminProductsController and the Product class

 

How did you implement it on wordpress after that? There are a few ways of going about it from there, you could alter the information in the php files (which might be needed if you're going for indepth changes), or you could get away with just altering the tpl files.

 

If you want a really simple way of handling it, I'd be tempted to just use a string comparison for the day of the week on the new field, something along the lines of:

{if strpos($product.availableDays, date("N")) !== false}

Then just set up the products containing the days they're available for order on (1 being Monday, 7 Sunday)

Which in this case would be:

product A : 567

product B : 1567

product C : 12567

product D : 123567

product E : 1234567

 

Which I believe would give you all the particular availability you need there.

 

Could also just store that in an array, and just reference it on the unique field.. which would be better if you planned to make sweeping changes to the days that certain products are available, but gives you less fine control

Link to comment
Share on other sites

  • 2 weeks later...

I managed to do it by adding a feature to each product with the number of the day in the week.

 

Then I would check which day it is:

{assign var="weekday" value=$smarty.now|date_format:"%u"}
			
{if $weekday == 1} {assign 'myProductsArray' ['2', '3', '4', '5']}
{elseif $weekday == 2} {assign 'myProductsArray' ['3', '4', '5']}
{elseif $weekday == 3} {assign 'myProductsArray' ['4', '5']}
{elseif $weekday == 4} {assign 'myProductsArray' ['5']}
{else $weekday == 5 || $weekday == 6 || $weekday == 7} {assign 'myProductsArray' ['1', '2', '3', '4', '5']}

{/if}

And after that filter the products that get to be displayed

{foreach from=$products item=product name=homeFeaturedProducts}
			
{foreach from=$product.features item=feature}
{if $feature.name == 'ProductDay' && in_array($feature.value,$myProductsArray)}

Not sure if it's the best way to do it, but it works

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...