Jump to content

Disable Category in PS1.6 Based on day of the week


Recommended Posts

Hello

 

I'm new in this Forum. 

I'm configuring a Shop where customers can buy different restaurant menus. 

 

The need:

I need to allow / disallow buy a product/s of a Category (day of the week) if the day of the week is the same as the name/day of the Category.

 

My Categories are the days (Monday to Sunday) and i've enter the different "products" on it.

 

Thanks

Víctor

 

Share this post


Link to post
Share on other sites

This will be a partial solution, because it will be possible to reach products from google search results for example.

this kind of feature requires modification or custom module

 

all what you need is to disable possibility to order product (not deactive products because it will hurt seo)

Share this post


Link to post
Share on other sites

This will be a partial solution, because it will be possible to reach products from google search results for example.

this kind of feature requires modification or custom module

 

all what you need is to disable possibility to order product (not deactive products because it will hurt seo)

 

My idea is to disallow buy (maybe "hide" add to cart or similar) , the problem is i never programmed in a .tpl ,  I try {php}{/php} but i think i'm doing something wrong. 

 

I need:  Detect Name or Id from a Category, detect if the category is the "same" as the day of week, and disable the buy option.  

 

If is tuesday i can buy all other days(catgories) except on Tuesday Category.

 

If you guide me to - code work to get the data, and maybe the principal affected files, i think i'll be able to do it. 

 

I make some programming in Wordpress, i use the Child theme for this, i read in Prestashop i make the modify in the Theme directly... There's any problem doing this way? If the Template is Updated, i lost the changes?

 

Thanks a lot!

Víctor

Edited by aedesgirona (see edit history)

Share this post


Link to post
Share on other sites

You will need to write all the logic in controllers/front/CategoryController.php and send .tpl variable to the category.tpl  file.

You can create an array of 7 items for days on week and use id_category as array key.  And do the comparation to the current day by using the date function.   This can be a good start:

<?php

//if you have 7 categories 
// 7 days on a week

//id_category=1 :  Monday etc..

$days=array(1=>'Monday',2=>'Thursday','etc');
$id_category=(int)Tools::getValue('id_category');

if($id_category=='') $id_category=Context::getContext()->cookie->id_category;

if($id_category==$days[1]){

//do something

}

//etc  
Edited by ndiaga (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

 

You will need to write all the logic in controllers/front/CategoryController.php and send .tpl variable to the category.tpl  file.

You can create an array of 7 items for days on week and use id_category as array key.  And do the comparation to the current day by using the date function.   This can be a good start:

<?php

//if you have 7 categories 
// 7 days on a week

//id_category=1 :  Monday etc..

$days=array(1=>'Monday',2=>'Thursday','etc');
$id_category=(int)Tools::getValue('id_category');

if($id_category=='') $id_category=Context::getContext()->cookie->id_category;

if($id_category==$days[1]){

//do something

}

//etc  

I'll try this!

Thanks

Share this post


Link to post
Share on other sites

To make the products from a category that corresponds to a day unavailable for order I recommend you override the class Product and add the category test in the constructor.

You should never edit the core classes or controllers unless there is no other option. Instead use the overriding system of PrestaShop to make sure your changes aren't lost when updating to a newer version.

 

Create or edit the file /override/classes/Product.php and add the following code:

<?php

class Product extends ProductCore
{

    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
        
        // day name matches category name
        if (strtolower(date('l', time())) === $this->category) {
            $this->available_for_order = false;
        }
    }

}

After saving go and delete /cache/class_index.php to be sure that the override will be activated.

Share this post


Link to post
Share on other sites

To make the products from a category that corresponds to a day unavailable for order I recommend you override the class Product and add the category test in the constructor.

You should never edit the core classes or controllers unless there is no other option. Instead use the overriding system of PrestaShop to make sure your changes aren't lost when updating to a newer version.

 

Create or edit the file /override/classes/Product.php and add the following code:

<?php

class Product extends ProductCore
{

    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
        
        // day name matches category name
        if (strtolower(date('l', time())) === $this->category) {
            $this->available_for_order = false;
        }
    }

}

After saving go and delete /cache/class_index.php to be sure that the override will be activated.

 

Hi

 

 

I think this solution is going to work, but i've got a doubt. The function takes the name of the Category, but the Date returns the Day in English... My web is in Spanish, and Category names are in  this language. 

 

I'm going to modify the code and make a switch of the Day and "convert" to Spanish but i think this isn't the best solution.

 

Thanks for the time!!!

 

Víctor

Share this post


Link to post
Share on other sites

Work with digits not with strings. Find them by id not buy name.

 

The problem with digits is the week days ara from 0 to 6, and the Category ID of the Shop are variable. I do a modification in product-list.tpl , getting day of the week (number) and comparing with CatId minus X. But In parent categories don't work.

I think the solution from gabdara will work better, if i can make it Work :-p 

There's any log output to see values returned from classes/Product.php?

 

Thanks again for your time and advices!

 

Víctor

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More