Paul Forsyth
|
Wednesday 11 February 2004 1:20:28 am
There shouldn't be a clash, although the names are the same. If you are worried change the name of the variable to 'itemCount' or something similar. I think we need to debug this further. From the current code we know the line: $item->setAttribute( "item_count", 1 ); works. Try changing the value to a higher number to confirm higher numbers work as expected. It should but its always useful to confirm 'assumed' cases. I often miss the 'assumed' cases :) If this works as expected then the problem is with the retreival of the value from the content object. Use a debug statement to show the value:
eZDebug::writeDebug( 'Checking for '.$attribute->attribute("name") );
if ($attribute->attribute("name") == "item_count")
{
$item_count=$attribute->content();
eZDebug::writeDebug( 'Count of items is: '.$item_count );
}
If you have debugging enabled you should see some debug entries at the bottom of the screen. If the second debug statement doesn't appear then the name check isn't working, but the first debug line should show the exact string to use. Paul P.s, sorry for they delay, just back from holidays :)
|
Sandra Parente
|
Friday 20 February 2004 3:23:29 am
This is the code for the original basket.php with debugging information:
<?php
//
// Created on: <04-Jul-2002 13:19:43 bf>
//
// Copyright (C) 1999-2004 eZ systems as. All rights reserved.
//
// This source file is part of the eZ publish (tm) Open Source Content
// Management System.
//
// This file may be distributed and/or modified under the terms of the
// "GNU General Public License" version 2 as published by the Free
// Software Foundation and appearing in the file LICENSE.GPL included in
// the packaging of this file.
//
// Licencees holding valid "eZ publish professional licences" may use this
// file in accordance with the "eZ publish professional licence" Agreement
// provided with the Software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
// THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE.
//
// The "eZ publish professional licence" is available at
// http://ez.no/products/licences/professional/. For pricing of this licence
// please contact us via e-mail to [email protected]. Further contact
// information is available at http://ez.no/home/contact/.
//
// The "GNU General Public License" (GPL) is available at
// http://www.gnu.org/copyleft/gpl.html.
//
// Contact [email protected] if any conditions of this licencing isn't clear to
// you.
//
$http =& eZHTTPTool::instance();
$module =& $Params["Module"];
include_once( "kernel/classes/ezcontentobject.php" );
include_once( "kernel/classes/ezbasket.php" );
include_once( "kernel/classes/ezvattype.php" );
include_once( "kernel/classes/ezorder.php" );
include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
include_once( "kernel/classes/ezproductcollection.php" );
include_once( "kernel/classes/ezproductcollectionitem.php" );
include_once( "kernel/classes/ezproductcollectionitemoption.php" );
include_once( "kernel/common/template.php" );
include_once( 'lib/ezutils/classes/ezhttptool.php' );
$basket =& eZBasket::currentBasket();
$basket->updatePrices();
if ( $http->hasPostVariable( "ActionAddToBasket" ) )
{
$objectID = $http->postVariable( "ContentObjectID" );
$optionList =& $http->postVariable( "eZOption" );
$object = eZContentObject::fetch( $objectID );
$nodeID = $object->attribute( 'main_node_id' );
$http->setSessionVariable( "FromPage", "/content/view/full/" . $nodeID . "/" );
$price = 0.0;
$isVATIncluded = true;
$attributes = $object->contentObjectAttributes();
foreach ( $attributes as $attribute )
{
$dataType =& $attribute->dataType();
if ( $dataType->isA() == "ezprice" )
{
$priceObj =& $attribute->content();
$price += $priceObj->attribute( 'price' );
}
}
$basket =& eZBasket::currentBasket();
$sessionID = $http->sessionID();
$item =& eZProductCollectionItem::create( $basket->attribute( "productcollection_id" ) );
$item->setAttribute( "contentobject_id", $objectID );
$item->setAttribute( "item_count", 1 );
$attributeName=$attribute->attribute("name");
eZDebug::writeDebug( 'Checking for '.$attribute->attribute("name") );
if ($attribute->attribute("name") == "item_count")
{
$item_count=$attribute->content();
eZDebug::writeDebug( 'Count of items is: '.$item_count );
}
$item->setAttribute( "price", $price );
if ( $priceObj->attribute( 'is_vat_included' ) )
{
$item->setAttribute( "is_vat_inc", '1' );
}
else
{
$item->setAttribute( "is_vat_inc", '0' );
}
$item->setAttribute( "vat_value", $priceObj->attribute( 'vat_percent' ) );
$item->setAttribute( "discount", $priceObj->attribute( 'discount_percent' ) );
$item->store();
$priceWithoutOptions = $price;
eZDebug::writeDebug( $optionList, 'optionlist' );
foreach ( array_keys( $optionList ) as $key )
{
$attributeID = $key;
$optionSelected = $optionList[$key];
$attribute =& eZContentObjectAttribute::fetch( $attributeID, $object->attribute( 'current_version' ) );
$option =& $attribute->attribute( 'content' );
eZDebug::writeDebug( $option->attribute( 'option_list' ), "optionitems" );
foreach( $option->attribute( 'option_list' ) as $optionArray )
{
if( $optionArray['id'] == $optionSelected )
{
$optionItem =& eZProductCollectionItemOption::create( $item->attribute( 'id' ), $optionArray['id'], $option->attribute( 'name' ),
$optionArray['value'], $optionArray['additional_price'], $attributeID );
$optionItem->store();
$price += $optionArray['additional_price'];
break;
}
}
}
if ( $price != $priceWithoutOptions )
{
$item->setAttribute( "price", $price );
$item->store();
}
$module->redirectTo( "/shop/basket/" );
return;
}
if ( $http->hasPostVariable( "RemoveProductItemButton" ) )
{
$itemCountList = $http->postVariable( "ProductItemCountList" );
$itemIDList = $http->postVariable( "ProductItemIDList" );
$i = 0;
foreach ( $itemIDList as $id )
{
$item = eZProductCollectionItem::fetch( $id );
$item->setAttribute( "item_count", $itemCountList[$i] );
$item->store();
$i++;
}
$basket =& eZBasket::currentBasket();
$item = $http->postVariable( "RemoveProductItemButton" );
eZDebug::writeDebug( $item, "basket item" );
if ( is_numeric( $http->postVariable( "RemoveProductItemButton" ) ) )
{
$item = $http->postVariable( "RemoveProductItemButton" );
$basket->removeItem( $item );
}
else
{
$itemList = $http->postVariable( "RemoveProductItemDeleteList" );
foreach ( $itemList as $item )
{
$basket->removeItem( $item );
}
}
$module->redirectTo( $module->functionURI( "basket" ) . "/" );
return;
}
if ( $http->hasPostVariable( "StoreChangesButton" ) )
{
$itemCountList = $http->postVariable( "ProductItemCountList" );
$itemIDList = $http->postVariable( "ProductItemIDList" );
$i = 0;
foreach ( $itemIDList as $id )
{
$item = eZProductCollectionItem::fetch( $id );
if ( $itemCountList[$i] == 0 )
{
$item->remove();
}
else
{
$item->setAttribute( "item_count", $itemCountList[$i] );
$item->store();
}
$i++;
}
$module->redirectTo( $module->functionURI( "basket" ) . "/" );
return;
}
if ( $http->hasPostVariable( "ContinueShoppingButton" ) )
{
$itemCountList = $http->postVariable( "ProductItemCountList" );
$itemIDList = $http->postVariable( "ProductItemIDList" );
$i = 0;
foreach ( $itemIDList as $id )
{
$item = eZProductCollectionItem::fetch( $id );
$item->setAttribute( "item_count", $itemCountList[$i] );
$item->store();
$i++;
}
$fromURL = $http->sessionVariable( "FromPage" );
$module->redirectTo( $fromURL );
}
$doCheckout = false;
if ( eZHTTPTool::hasSessionVariable( 'DoCheckoutAutomatically' ) )
{
if ( eZHTTPTool::sessionVariable( 'DoCheckoutAutomatically' ) === true )
{
$doCheckout = true;
eZHTTPTool::setSessionVariable( 'DoCheckoutAutomatically', false );
}
}
$removedItems = array();
if ( $http->hasPostVariable( "CheckoutButton" ) or ( $doCheckout === true ) )
{
if ( $http->hasPostVariable( "ProductItemIDList" ) )
{
$itemCountList = $http->postVariable( "ProductItemCountList" );
$itemIDList = $http->postVariable( "ProductItemIDList" );
$i = 0;
foreach ( $itemIDList as $id )
{
$item = eZProductCollectionItem::fetch( $id );
$item->setAttribute( "item_count", $itemCountList[$i] );
$item->store();
$i++;
}
}
// Fetch the shop account handler
include_once( 'kernel/classes/ezshopaccounthandler.php' );
$accountHandler =& eZShopAccountHandler::instance();
// Do we have all the information we need to start the checkout
if ( !$accountHandler->verifyAccountInformation() )
{
// Fetches the account information, normally done with a redirect
$accountHandler->fetchAccountInformation( $module );
return;
}
else
{
// Creates an order and redirects
$basket =& eZBasket::currentBasket();
$productCollectionID = $basket->attribute( 'productcollection_id' );
$verifyResult =& eZProductCollection::verify( $productCollectionID );
$basket->updatePrices();
if ( $verifyResult === true )
{
$order =& $basket->createOrder();
$order->setAttribute( 'account_identifier', "default" );
$order->store();
eZHTTPTool::setSessionVariable( 'MyTemporaryOrderID', $order->attribute( 'id' ) );
$module->redirectTo( '/shop/confirmorder/' );
return;
}
else
{
$basket =& eZBasket::currentBasket();
$itemList =& $verifyResult;
$removedItems = array();
foreach ( $itemList as $item )
{
$removedItems[] = $item;
$basket->removeItem( $item->attribute( 'id' ) );
}
}
}
}
$basket =& eZBasket::currentBasket();
$tpl =& templateInit();
$tpl->setVariable( "removed_items", $removedItems);
$tpl->setVariable( "basket", $basket );
$tpl->setVariable( "module_name", 'shop' );
$Result = array();
$Result['content'] =& $tpl->fetch( "design:shop/basket.tpl" );
$Result['path'] = array( array( 'url' => false,
'text' => ezi18n( 'kernel/shop', 'Basket' ) ) );
?>
This is the code for the basket.php with the new variable declared and debugging info:
<?php
//
// Created on: <04-Jul-2002 13:19:43 bf>
//
// Copyright (C) 1999-2004 eZ systems as. All rights reserved.
//
// This source file is part of the eZ publish (tm) Open Source Content
// Management System.
//
// This file may be distributed and/or modified under the terms of the
// "GNU General Public License" version 2 as published by the Free
// Software Foundation and appearing in the file LICENSE.GPL included in
// the packaging of this file.
//
// Licencees holding valid "eZ publish professional licences" may use this
// file in accordance with the "eZ publish professional licence" Agreement
// provided with the Software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
// THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE.
//
// The "eZ publish professional licence" is available at
// http://ez.no/products/licences/professional/. For pricing of this licence
// please contact us via e-mail to [email protected]. Further contact
// information is available at http://ez.no/home/contact/.
//
// The "GNU General Public License" (GPL) is available at
// http://www.gnu.org/copyleft/gpl.html.
//
// Contact [email protected] if any conditions of this licencing isn't clear to
// you.
//
$http =& eZHTTPTool::instance();
$module =& $Params["Module"];
include_once( "kernel/classes/ezcontentobject.php" );
include_once( "kernel/classes/ezbasket.php" );
include_once( "kernel/classes/ezvattype.php" );
include_once( "kernel/classes/ezorder.php" );
include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
include_once( "kernel/classes/ezproductcollection.php" );
include_once( "kernel/classes/ezproductcollectionitem.php" );
include_once( "kernel/classes/ezproductcollectionitemoption.php" );
include_once( "kernel/common/template.php" );
include_once( 'lib/ezutils/classes/ezhttptool.php' );
$basket =& eZBasket::currentBasket();
$basket->updatePrices();
if ( $http->hasPostVariable( "ActionAddToBasket" ) )
{
$objectID = $http->postVariable( "ContentObjectID" );
$optionList =& $http->postVariable( "eZOption" );
$object = eZContentObject::fetch( $objectID );
$nodeID = $object->attribute( 'main_node_id' );
$http->setSessionVariable( "FromPage", "/content/view/full/" . $nodeID . "/" );
$item_count = 0;
$price = 0.0;
$isVATIncluded = true;
$attributes = $object->contentObjectAttributes();
foreach ( $attributes as $attribute )
{
$dataType =& $attribute->dataType();
if ( $dataType->isA() == "ezprice" )
{
$priceObj =& $attribute->content();
$price += $priceObj->attribute( 'price' );
}
if ($attribute->attribute("name") == "item_count")
{
$item_count=$attribute->content();
}
}
$attributeName=$attribute->attribute("name");
eZDebug::writeDebug( 'Checking for '.$attributeName );
if ($attribute->attribute("name") == "item_count")
{
$item_count=$attribute->content();
eZDebug::writeDebug( 'Count of items is: '.$item_count );
}
$basket =& eZBasket::currentBasket();
$sessionID = $http->sessionID();
$item =& eZProductCollectionItem::create( $basket->attribute( "productcollection_id" ) );
$item->setAttribute( "contentobject_id", $objectID );
$item->setAttribute( "item_count", $item_count );
$item->setAttribute( "price", $price );
if ( $priceObj->attribute( 'is_vat_included' ) )
{
$item->setAttribute( "is_vat_inc", '1' );
}
else
{
$item->setAttribute( "is_vat_inc", '0' );
}
$item->setAttribute( "vat_value", $priceObj->attribute( 'vat_percent' ) );
$item->setAttribute( "discount", $priceObj->attribute( 'discount_percent' ) );
$item->store();
$priceWithoutOptions = $price;
eZDebug::writeDebug( $optionList, 'optionlist' );
foreach ( array_keys( $optionList ) as $key )
{
$attributeID = $key;
$optionSelected = $optionList[$key];
$attribute =& eZContentObjectAttribute::fetch( $attributeID, $object->attribute( 'current_version' ) );
$option =& $attribute->attribute( 'content' );
eZDebug::writeDebug( $option->attribute( 'option_list' ), "optionitems" );
foreach( $option->attribute( 'option_list' ) as $optionArray )
{
if( $optionArray['id'] == $optionSelected )
{
$optionItem =& eZProductCollectionItemOption::create( $item->attribute( 'id' ), $optionArray['id'], $option->attribute( 'name' ),
$optionArray['value'], $optionArray['additional_price'], $attributeID );
$optionItem->store();
$price += $optionArray['additional_price'];
break;
}
}
}
if ( $price != $priceWithoutOptions )
{
$item->setAttribute( "price", $price );
$item->store();
}
$module->redirectTo( "/shop/basket/" );
return;
}
if ( $http->hasPostVariable( "RemoveProductItemButton" ) )
{
$itemCountList = $http->postVariable( "ProductItemCountList" );
$itemIDList = $http->postVariable( "ProductItemIDList" );
$i = 0;
foreach ( $itemIDList as $id )
{
$item = eZProductCollectionItem::fetch( $id );
$item->setAttribute( "item_count", $itemCountList[$i] );
$item->store();
$i++;
}
$basket =& eZBasket::currentBasket();
$item = $http->postVariable( "RemoveProductItemButton" );
eZDebug::writeDebug( $item, "basket item" );
if ( is_numeric( $http->postVariable( "RemoveProductItemButton" ) ) )
{
$item = $http->postVariable( "RemoveProductItemButton" );
$basket->removeItem( $item );
}
else
{
$itemList = $http->postVariable( "RemoveProductItemDeleteList" );
foreach ( $itemList as $item )
{
$basket->removeItem( $item );
}
}
$module->redirectTo( $module->functionURI( "basket" ) . "/" );
return;
}
if ( $http->hasPostVariable( "StoreChangesButton" ) )
{
$itemCountList = $http->postVariable( "ProductItemCountList" );
$itemIDList = $http->postVariable( "ProductItemIDList" );
$i = 0;
foreach ( $itemIDList as $id )
{
$item = eZProductCollectionItem::fetch( $id );
if ( $itemCountList[$i] == 0 )
{
$item->remove();
}
else
{
$item->setAttribute( "item_count", $itemCountList[$i] );
$item->store();
}
$i++;
}
$module->redirectTo( $module->functionURI( "basket" ) . "/" );
return;
}
if ( $http->hasPostVariable( "ContinueShoppingButton" ) )
{
$itemCountList = $http->postVariable( "ProductItemCountList" );
$itemIDList = $http->postVariable( "ProductItemIDList" );
$i = 0;
foreach ( $itemIDList as $id )
{
$item = eZProductCollectionItem::fetch( $id );
$item->setAttribute( "item_count", $itemCountList[$i] );
$item->store();
$i++;
}
$fromURL = $http->sessionVariable( "FromPage" );
$module->redirectTo( $fromURL );
}
$doCheckout = false;
if ( eZHTTPTool::hasSessionVariable( 'DoCheckoutAutomatically' ) )
{
if ( eZHTTPTool::sessionVariable( 'DoCheckoutAutomatically' ) === true )
{
$doCheckout = true;
eZHTTPTool::setSessionVariable( 'DoCheckoutAutomatically', false );
}
}
$removedItems = array();
if ( $http->hasPostVariable( "CheckoutButton" ) or ( $doCheckout === true ) )
{
if ( $http->hasPostVariable( "ProductItemIDList" ) )
{
$itemCountList = $http->postVariable( "ProductItemCountList" );
$itemIDList = $http->postVariable( "ProductItemIDList" );
$i = 0;
foreach ( $itemIDList as $id )
{
$item = eZProductCollectionItem::fetch( $id );
$item->setAttribute( "item_count", $itemCountList[$i] );
$item->store();
$i++;
}
}
// Fetch the shop account handler
include_once( 'kernel/classes/ezshopaccounthandler.php' );
$accountHandler =& eZShopAccountHandler::instance();
// Do we have all the information we need to start the checkout
if ( !$accountHandler->verifyAccountInformation() )
{
// Fetches the account information, normally done with a redirect
$accountHandler->fetchAccountInformation( $module );
return;
}
else
{
// Creates an order and redirects
$basket =& eZBasket::currentBasket();
$productCollectionID = $basket->attribute( 'productcollection_id' );
$verifyResult =& eZProductCollection::verify( $productCollectionID );
$basket->updatePrices();
if ( $verifyResult === true )
{
$order =& $basket->createOrder();
$order->setAttribute( 'account_identifier', "default" );
$order->store();
eZHTTPTool::setSessionVariable( 'MyTemporaryOrderID', $order->attribute( 'id' ) );
$module->redirectTo( '/shop/confirmorder/' );
return;
}
else
{
$basket =& eZBasket::currentBasket();
$itemList =& $verifyResult;
$removedItems = array();
foreach ( $itemList as $item )
{
$removedItems[] = $item;
$basket->removeItem( $item->attribute( 'id' ) );
}
}
}
}
$basket =& eZBasket::currentBasket();
$tpl =& templateInit();
$tpl->setVariable( "removed_items", $removedItems);
$tpl->setVariable( "basket", $basket );
$tpl->setVariable( "module_name", 'shop' );
$Result = array();
$Result['content'] =& $tpl->fetch( "design:shop/basket.tpl" );
$Result['path'] = array( array( 'url' => false,
'text' => ezi18n( 'kernel/shop', 'Basket' ) ) );
?>
Sandra
Sandra Parente
www.netbliss.it
|
Paul Forsyth
|
Sunday 22 February 2004 1:01:10 pm
Okay, heres the file. I tested it here and it works for me. To see the debugging information you must enable debugging in site.ini. You should be able to cut and paste into your system.
<?php
//
// Created on: <04-Jul-2002 13:19:43 bf>
//
// Copyright (C) 1999-2004 eZ systems as. All rights reserved.
//
// This source file is part of the eZ publish (tm) Open Source Content
// Management System.
//
// This file may be distributed and/or modified under the terms of the
// "GNU General Public License" version 2 as published by the Free
// Software Foundation and appearing in the file LICENSE.GPL included in
// the packaging of this file.
//
// Licencees holding valid "eZ publish professional licences" may use this
// file in accordance with the "eZ publish professional licence" Agreement
// provided with the Software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
// THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE.
//
// The "eZ publish professional licence" is available at
// http://ez.no/products/licences/professional/. For pricing of this licence
// please contact us via e-mail to [email protected]. Further contact
// information is available at http://ez.no/home/contact/.
//
// The "GNU General Public License" (GPL) is available at
// http://www.gnu.org/copyleft/gpl.html.
//
// Contact [email protected] if any conditions of this licencing isn't clear to
// you.
//
$http =& eZHTTPTool::instance();
$module =& $Params["Module"];
include_once( "kernel/classes/ezcontentobject.php" );
include_once( "kernel/classes/ezbasket.php" );
include_once( "kernel/classes/ezvattype.php" );
include_once( "kernel/classes/ezorder.php" );
include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
include_once( "kernel/classes/ezproductcollection.php" );
include_once( "kernel/classes/ezproductcollectionitem.php" );
include_once( "kernel/classes/ezproductcollectionitemoption.php" );
include_once( "kernel/common/template.php" );
include_once( 'lib/ezutils/classes/ezhttptool.php' );
$basket =& eZBasket::currentBasket();
$basket->updatePrices();
if ( $http->hasPostVariable( "ActionAddToBasket" ) )
{
$objectID = $http->postVariable( "ContentObjectID" );
$optionList =& $http->postVariable( "eZOption" );
$object = eZContentObject::fetch( $objectID );
$nodeID = $object->attribute( 'main_node_id' );
$http->setSessionVariable( "FromPage", "/content/view/full/" . $nodeID . "/" );
$price = 0.0;
$item_count=0;
$isVATIncluded = true;
$attributes = $object->contentObjectAttributes();
foreach ( $attributes as $attribute )
{
$contentClassAttribute =& $attribute->contentClassAttribute();
$attributeName=$contentClassAttribute->attribute("name");
eZDebug::writeDebug( 'Checking for '.$attributeName );
if ($attributeName == "item_count")
{
$item_count=$attribute->content();
}
$dataType =& $attribute->dataType();
if ( $dataType->isA() == "ezprice" )
{
$priceObj =& $attribute->content();
$price += $priceObj->attribute( 'price' );
}
}
$basket =& eZBasket::currentBasket();
$sessionID = $http->sessionID();
$item =& eZProductCollectionItem::create( $basket->attribute( "productcollection_id" ) );
$item->setAttribute( "contentobject_id", $objectID );
$item->setAttribute( "item_count", $item_count );
$item->setAttribute( "price", $price );
if ( $priceObj->attribute( 'is_vat_included' ) )
{
$item->setAttribute( "is_vat_inc", '1' );
}
else
{
$item->setAttribute( "is_vat_inc", '0' );
}
$item->setAttribute( "vat_value", $priceObj->attribute( 'vat_percent' ) );
$item->setAttribute( "discount", $priceObj->attribute( 'discount_percent' ) );
$item->store();
$priceWithoutOptions = $price;
eZDebug::writeDebug( $optionList, 'optionlist' );
foreach ( array_keys( $optionList ) as $key )
{
$attributeID = $key;
$optionSelected = $optionList[$key];
$attribute =& eZContentObjectAttribute::fetch( $attributeID, $object->attribute( 'current_version' ) );
$option =& $attribute->attribute( 'content' );
eZDebug::writeDebug( $option->attribute( 'option_list' ), "optionitems" );
foreach( $option->attribute( 'option_list' ) as $optionArray )
{
if( $optionArray['id'] == $optionSelected )
{
$optionItem =& eZProductCollectionItemOption::create( $item->attribute( 'id' ), $optionArray['id'], $option->attribute( 'name' ),
$optionArray['value'], $optionArray['additional_price'], $attributeID );
$optionItem->store();
$price += $optionArray['additional_price'];
break;
}
}
}
if ( $price != $priceWithoutOptions )
{
$item->setAttribute( "price", $price );
$item->store();
}
$module->redirectTo( "/shop/basket/" );
return;
}
if ( $http->hasPostVariable( "RemoveProductItemButton" ) )
{
$itemCountList = $http->postVariable( "ProductItemCountList" );
$itemIDList = $http->postVariable( "ProductItemIDList" );
$i = 0;
foreach ( $itemIDList as $id )
{
$item = eZProductCollectionItem::fetch( $id );
$item->setAttribute( "item_count", $itemCountList[$i] );
$item->store();
$i++;
}
$basket =& eZBasket::currentBasket();
$item = $http->postVariable( "RemoveProductItemButton" );
eZDebug::writeDebug( $item, "basket item" );
if ( is_numeric( $http->postVariable( "RemoveProductItemButton" ) ) )
{
$item = $http->postVariable( "RemoveProductItemButton" );
$basket->removeItem( $item );
}
else
{
$itemList = $http->postVariable( "RemoveProductItemDeleteList" );
foreach ( $itemList as $item )
{
$basket->removeItem( $item );
}
}
$module->redirectTo( $module->functionURI( "basket" ) . "/" );
return;
}
if ( $http->hasPostVariable( "StoreChangesButton" ) )
{
$itemCountList = $http->postVariable( "ProductItemCountList" );
$itemIDList = $http->postVariable( "ProductItemIDList" );
$i = 0;
foreach ( $itemIDList as $id )
{
$item = eZProductCollectionItem::fetch( $id );
if ( $itemCountList[$i] == 0 )
{
$item->remove();
}
else
{
$item->setAttribute( "item_count", $itemCountList[$i] );
$item->store();
}
$i++;
}
$module->redirectTo( $module->functionURI( "basket" ) . "/" );
return;
}
if ( $http->hasPostVariable( "ContinueShoppingButton" ) )
{
$itemCountList = $http->postVariable( "ProductItemCountList" );
$itemIDList = $http->postVariable( "ProductItemIDList" );
$i = 0;
foreach ( $itemIDList as $id )
{
$item = eZProductCollectionItem::fetch( $id );
$item->setAttribute( "item_count", $itemCountList[$i] );
$item->store();
$i++;
}
$fromURL = $http->sessionVariable( "FromPage" );
$module->redirectTo( $fromURL );
}
$doCheckout = false;
if ( eZHTTPTool::hasSessionVariable( 'DoCheckoutAutomatically' ) )
{
if ( eZHTTPTool::sessionVariable( 'DoCheckoutAutomatically' ) === true )
{
$doCheckout = true;
eZHTTPTool::setSessionVariable( 'DoCheckoutAutomatically', false );
}
}
$removedItems = array();
if ( $http->hasPostVariable( "CheckoutButton" ) or ( $doCheckout === true ) )
{
if ( $http->hasPostVariable( "ProductItemIDList" ) )
{
$itemCountList = $http->postVariable( "ProductItemCountList" );
$itemIDList = $http->postVariable( "ProductItemIDList" );
$i = 0;
foreach ( $itemIDList as $id )
{
$item = eZProductCollectionItem::fetch( $id );
$item->setAttribute( "item_count", $itemCountList[$i] );
$item->store();
$i++;
}
}
// Fetch the shop account handler
include_once( 'kernel/classes/ezshopaccounthandler.php' );
$accountHandler =& eZShopAccountHandler::instance();
// Do we have all the information we need to start the checkout
if ( !$accountHandler->verifyAccountInformation() )
{
// Fetches the account information, normally done with a redirect
$accountHandler->fetchAccountInformation( $module );
return;
}
else
{
// Creates an order and redirects
$basket =& eZBasket::currentBasket();
$productCollectionID = $basket->attribute( 'productcollection_id' );
$verifyResult =& eZProductCollection::verify( $productCollectionID );
$basket->updatePrices();
if ( $verifyResult === true )
{
$order =& $basket->createOrder();
$order->setAttribute( 'account_identifier', "default" );
$order->store();
eZHTTPTool::setSessionVariable( 'MyTemporaryOrderID', $order->attribute( 'id' ) );
$module->redirectTo( '/shop/confirmorder/' );
return;
}
else
{
$basket =& eZBasket::currentBasket();
$itemList =& $verifyResult;
$removedItems = array();
foreach ( $itemList as $item )
{
$removedItems[] = $item;
$basket->removeItem( $item->attribute( 'id' ) );
}
}
}
}
$basket =& eZBasket::currentBasket();
$tpl =& templateInit();
$tpl->setVariable( "removed_items", $removedItems);
$tpl->setVariable( "basket", $basket );
$tpl->setVariable( "module_name", 'shop' );
$Result = array();
$Result['content'] =& $tpl->fetch( "design:shop/basket.tpl" );
$Result['path'] = array( array( 'url' => false,
'text' => ezi18n( 'kernel/shop', 'Basket' ) ) );
?>
|