Forums / Setup & design / item_count always 1

item_count always 1

Author Message

Steve P

Wednesday 25 May 2005 7:47:16 am

Hello

I am having trouble setting item_count to always be 1 in the shop/basket? Probably my bad sytax :(

Any ideas?

Thanks

Steve

Łukasz Serwatka

Thursday 26 May 2005 12:21:16 am

Hi Steve,

Syntax is very simple:

{let basket=fetch( 'shop', 'basket' )}
    {count( $basket.items )}
{/let}

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Steve P

Thursday 26 May 2005 3:11:35 am

Thanks, but not sure I explained what I want to do. In plain english I'd like to achieve something like:

If the quantity of a product {$product_item.item_count} is greater than 1 set quantiy to 1 & echo "you have already ordered {$product_item.object_name}!!"

For some reason I can't seem to re-set {$product_item.item_count}?

Best

Steve

Łukasz Serwatka

Thursday 26 May 2005 3:38:44 am

Could you show your code?

This example checks if quantity is greater then 1, reseting quantity to 1 on template level only. Look in to kernel/shop/basket.php

{let basket=fetch( 'shop', 'basket' )}
    {section var=product_item loop=$basket.items}
        {section show=$product_item.item_count|gt(1)}
            you have already ordered
            <input type="text" name="ProductItemCountList[]" value="1" size="5" />
        {section-else}
            <input type="text" name="ProductItemCountList[]" value="{$product_item.item_count}" size="5" />
        {/section}
    {/section}
{/let}

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Steve P

Thursday 26 May 2005 3:56:39 am

Thank you Lukasz.

Your code displays correctly when item_count is greater than 1. I have been tying to insert something like:
<let>($product_item.item_count=1)</let> in the basket loop [& lots of variations in syntax] with no luck.

$product_item.item_count should aways be 1 for this application.

Steve P

Thursday 26 May 2005 4:22:15 am

Ahh! Becoming clearer. The data has already been written? So I could nobble the kernal here [is this a good idea?]

    if ( $itemID )
    {
        /* If found in the basket, just increment number of that items: */
        $item =& eZProductCollectionItem::fetch( $itemID );
        $item->setAttribute( 'item_count', 1 + $item->attribute( 'item_count' ) );
        $item->store();
    }

...or maybe set item_count to 1 in the template, display a warning & present a button to write the quantiy???

This is a great help - thanks!

Chris Lan

Wednesday 23 November 2005 7:17:49 am

Lukasz, Steve, friends,

I am fighting to implement a simple functionnality since three days but the only thing I succeed is to create bugs and bugs.

I just want to add in kernel/basket.php a control if he find the item, he does not add it again as they're only one sample of each.

My best result is :

if ( $http->hasPostVariable( "ActionAddToBasket" ) )
{
    $objectID = $http->postVariable( "ContentObjectID" );

    if ( $http->hasPostVariable( 'eZOption' ) )
        $optionList = $http->postVariable( 'eZOption' );
    else
        $optionList = array();
		$itemIDList = $http->postVariable( "ProductItemIDList" );
    	$i = 0;

The issue is when I use "continue shopping" it delete the content of my basket. I am lost. Please be merciful with a newbie ez.

Thanks,
Chris