How to display a defined quantity other then 1 in basket

Author Message

Sandra Parente

Tuesday 03 February 2004 11:39:30 am

I'using 3.3-2
I want to display the minimum quantity to be purchased for a product in the quantity text field in basket.tpl, which has this value: "{$Basket:ProductItem:item.item_count}"

I created a integer datatype in product class and gave it as identifier "item_count", in which to insert the minimum quantity.
Then I modified basket.php changing the string:

$item->setAttribute( "item_count", '1' );

into

$item->setAttribute( "item_count", $item_count );

The result is that after clicking 'Add to basket' it displays 0 as quantity.

I found no documentation for help. May someone give me some advice?

Regards.
Sandra

Sandra Parente
www.netbliss.it

Paul Forsyth

Tuesday 03 February 2004 11:58:47 am

I think that the value for your 'item_count' attribute isn't being read by the 'basket.php' script. When you assign the attribute with that value, because it hasn't been initialised, it will set it as 0.

Try adding this code, it should read the correct value from your object and set it.

In 'basket.php' before the 'foreach' line declare the item_count:

$item_count=0;

Within the 'foreach ( $attributes as $attribute )' loop add this:

if ($attribute->attribute("name") == "item_count")
{
   $item_count=$attribute->content();
}

This should set item_count properly.

Paul

Sandra Parente

Wednesday 04 February 2004 2:03:17 am

Hi, Paul.
I think the code now is OK but basket still displays quantity 0.
This is now my basket.tpl code:

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();
        }

    $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 );

Do you think integer datatype for item_count is ok? I see there is also an identifier datatype...

Thanks.
Sandra

Sandra Parente
www.netbliss.it

Paul Forsyth

Wednesday 04 February 2004 2:14:42 am

Make sure the attribute setting code is inside the loop. You have it outside:


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();
        }
    }

Try it with this.

Also, remember to clear your cache. The template may have cached values otherwise.

paul

Sandra Parente

Wednesday 04 February 2004 8:22:57 am

You are right Paul: I copied your code and cleared all caches manually, but the result is always 0 quantity.
In ezproductcollectionitem.php item_count is already defined this way:

  "item_count" => array( 'name' => "ItemCount",
                                                                'datatype' => 'integer',
                                                                'default' => 0,
                                                                'required' => true ),

This is maybe in contrast with what we added in basket.php:

if ($attribute->attribute("name") == "item_count")

Am I wrong?

Cheers.
Sandra

Sandra Parente
www.netbliss.it

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

Wednesday 11 February 2004 10:22:24 am

Welcome back, Paul.

Changing the value works, so this is confirmed.
The debugging gives this output:

eZDebug::writeDebug( 'Checking for '.$attribute->attribute("name") ); if ($attribute->attribute("name") == "item_count")

Maybe I inserted the debug code badly in basket.tpl?

Sandra

Sandra Parente
www.netbliss.it

Paul Forsyth

Wednesday 11 February 2004 11:08:03 am

Yes, i would have expected different debug results.

Can you try this. Replace the first eZDebug line with this code:

$attributeName=$attribute->attribute("name");
eZDebug::writeDebug( 'Checking for '.$attributeName );

The quotes may have been affecting the php.

If this doesn't output debug lines with the correct names can you show your current code here?

thanks

paul

Sandra Parente

Wednesday 18 February 2004 9:02:35 am

Hi Paul.
Sorry for the delay, just back from flu :(
This is the output I get now:

$attributeName=$attribute->attribute("name"); 
eZDebug::writeDebug( 'Checking for '.$attributeName ); 
if ($attribute->attribute("name") == "item_count") 

I was thinking to a more flexible solution. Suppose in product class we create an attribute (integer) called min_quantity, and suppose we want to display it in place of item_count attribute in basket.tpl (item_count must be equal to min_quantity)... Can we work directly in the template, without changing the kernel?

Sandra

Sandra Parente
www.netbliss.it

Paul Forsyth

Thursday 19 February 2004 12:20:46 am

Hmm, the code isn't printing what it should be printing. Can you show the code you are using?

Adding a another class attribute will still require kernel changes, because there is no other way of using your new variable to set the item count with.

paul

Sandra Parente

Thursday 19 February 2004 8:07:53 am

I receive no debug output if I insert the debugging code inside basket.php
If I insert the debugging code in basket.tpl I receive the same output wherever I insert it.

Unfortunately I'm a nerd with debugging.
What is the right place to put it?

Sandra.

Sandra Parente
www.netbliss.it

Paul Forsyth

Thursday 19 February 2004 10:50:54 am

It takes time :)

Can you post the code you have for basket.php? This is the place to put the information.

Paul

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

Friday 20 February 2004 4:06:17 am

Ok, you have a bracket in the wrong place and have code declared twice, but the important bit is the bracket. This finishes the loop early before the debug code can be used.

Look for code like this - it should be line numbers 73-77. Remove this, and try running again, with cache cleared.

if ($attribute->attribute("name") == "item_count")
       {
        $item_count=$attribute->content();
        }
}

If this doesn't work i'll repost the whole with the changes.

Paul

Sandra Parente

Friday 20 February 2004 9:12:52 am

I think I did a disaster :( I receive a parse error:
it's better if you post the whole code here...

Thanks
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' ) ) );
?>

Sandra Parente

Monday 23 February 2004 5:13:09 am

Thanks a lot Paul!
These are the only three warnings I receive:

-----------------------------------------------
Warning: PHP feb 23 2004 14:01:57
Undefined index: node in /var/www/html/prova/kernel/common/eztemplatedesignresource.php(222) : eval()'d code on line 1
Warning: PHP feb 23 2004 14:01:57
Undefined property: SetName in /var/www/html/prova/lib/eztemplate/classes/eztemplatesetfunction.php on line 155
Warning: eZTemplate feb 23 2004 14:01:57
Variable 'basket' already exists, cannot define
</code>
---------------------------------------------------

Are we near to the solution?
Cheers.

Sandra

Sandra Parente
www.netbliss.it

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