Pass additional information to cart

Author Message

Alex Jones

Monday 11 August 2003 11:52:50 am

How can I pass additional information from a product page to the shopping cart? While I can easily add a hidden field on my product page, I'm not sure as to how to capture and display the information from that hidden field in the cart page.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Claire Lin

Monday 11 August 2003 2:09:47 pm

I am not sure what you are trying to do. If you need extra info for a product, why not just modify the product class attributes?

On the other hand, if you want to record extra info on an order, I had a situation where I need to record the payment method chosen by the user (say visa, mastercard, or check). I used the spare data fields of the "ezorder" class. There are two fields you can use, data_text_1, and data_text_2. YOu can use something like the following to set the attributes: $order->setAttribute( 'data_text_1', $method ); To display the attribute in cart, just

I did the following in the php code:
$method = $http->postVariable( "WorkflowEvent_event_ezconfirmprocess_paymentmethod" );
include_once( 'kernel/classes/ezorder.php' );
$orderID = eZHTTPTool::sessionVariable( 'MyTemporaryOrderID' );
$order = eZOrder::fetch( $orderID );
$order->setAttribute( 'data_text_1', $method );
$order->store();

Alex Jones

Monday 11 August 2003 2:23:36 pm

Claire, thanks for responding. At this point I merely need the capability to pass a text string from the product page to the cart. Thanks for that code snippet, it may be exactly what I need. :)

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Alex Jones

Tuesday 12 August 2003 8:39:01 am

Actually, I'm not quite sure if this is what I need. Perhaps I'm just not getting it in general. :(

What I am trying to do is pass the contents of a field (in my product class) from the product page to the shopping cart. Some of my product pages contain/display more than one product, so the standard 'add to cart' functionality doesn't work as it is node-based and automatically displays the information from the first item on the product page, even when the second item was chosen.

What I would like is to set up the shopping cart to display certain fields passed from the product page and hold onto those values until the order is processed or cancelled. As our cart will be pretty straightforward (just e-mailing all of the values) I don't think this should be too hard, but I am confused as to how to pass the variables from product page to cart, then capture and display them on the cart.

Is there a way of doing this without modifying the underlying PHP? I really don't want to risk losing these changes in a future upgrade.

Does this make sense? Is it possible?

I would truly appreciate an example of how to accomplish this as I have scoured the forum and documentation and have yet to find something that makes sense by explaining where each change needs to be made.

Thanks,

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Wednesday 13 August 2003 4:00:51 am

I assume that overriding the shop template files like basket.tpl isn't what you are after?

paul

Alex Jones

Wednesday 13 August 2003 6:46:24 am

Paul, at this point I'm not sure what changes need to be made to the basket template in order to gather the information I need. It may indeed be as simple as an override, but I'm missing something...

How can I tell the basket to grab and store a field from a hidden input posted from the product page?

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Wednesday 13 August 2003 8:44:40 am

Ah, i didn't see that it was a hidden field being posted. So the value of this hidden field is from one of your objects attributes?

Im wondering. Basket.tpl has access to your products, so you have access to all of their fields to do with as you wish.

Does this give you the access you need? Or does the hidden field contain something the chosen products do not contain?

If you need to pass a special value through then you would need to edit the kernel/shop/basket.php file so that it reads your post variable and sets the template with the correct variable, sort of passing it through.

paul

Alex Jones

Wednesday 13 August 2003 8:50:06 am

Well, I need to tell the basket which field to grab. For example, I may have item_1_name, item_1_price and item_2_name and item_2_price which are on the same page (and are in the same node/content form) each has a purchase button on the page. The standard code sends the node information, but I need to be able to tell the basket that it should grab the item_2_name and item_2_price instead of the default item_1_name and item_1_price.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Wednesday 13 August 2003 9:09:58 am

Im having a little difficulty seeing exactly what you are doing. Are you saying that when you have multiple products on a page you want the basket to add only the single item you have chosen?

The site we are working on (slowly) uses this, and we have six products on the screen at any one time. Each product is contained in its own template (full,line,menu) and in each template we have code like:

<form action={"/content/action/"|ezurl} method="post">
----<input type="hidden" name="ContentObjectID" value="{$content_object.id}" />

----<input type="image" src={"buttons/b-addbasket.gif"|ezimage} name="ActionAddToBasket" align="middle" border="0" alt="Add to basket" />
</form>

The important point here is that each product item is wrapped with its own form. This allows you to select one over another.

Hope this is getting close to what you want :)

paul

Alex Jones

Wednesday 13 August 2003 9:27:40 am

Close...very very close. :)

From what I can tell, you are displaying multiple products (each of which is a node) on a single page; whereas I am displaying multiple products that share a single node (all input in a single class form).

Thus, if I understand you correctly your products A, B and C each have a unique ContentObjectID. Each of my products (1, 2 and 3) share a ContentObjectID as they all exist within the same 'product'.

My product form has fields akin to:
Item 1 Name:
Item 1 Number:
Item 2 Name:
Item 2 Number:
Item 3 Name:
Item 3 Number:

So, I need the basket to recognize which item (1, 2 or 3) was chosen by the user. I figure the best way is to pass the information via a hidden field, though I am open to other suggestions.

One note, I cannot change the product forms at this point as they are setup in a way that meets our business requirements - plus we are constrained by time. So, my hands are tied along those lines.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Wednesday 13 August 2003 9:37:21 am

Mmm, tricky one. I understand you now. One big problem i see is that the ez db table, ezproductcollection_item, where product items are stored (ezorder_item doesn't seem to get used...) requires that a product has a contentobject_id, and therefore a content object.

While your front end might not be able to change can you change the back end? To me you have individual products.

paul

Alex Jones

Wednesday 13 August 2003 9:41:45 am

How do you mean change the back-end?

What I am pondering is the ability to pass a variable that would contain the item number (item_1, item_2) which I could then tap into within the templates to grab the proper names, number and price for display and e-mail.

Is this viable? If so, how do I go about setting up the basket to recognize a new post variable? The various forum entries and documentation is a bit confusing. I'm using 3.1.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Wednesday 13 August 2003 9:54:33 am

Sorry, by back-end i meant the ez side where you categorise 'something' as a product, how you design what is what.

From what i can see Items 1, 2 and 3 are seperate products but you are classifying them as being a single product of three varieties.

This is more difficult to do. When you select your product and your variety (my term!) do you then wish to set the object with the variety chosen? In a sense what you are doing is editing the product and changing a setting. Once you have done this you can pass it to the basket and have the basket do a simple check on attributes to show what has happened...

paul

Paul Forsyth

Wednesday 13 August 2003 9:57:59 am

For changing the basket you would need to do this at the top of the file:

if ( $http->hasPostVariable( 'my_post_var' )
{
------$myVar = $http->postVariable( 'my_post_var' );
}

and at the bottom include:

$tpl->setVariable( "my_post_var", $myVar );

to pass through the variable into your basket.tpl script.

paul

Alex Jones

Wednesday 13 August 2003 10:02:20 am

PF> From what i can see Items 1, 2 and 3 are seperate products but you are classifying them as being a single product of three varieties.

This is exactly right. Nicely put.

PF> This is more difficult to do. When you select your product and your variety (my term!) do you then wish to set the object with the variety chosen? In a sense what you are doing is editing the product and changing a setting. Once you have done this you can pass it to the basket and have the basket do a simple check on attributes to show what has happened...

Hrrrm, this seems close to what I need to do. This sounds a good bit like the Option datatype which didn't quite meet my initial needs. So how would I set this up to allow this pseudo-editing and attribute checking?

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Alex Jones

Wednesday 13 August 2003 10:04:36 am

Thanks for the code snippet Paul! I'll try that out.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Paul Forsyth

Thursday 14 August 2003 4:52:32 am

Yesterday i was thinking about how to handle this and realised that for our upcoming e-commerce site we don't have this kind of situation and am also wondering about the best way to proceed should we hit it.

A simple example of this would be to have a product such as a paint pot that comes in several colours. The user selects the paint pot and colour and somehow this gets stored for that user. Since the product content object cannot store this information per purchase I then thought that it would get stored within the 'ezproductcollection_item_opt' database table.

From what i can see in the code it is used to allow different pricing schemes to be applied to the product but it should be able to be used to allow for varieties of a product. But im not sure how to connect a particular content object with this. Is this where the ezOption datatype comes in? I notice 'kernel/shop/basket.tpl' looks for such options...

Anyone, has anyone used this?

Paul

Alex Jones

Thursday 14 August 2003 6:51:23 am

Well, I think the option datatype would be helpful for something like that assuming you don't need to associate a separate model number with the option, which is where I ran into a problem for the site I am working on. The option datatype doesn't allow you to set the value. It automatically numbers the value which is rather annoying and a bit counterintuitive considering most companies and stores (on-line or off) separate these differences with unique model numbers to ensure they can keep an accurate inventory.

Man...come to think of it, I probably could have created a new datatype based off of the eZoption with an additional field for model number. This would have solved so many issues! Too late now though.

Damn damn damn.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.