Forums / Templates, Stylesheets, Page Layout / Show comments field below shopping cart if cart contains certain product model

Show comments field below shopping cart if cart contains certain product model

Locked

Started by frank18 on 5 Feb 2010, 6:54 AM · Views: 35,891

Results 1 to 10 of 10
This thread is locked. New replies are disabled.
5 Feb 2010, 6:54 AM
#1
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

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 https://www.frnt.org/zencart

Just drop something into the cart and you will see the comments field displayed.

Thanks in advance

Frank

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

7 Feb 2010, 11:07 PM
#2
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Show comments field below shopping cart if cart contains certain product model

anyone please ?? :(

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

8 Feb 2010, 3:21 AM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

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

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

8 Feb 2010, 5:19 AM
#4
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

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

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

8 Feb 2010, 7:48 PM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Show comments field below shopping cart if cart contains certain product model

You could use this function from the shopping_cart class:

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

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

8 Feb 2010, 11:34 PM
#6
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

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:

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

9 Feb 2010, 3:37 AM
#7
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

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:

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:

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)

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

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

9 Feb 2010, 4:53 AM
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

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

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

9 Feb 2010, 5:03 AM
#9
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

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:

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

9 Feb 2010, 10:37 AM
#10
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

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

define('TEXT_PRODUCT_OPTIONS', 'Please Choose: ');

to this

//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:

<!--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?

NOTE: We are sorry that Frank is no longer with us.
We are grateful for all his contributions to the Zen Cart community.