Mailing List Archive

[item-sub] - how to use [item-quantity] inside it?
Hi,

We need to improve the load speed of the basket and checkout pages from
our stores because the carts of our customers have an average of 60
different products and, also, we have a specific situation of 4 diferent
price levels per product according to a matrix customer x product. The
price and the discount area from interchange works for 2 of the prices,
but for the other 2 we calculate it in on-the-fly.

We are moving the calcs from [item-calc] to [item-sub] tag as it gives
us an average of 60% reduction in load/processing the basket and
checkout, according to [benchmark].

Inside the [item-sub] we need to use the code and quantity of the item
(from the cart) and a value from a scratch variable.

This is the calculation we do today in basket.html (very slow, but works):

==========================================================
[tmp desconto]0.8375[/tmp]    <-- hypothetical value, just for example,
changes for each customer
...
[item-list]
...
Price per unit: [currency][item-calc][item-price noformat] *
$Tag->scratch('desconto')[/item-calc][/currency]
Subtotal      : [currency][item-calc]([item-price noformat] *
$Tag->scratch('desconto')) * [item-quantity][/item-calc][/currency]
...
[/item-list]

==========================================================

We moved it to [item-sub] this way in basket.html (very fast, but works
partially):

==========================================================
[tmp desconto]0.8375[/tmp] <-- hypothetical value, just for example,
changes for each customer

[item-list]
...
[item-sub preco_unit_esp]
    my $code = shift;
    my $priceitem = $Tag->currency( { convert => 1 }, $Tag->price( {
code => $code, noformat => 1, interpolate => 1 } ) *
$Tag->scratch('desconto') );
    return $priceitem
[/item-sub]

[item-sub subtotal_esp]
    my $code = shift;
    my $qt = $item->{quantity};
    my $subtotalitem = $Tag->currency( { convert => 1 }, $Tag->price( {
code => $code, noformat => 1, interpolate => 1 } ) *
$Tag->scratch('desconto') * $qt );
    return $subtotalitem
[/item-sub]

Price per unit: [item-exec preco_unit_esp][item-code][/item-exec]
Subtotal      : [item-exec subtotal_esp][item-code][/item-exec]
...
[/item-list]

==========================================================

The problem is that $qt does not work as expected, it does not return
the quantity of the current item in the cart.

After digging Cart.pm, item_list.coretag and the list we saw a lot of
options for getting the item code and quantity from the cart. Then, in
the [item-sub] above we have tried this options:

1) my $code = shift;
2) my $code = $item->{code};
3) my $code = $Item->{code};
4) my $code = [item-code]; (with [item-sub subtotal_esp] and [item-sub
subtotal_esp interpolate=1])
5) my $code = $Tag->scratch('cod'); (inside the item-list and before the
item-sub we do a [tmp cod][item-code][/tmp])
6) my $code = "[item-code]";
7) my $code = $Item->[0]{code};
8) my $code = 2;

9) my $qt = shift;
10) my $qt = $item->{quantity};
11) my $qt = $Item->{quantity};
12) my $qt = [item-quantity];  (with [item-sub subtotal_esp] and
[item-sub subtotal_esp interpolate=1])
13) my $qt = $Tag->scratch('qtde');  (inside the item-list and before
the item-sub we do a [tmp qtde][item-quantity][/tmp])
14) my $qt = "[item-quantity]";
15) my $qt = $Item->[0]{quantity};
16) my $qt = 2;

And the results:

- 1 works perfectly for the code
- 2, 3, 4 and 5 "return $code" is either empty, ERROR or ARRAY??????
- 6 "return $code" is equal to the string "[item-code]"
- 7 works but as we typed the index "0" this gives us always the code
for the first item in the cart and not the code for the current item
listed (from 0 to n)
- 8 works but this is not a solution.

- 9, 10, 11, 12 and 13 "return $qt" is either empty, ERROR or ARRAY??????
- 14 "return $qt" is equal to the string "[item-quantity]"
- 15 works but as we typed the index "0" this gives us always the
quantity for the first item in the cart and not the quantity for the
current item listed (from 0 to n)
- 16 works but this is not a solution.

Can somebody give me a light on how to make $qt return the current
[item-quantity] on the situation above?

Thanks.

Best regards
Luiz Carlos Maciel Junior
MKNET SYSTEMS INFORMATICA LTDA.
Re: [item-sub] - how to use [item-quantity] inside it? [ In reply to ]
On 10/17/19 1:16 PM, Luiz Carlos Maciel Junior wrote:
> Hi,
>
> We need to improve the load speed of the basket and checkout pages from
> our stores because the carts of our customers have an average of 60
> different products and, also, we have a specific situation of 4 diferent
> price levels per product according to a matrix customer x product. The
> price and the discount area from interchange works for 2 of the prices,
> but for the other 2 we calculate it in on-the-fly.
>
> We are moving the calcs from [item-calc] to [item-sub] tag as it gives
> us an average of 60% reduction in load/processing the basket and
> checkout, according to [benchmark].
>
> Inside the [item-sub] we need to use the code and quantity of the item
> (from the cart) and a value from a scratch variable.
>
> This is the calculation we do today in basket.html (very slow, but works):
>
> ==========================================================
> [tmp desconto]0.8375[/tmp]    <-- hypothetical value, just for
> example, changes for each customer
> ...
> [item-list]
> ...
> Price per unit: [currency][item-calc][item-price noformat] *
> $Tag->scratch('desconto')[/item-calc][/currency]
> Subtotal      : [currency][item-calc]([item-price noformat] *
> $Tag->scratch('desconto')) * [item-quantity][/item-calc][/currency]
> ...
> [/item-list]

You would improve the speed above by converting all ITL into loop tags.
Most of the time slowness in loops comes from the final reparse of the
fully assembled loop body after the loop has finished processing. For a
minor adjustment, you also don't need to invoke $Tag just to get at scratch:

* Convert [currency]...[/currency] to [item-filter
currency]...[/item-filter]

* Convert $Tag->scratch('foo') to $Scratch->{foo}

To answer your specific question though ...

> ==========================================================
>
> We moved it to [item-sub] this way in basket.html (very fast, but works
> partially):
>
> ==========================================================
> [tmp desconto]0.8375[/tmp] <-- hypothetical value, just for example,
> changes for each customer
>
> [item-list]
> ...
> [item-sub preco_unit_esp]
>     my $code = shift;
>     my $priceitem = $Tag->currency( { convert => 1 }, $Tag->price( {
> code => $code, noformat => 1, interpolate => 1 } ) *
> $Tag->scratch('desconto') );
>     return $priceitem
> [/item-sub]
>
> [item-sub subtotal_esp]
>     my $code = shift;
>     my $qt = $item->{quantity};
>     my $subtotalitem = $Tag->currency( { convert => 1 }, $Tag->price(
> { code => $code, noformat => 1, interpolate => 1 } ) *
> $Tag->scratch('desconto') * $qt );
>     return $subtotalitem
> [/item-sub]
>
> Price per unit: [item-exec preco_unit_esp][item-code][/item-exec]
> Subtotal      : [item-exec subtotal_esp][item-code][/item-exec]
> ...
> [/item-list]

[snip]

> Can somebody give me a light on how to make $qt return the current
> [item-quantity] on the situation above?

You can access the record in question as a hash using $Row. E.g.,

[item-sub subtotal_esp]
$Tag->currency(
{ convert => 1,},
$Tag->price({ code => $Row->{code}, noformat => 1, })
* $Scratch->{desconto}
* $Row->{quantity},
)
[/item-sub]
Subtotal: [item-exec subtotal_esp][/item-exec]

--
Mark Johnson
End Point Corporation
http://www.endpoint.com

Phone: 571/577-4554
Skype: mark.at.endpoint
IRC: mark-ep@Freenode/#endpoint
_______________________________________________
interchange-users mailing list
interchange-users@interchangecommerce.org
https://www.interchangecommerce.org/mailman/listinfo/interchange-users
Re: [item-sub] - how to use [item-quantity] inside it? [ In reply to ]
Le 18/10/2019 à 11:48, Mark Johnson a écrit :
> On 10/17/19 1:16 PM, Luiz Carlos Maciel Junior wrote:
>> Hi,
>>
>> We need to improve the load speed of the basket and checkout pages from
>> our stores because the carts of our customers have an average of 60
>> different products and, also, we have a specific situation of 4 diferent
>> price levels per product according to a matrix customer x product. The
>> price and the discount area from interchange works for 2 of the prices,
>> but for the other 2 we calculate it in on-the-fly.
>>
>> We are moving the calcs from [item-calc] to [item-sub] tag as it gives
>> us an average of 60% reduction in load/processing the basket and
>> checkout, according to [benchmark].
>>
>> Inside the [item-sub] we need to use the code and quantity of the item
>> (from the cart) and a value from a scratch variable.
>>
>> This is the calculation we do today in basket.html (very slow, but works):
>>
>> ==========================================================
>> [tmp desconto]0.8375[/tmp]    <-- hypothetical value, just for
>> example, changes for each customer
>> ...
>> [item-list]
>> ...
>> Price per unit: [currency][item-calc][item-price noformat] *
>> $Tag->scratch('desconto')[/item-calc][/currency]
>> Subtotal      : [currency][item-calc]([item-price noformat] *
>> $Tag->scratch('desconto')) * [item-quantity][/item-calc][/currency]
>> ...
>> [/item-list]
> You would improve the speed above by converting all ITL into loop tags.
> Most of the time slowness in loops comes from the final reparse of the
> fully assembled loop body after the loop has finished processing. For a
> minor adjustment, you also don't need to invoke $Tag just to get at scratch:
>
> * Convert [currency]...[/currency] to [item-filter
> currency]...[/item-filter]
>
> * Convert $Tag->scratch('foo') to $Scratch->{foo}
>
> To answer your specific question though ...
>
>> ==========================================================
>>
>> We moved it to [item-sub] this way in basket.html (very fast, but works
>> partially):
>>
>> ==========================================================
>> [tmp desconto]0.8375[/tmp] <-- hypothetical value, just for example,
>> changes for each customer
>>
>> [item-list]
>> ...
>> [item-sub preco_unit_esp]
>>     my $code = shift;
>>     my $priceitem = $Tag->currency( { convert => 1 }, $Tag->price( {
>> code => $code, noformat => 1, interpolate => 1 } ) *
>> $Tag->scratch('desconto') );
>>     return $priceitem
>> [/item-sub]
>>
>> [item-sub subtotal_esp]
>>     my $code = shift;
>>     my $qt = $item->{quantity};
>>     my $subtotalitem = $Tag->currency( { convert => 1 }, $Tag->price(
>> { code => $code, noformat => 1, interpolate => 1 } ) *
>> $Tag->scratch('desconto') * $qt );
>>     return $subtotalitem
>> [/item-sub]
>>
>> Price per unit: [item-exec preco_unit_esp][item-code][/item-exec]
>> Subtotal      : [item-exec subtotal_esp][item-code][/item-exec]
>> ...
>> [/item-list]
> [snip]
>
>> Can somebody give me a light on how to make $qt return the current
>> [item-quantity] on the situation above?
> You can access the record in question as a hash using $Row. E.g.,
>
> [item-sub subtotal_esp]
> $Tag->currency(
> { convert => 1,},
> $Tag->price({ code => $Row->{code}, noformat => 1, })
> * $Scratch->{desconto}
> * $Row->{quantity},
> )
> [/item-sub]
> Subtotal: [item-exec subtotal_esp][/item-exec]


Hi Mark,

Thanks for your time.

Worked perfectly.


Best regards,

Luiz Carlos Maciel Junior
MKNET SYSTEMS INFORMATICA LTDA.
_______________________________________________
interchange-users mailing list
interchange-users@interchangecommerce.org
https://www.interchangecommerce.org/mailman/listinfo/interchange-users