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

Mark Johnson mark at endpoint.com
Fri Oct 18 14:48:06 UTC 2019


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 at Freenode/#endpoint


More information about the interchange-users mailing list