Jump to content

[Solved] New Product with Attributes, but Add to Cart Button Still Appears


Recommended Posts

Whew! This one gave me the run around for a while, so I thought I would share what I found.

Version 1.4.0.8 + SVN trunk | IE 8.0.6 and FF 3.6.13

Under Preferences > Products, I changed the setting for Display "add to cart" button when product has attributes to No; because I want to force the customer to view the product and select the proper attribute combinations. After I set that value and saved, I added a new product with 4 attribute combinations. I viewed the product under its category, and everything looked fine.

Then, I viewed the product under "New Products," and the Add to Cart button appeared! I added another product with a similar number of attribute combinations, and it was fine under its category and the "New Products" display. Next, I wasted a couple of hours of forum searching and code diving. I deleted some products and re-added them. The problem seemed random.

Then, I decided to look in the database and see if there was a difference between the products that were working properly and those that weren't. I found one column in the `xx_product` table that was different than the others. The `cache_default_attribute` value was zero for the faulty product, and had values of 1 or 3 for the others.

I changed the zero value to one, cleared my cache, and BAM - no "Add to cart" button. Now I should find out where this value gets set, what setting it should have, and why it isn't setting properly; but that may have to wait.

UPDATE: The only code related to that column I could find was in /classes/Product.php

Link to comment
Share on other sites

I haven't had time yet to track down the code that updates this column. I did, however, create a database script, since I'm a DB guy, that will set the cache_default_attribute of a given product to its default attribute combination, if it is not set by the system. Just substitute the "x" value with the id_product value for the product you are updating:

/* Execute after adding product, running attribute generator, and 
  selecting a default attribute combination
  Replace x with the proper product id */
UPDATE `ps_product` SET `cache_default_attribute` = (
 SELECT `id_product_attribute` FROM `ps_product_attribute` WHERE `default_on` = 1 AND
 `id_product` = x) WHERE `id_product` = x;

  • Like 1
Link to comment
Share on other sites

  • 2 years later...

Thank you for the information @web.geek attached is a PHP Script to re-index product cache attributes


You need to edit the file product_cache_attributes.php to updated your DB username & password than upload it to your web-server with FTP and open the file URL in your web browser.

product_cache_attributes.php

Edited by HA!*!*Y (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...

I have solved it by executing this query:

UPDATE `ps_product` SET `cache_default_attribute` = 0;
UPDATE `ps_product_shop` SET `cache_default_attribute` = 0;
UPDATE `ps_product` AS p, `ps_product_attribute` AS pa 
SET p.`cache_default_attribute` = pa.`id_product_attribute` 
WHERE p.`id_product` = pa.`id_product` AND pa.`default_on` = 1;
UPDATE `ps_product_shop` AS p, `ps_product_attribute` AS pa 
SET p.`cache_default_attribute` = pa.`id_product_attribute` 
WHERE p.`id_product` = pa.`id_product` AND pa.`default_on` = 1;
  • Like 1
Link to comment
Share on other sites

  • 5 months later...

 

I have solved it by executing this query:

UPDATE `ps_product` SET `cache_default_attribute` = 0;
UPDATE `ps_product_shop` SET `cache_default_attribute` = 0;
UPDATE `ps_product` AS p, `ps_product_attribute` AS pa 
SET p.`cache_default_attribute` = pa.`id_product_attribute` 
WHERE p.`id_product` = pa.`id_product` AND pa.`default_on` = 1;
UPDATE `ps_product_shop` AS p, `ps_product_attribute` AS pa 
SET p.`cache_default_attribute` = pa.`id_product_attribute` 
WHERE p.`id_product` = pa.`id_product` AND pa.`default_on` = 1;

 

This worked for me to make sure that the prices are present in the productlistings. So "Thanks!"

 

But... it's still not working for the new "popular" products on the main-page, it still says "0,00 euro".

 

In the mean time I shut down the module, but I would like to show the new products with the correct price, or even with no price at all, just a small title and photo will do. Who can help with that?

Link to comment
Share on other sites

This worked for me to make sure that the prices are present in the productlistings. So "Thanks!"

 

But... it's still not working for the new "popular" products on the main-page, it still says "0,00 euro".

 

In the mean time I shut down the module, but I would like to show the new products with the correct price, or even with no price at all, just a small title and photo will do. Who can help with that?

 

Have you tried to clear cache?

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