Forums / Setup & design / Change product option(s) from within basket?

Change product option(s) from within basket?

Author Message

Felix Leimbach

Sunday 25 February 2007 9:26:20 am

Hello everyone,

what I'm trying to achieve is:

- A product with an ezOption attribute is sitting in the shop's basket.
- The user should be able to change that option (f.ex. product's color, size, first issue, ...)

The following code takes care of showing the option to the user:

{attribute_view_gui attribute=$MyProduct.item_object.contentobject.data_map.my_option}

But the option is neither saved within the "StoreChangesButton" event nor within the "CheckoutButton" event.

Digging through /kernel/shop/basket.php I can see, that product options are only supposed to be set when a product is <b>added</b> to the basket.

IMHO it's very user-unfriendly to force them to remove an item form the basket, search it again, and add with a different option.

Other options I tried:

- add a HTML input field with the option and grab it with ezhttp() in the userregister.tpl
=><b>PROBLEM:</b> Needs modification to shop /kernel/shop/basket.php to pass through the POST fields. That's at least ugly and surely breaks updates made by your fellow sysadmin

- add it to the user's session and later grab it with http('whatever', 'session')
=><b>PROBLEM:</b> Didn't figure out how to set a session variable from within a template. Does anyone know how to do that?

How did you all solve this in your shops?
I'm on eZP 3.8.6

kracker (the)

Wednesday 28 February 2007 11:16:33 am

Hello Felix,

I think you have a good idea for a useful feature.

It would seem that you might want to remove the existing product (+option selection) from the basket before adding the new product (+option selection) (if the basket does not provide for option selection changes from within the cart on an existing cart item.

* You might want to create a workflow event which is triggered upon the execution of the 'addtocart' workflow trigger, which performed the tasks required to provide the above dependencies.

<i> > But the option is neither saved within the "StoreChangesButton" event nor within the "CheckoutButton" event.</i>

These details seem (to me upon first review) to be abstracted in the add to basket process but not supported afterwards...

<i> > Digging through /kernel/shop/basket.php I can see, that product options are only supposed to be set when a product is added to the basket.</i>

I too have had to modify the kernel in the past to move past this issue / breakdown.

<i> > IMHO it's very user-unfriendly to force them to remove an item form the basket, search it again, and add with a different option.</i>

I hear you man ...

Got any specific examples for suggestions for an actual api adjustment to cleanly and flexibly address this problem for everyone ... cause the distance between A to B to C is so relative it's driven by communicating weight ... I was listening.

<i> > - add it to the user's session and later grab it with http('whatever', 'session') =>PROBLEM: Didn't figure out how to set a session variable from within a template. Does anyone know how to do that?</i>

- You might want to create an eZ publish workflow event which captures the $_REQUEST variables you need and trigger the resulting actions you wish to accomplish within the workflow event.

//kracker
<i>KMK - Last Chance</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

kracker (the)

Wednesday 28 February 2007 11:28:23 am

Related topic references,

I mention in passing the existence of the 'addtobasket' workflow trigger,
which if I remember correctly is not enabled by default (note) in the
presentation I made on eZ publish e-commerce, workflows and payment gateways.

You can enable the 'addtobasket' trigger by creating a modiying a setting override file called "workflow.ini.append.php" in the settings/override folder and add the following code to activate it.

[OperationSettings]
AvailableOperationList[]=shop_addtobasket
AvailableOperationList[]=shop_updatebasket

Search google for references on the subject keyword, 'addtobasket'
<i>http://www.google.com/search?hl=en&safe=off&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=addtobasket+site%3Aez.no&btnG=Search

eZ systems listens and accepts patches to eZ publish and the proof is in the threads you either read or find while searching,
<i>http://lists.ez.no/pipermail/sdk-public/2005-October/001682.html
http://lists.ez.no/pipermail/sdk-public/2005-March/001054.html</i>

Not as directly related but but ...
http://ez.no/community/forum/developer/how_to_include_an_add_to_basket_button_in_a_list_view_of_products</i>

hth,
//kracker
<i>KMK - One too many timez!</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

kracker (the)

Thursday 01 March 2007 1:59:36 pm

Related issue update ...

New Enhancement - #010363 : Change product option(s) from within basket <http://issues.ez.no/IssueView.php?Id=10363&amp;ProjectId=3>

//kracker

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Felix Leimbach

Tuesday 20 March 2007 5:16:12 am

Until someone at eZ gets around to tackle the issue tracked in the above link from kracker, I'll provide my temporary hack as a reference for others:

$YourDesign/templates/shop/basket.tpl:

(Add one or more HTML field(s) representing the options the user can chose from. An example follows)

{if array("YearlySubscription", "HalfyearlySubscription", "TrialSubscription")|contains($Product.item_object.contentobject.class_name)}
Subscription type: <select name="{$Product.item_object.contentobject.class_name}" size="1" onchange="document.getElementsByName('StoreChangesButton')[0].click();">
<option>yearly</option>
<option>...</option>
</select>
{/if}

Note that this must of course be placed within the HTML <form>. Upon saving and upon checking out of the basket your products options will be POSTed.
The bad thing now is, that eZ does NOT allow you to catch that POSTed variables in the subsequent form. Note that this defect only applies to the shop module.

The workaround is to catch the variables from within kernel/shop/basket.php and store them in a session variable, which in turn can be read from anywhere in your templates by ezhttp().
You might ask: Why not directly put it in a session variable from within basket.tpl?
Answer: There seems to be no template operator for that, searched docs and forums. I'll write one in future if I find the spare time.

if ( $http->hasPostVariable( "StoreChangesButton" ) )
{
    // HACK, see: http://ez.no/community/forum/setup_design/change_product_option_s_from_within_basket
    foreach (array('YearlySubscription', 'HalfyearlySubscription', 'TrialSubscription') as $ProductOption)
    {
            if ( $http->hasPostVariable( $ProductOption ) )
            {
                if ( $http->hasSessionVariable( $ProductOption ) )
                {
                    $http->removeSessionVariable( $ProductOption );
                }
                $http->setSessionVariable( $ProductOption, $http->postVariable( $ProductOption ) );
            }
    }
    // END HACK

    // original code follows, leave unmodified ...

if ( $http->hasPostVariable( "CheckoutButton" ) or ( $doCheckout === true ) )
{
    // HACK, see: http://ez.no/community/forum/setup_design/change_product_option_s_from_within_basket
    foreach (array('YearlySubscription', 'HalfyearlySubscription', 'TrialSubscription') as $ProductOption)
    {
            if ( $http->hasPostVariable( $ProductOption ) )
            {
                if ( $http->hasSessionVariable( $ProductOption ) )
                {
                    $http->removeSessionVariable( $ProductOption );
                }
                $http->setSessionVariable( $ProductOption, $http->postVariable( $ProductOption ) );
            }
    }
    // END HACK FL
   
    // original code follows, leave unmodified ...

The above codes allows you to catch the POSTed variable from your templates and set the products options accordingly. In my example I use it to
a) remember the chosen options while the user navigates in the shop
b) calculate prices and shipping cost accordingly
c) include it in the order confirmation email

Hope it helps someone :-)