iwonder Posted October 1, 2006 Posted October 1, 2006 A person I am modifying a script for would like a message to appear in the shopping cart when a product from a particular category is selected. The message states that they should enter the number 7 or 14 dicating a quantity amount. I thought something along the lines of the below would work but I'm unsure how to call up the category from the shoppping_cart.php page. if ($category == fabric) { $info_box_contents[0][] = array('align' => 'center', 'params' => 'class="productListing-heading"', 'text' => TABLE_HEADING_QUANTITY_NOTE); } else { $info_box_contents[0][] = array('align' => 'center', 'params' => 'class="productListing-heading"', 'text' => TABLE_HEADING_QUANTITY); } Any ideas or other suggestions would be appreciated.
iwonder Posted October 2, 2006 Author Posted October 2, 2006 Sorry should have mentioned that they don't want to use product attributes as they have too many products to modify. :)
boxtel Posted October 2, 2006 Posted October 2, 2006 Sorry should have mentioned that they don't want to use product attributes as they have too many products to modify. :) well, unfortunately the shipping cart does not hold the category info for the products which is rather odd as osc allows you to assign a product to multiple categories which then makes that info pretty valuable there. so you could alter the shopping cart to contain the category id that the product came from and have that info stored in the cart the moment the product is added or you will have to determine it after the fact which then requires some database calls. You could add a function like this: function category_has_product ($categories_name, $products_id) { global $languages_id; $products_id = tep_get_prid($products_id); $db_result = tep_db_query("select cd.categories_id from categories_description cd, products_to_categories p2c where p2c.products_id = '".$products_id."' and cd.categories_name = '".$categories_name."' and cd.categories_id = p2c.categories_id and cd.language_id = '".$languages_id."'"); if ($number_of_rows = tep_db_num_rows($db_result)) return true; return false; } and call it like this: if (category_has_product('fabric',$products[$i]['id'])) { // product belongs to category 'fabric' } but then again, it is never a good idea to use the category name as that can change and if it does your code stops functioning. Not to mention the difficulty if you have a mult-lingual site. So it would be better to use the category id's to do that. Treasurer MFC
iwonder Posted October 2, 2006 Author Posted October 2, 2006 Thanks. Looks scary but I'll give it a go.
boxtel Posted October 2, 2006 Posted October 2, 2006 Thanks. Looks scary but I'll give it a go. It is scary, use it wisely or it could destroy your shop. Treasurer MFC
boxtel Posted October 2, 2006 Posted October 2, 2006 Okay now I'm petrified. just kidding, it is a simple function which you give a category name and a product id and it returns either true or false. True if that product is defined in that category and false if it is not. Treasurer MFC
iwonder Posted October 2, 2006 Author Posted October 2, 2006 Whew. Okay now before I try this (showing my lack of knowledge) in which files do I place the coding? Is it two separate pages or all in the shopping_cart.php page?
boxtel Posted October 2, 2006 Posted October 2, 2006 Whew. Okay now before I try this (showing my lack of knowledge) in which files do I place the coding? Is it two separate pages or all in the shopping_cart.php page? well, that normally depends on the scope of the function. Many people simply dump any function they have in general.php for convenience but if that function is only used on a specific page, you might as well just put it in there. At least it then need not be loaded for pages which don't use it anyway. In your case I would not use the function to display a message about 7 or 14 being the quantities accepted because then you also need to verify that elsewhere. I would just offer a quantity dropdown with only 7 and 14 in there so they cannot choose anything else. Treasurer MFC
iwonder Posted October 2, 2006 Author Posted October 2, 2006 Sounds good. Shall have a go at creating the dropdown in the next few days.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.