Show comments field below shopping cart if cart contains certain product model
Greetings,
I need to show the comments field just below the shopping cart content but ONLY if the cart contains one certain product model (let's call it model 12345).
If the cart contains any product which does not have the model attribute "12345", then the comments field should NOT show up below the content of the shopping cart.
As it stands now, the comments field always shows on the shopping cart page, regardless of model.
How can this be coded in a simple way?
ZC 1.3.7.1 with many add-ons
URL www.frnt.org/zencart
Just drop something into the cart and you will see the comments field displayed.
Thanks in advance
Frank
Re: Show comments field below shopping cart if cart contains certain product model
Re: Show comments field below shopping cart if cart contains certain product model
Wouldn't that be better done on a per Product basis with TEXT attributes?
You can just have a general TEXT box like you do, but what if you later need it for another Product ... and then another Product?
Do you need to just know ... Yes a products_id is in the cart ... or do you need to know how many or anything else?
There are several functions in the shopping_cart class that can be used to identify the contents ...
Re: Show comments field below shopping cart if cart contains certain product model
Thanks Linda
I have chosen to use the comments box as it re-appears on the following checkout pages. Customers are then always reminded to enter the details of their prescribing practitioner.
Basically the store has 2 types of products, Practitioner Only and general retail stuff. There are no plans or reasons to add another product type.
Also, I opted for the "model" attribute for ease of making a distinction. The field already exists on product details page.
So, if the cart contains one or more products with model = prac then the box is to appear. If none of the products in the cart is marked as prac then the box should not appear.
Eventually most non-prac (retail) items will disappear from this shop and will be permanently moved to my retail shop Personal Naturals.
What I am struggling with is the coding to make the box appear or not appear depending on product in the cart.
Appreciate your help
Thanks / Frank
Re: Show comments field below shopping cart if cart contains certain product model
You could use this function from the shopping_cart class:
Code:
/**
* Method to check whether a product exists in the cart
*
* @param mixed product ID of item to check
* @return boolean
*/
function in_cart($products_id) {
that will return true or false ...
Re: Show comments field below shopping cart if cart contains certain product model
Thanks Linda, will take a look at this during the course of the day and post my results .... if any .... :unsure:
Re: Show comments field below shopping cart if cart contains certain product model
I abolished the idea of using the "model" field - too messy etc. and assigned this attribute to relevant products:
Quote:
ID Option Name Option Type Option Value
2 Restricted Read Only Practitioner Details Required !
It had to be a Read Only attribute as I don't want any dropdowns, radio buttons, text fields or check boxes.
shows up in database as:
Quote:
products_options_id = 2
products_options_name = Restricted
example product: Blackmores P.C.I.P. 170tabs
So, if the cart contains product(s) with products_options_id = 2 the following should come into play:
(file tpl_shopping_cart_default.php around lines 131-136)
Quote:
<!--bof practitioner details-->
<fieldset class="shipping" id="comments">
<legend><?php echo TABLE_HEADING_COMMENTS; ?></legend>
<?php echo zen_draw_textarea_field('comments', '45', '3'); ?>
</fieldset>
<!--eof practitioner details-->
If the cart contains no products with products_options_id = 2 then comments box / legend should not be shown.
Not being savvy with php coding, how can I achieve this?
Thanks again
Re: Show comments field below shopping cart if cart contains certain product model
Read Only Attributes are just that ... they are for READONLY display on the Product _info page ... as such, they never get added to the cart ...
Re: Show comments field below shopping cart if cart contains certain product model
Thanks Linda
I have played with the TEXT attribute but it gives customers the option to enter something into the box. The Radio Button attribute also leaves the undesirable comment "please choose" when there really is no choice.
Hence I played with the READ ONLY attribute ..... :unsure:
Re: Show comments field below shopping cart if cart contains certain product model
Ok, changed the attribute from "Read Only" to "Radio" and got around the undesired *Please Choose:* by changing includes/languages/english/product_info.php
from this
Quote:
define('TEXT_PRODUCT_OPTIONS', 'Please Choose: ');
to this
Quote:
//define('TEXT_PRODUCT_OPTIONS', 'Please Choose: ');
define('TEXT_PRODUCT_OPTIONS', 'Please Note: ');
and saved the file using the override system.
So I guess the attribute could now be used to control the display of this bit of code:
Quote:
<!--bof practitioner details-->
<fieldset class="shipping" id="comments">
<legend><?php echo TABLE_HEADING_COMMENTS; ?></legend>
<?php echo zen_draw_textarea_field('comments', '45', '3'); ?>
</fieldset>
<!--eof practitioner details-->
Again, the box should only appear if the cart contains no products with products_options_id = 2
Any hints please?