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

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

eZ debug

Timing: Jan 19 2025 08:53:45
Script start
Timing: Jan 19 2025 08:53:45
Module start 'layout'
Timing: Jan 19 2025 08:53:45
Module start 'content'
Timing: Jan 19 2025 08:53:46
Module end 'content'
Timing: Jan 19 2025 08:53:46
Script end

Main resources:

Total runtime1.4350 sec
Peak memory usage4,096.0000 KB
Database Queries71

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 589.1484152.6250
Module start 'layout' 0.00580.0028 741.773439.4297
Module start 'content' 0.00861.4247 781.2031627.6797
Module end 'content' 1.43330.0017 1,408.882816.1875
Script end 1.4350  1,425.0703 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.2365160.0002
Check MTime0.00130.0909160.0001
Mysql Total
Database connection0.00080.054910.0008
Mysqli_queries1.361494.8670710.0192
Looping result0.00090.0615690.0000
Template Total1.402097.720.7010
Template load0.00180.122820.0009
Template processing1.400297.572520.7001
Template load and register function0.00020.016610.0002
states
state_id_array0.00110.074610.0011
state_identifier_array0.00240.165820.0012
Override
Cache load0.00160.1098440.0000
Sytem overhead
Fetch class attribute can translate value0.00190.129330.0006
Fetch class attribute name0.00130.092090.0001
XML
Image XML parsing0.00440.305630.0015
class_abstraction
Instantiating content class attribute0.00000.0013100.0000
General
dbfile0.00650.4532240.0003
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 29
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs