I'm working on a modification to CMSMS View Cart Template to suggest associated items to items already in cart. Versions CMSMS 1.10.2 with Cart 1.8.1.
I've tried to create a PHP script with the Viewcart Template to read Variables into Associative Array for Items associated with the cart item but can't get them into the array, the array values are empty. I can write values into the array directly so I know that the array is created and can print_r.
The array should look like this so that I can read there recommended items back out with a {foreach}, and can increment the recommended quantities as many cart items will have the same associated item.
Array Name SuggestedItem.Sku.Index.Value Where SKU is read from Smarty
SuggestedItem.SkuA
[Url]=value
[RecommendedQty]=value
[CaseQTY]=value
SuggestedItem.SkuB
[Url]=value
[RecommendedQty]=value
[CaseQTY]=value
...etc.
Current template snippet, successfully reads values from the cart into variables.
======================================
{assign var="RecommendedQty" value=$RecommendedQty+$oneitem->flds.CaseCount->value*$oneitem->quantity}
{capture append='Sku'}{$oneitem->flds.ClosureSKU->value}{/capture}
{capture append='SkuPack'}{$oneitem->flds.ClosureSKUQty->value}{/capture}
{capture append='SkuURL'}{$oneitem->flds.ClosureURL->value}{/capture}
{assign var="RecommendedQty" value=$RecommendedQty+$oneitem->flds.CaseCount->value*$oneitem->quantity}
PHP code in template, used for Testing, 'link' and 'case' values used for testing.
=======================
{php}
global $gCms;
$smarty =& $gCms->GetSmarty();
$smarty->assign('Suggested',
array('Sku' => $Sku, --Sku
$Values => array('Qty' => $RecommendedQty,
'link' => '555-111-1234",
'case' => '555-111-5678')
)
);
{/php}
Print_r of
<h3>Suggested</h3>
{$Suggested|print_r}
<h3>Sku</h3>
{$Sku|print_r}
Returns....
<h3>Suggested</h3>
Array
(
[Qty] =>
[link] => 555-111-1234
[case] => 555-111-5678
)
Array
<h3>Sku</h3>
Array
<h3>Cart</h3>
Help needed Creating Associative Array within Cart [Solved]
-
- New Member
- Posts: 4
- Joined: Tue Mar 15, 2011 5:58 pm
Help needed Creating Associative Array within Cart [Solved]
Last edited by patrickpowerlight on Mon Jan 16, 2012 7:35 pm, edited 1 time in total.
Re: Help needed Creating Associative Array within Cart Templ
Cart only knows what the incoming module tells it, so if you use Products module to sell items it pushes the items to Cart...
So it looks like you need to instantiate Products module then pull some variables from it to put in Cart...
So it looks like you need to instantiate Products module then pull some variables from it to put in Cart...