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