Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In a first time, </p> <pre><code>if( in_array($id,$_SESSION['cartArr'])) { array_push($_SESSION['cartArr'], $id); } </code></pre> <p>If <code>$id</code> is in <code>$_SESSION['cartArr']</code>, why do you push it another time ? <br /> <br /> <br /> <br /> In a second time, your last inserted item in your "shoppingCart" is <code>$result</code> (array fetched) and your "shoppingCart" is in array of ids stored in session.<br /> So, in your template Shoppingcart.tpl, when you loop on <code>$cartArr</code>, <code>$item</code> is the id of your "product", not a variable who contains data of your "product". Then, in your <code>foreach</code> loop, you put <code>$arrProducts.attribute</code>, but <code>$arrProducts</code> corresponds to your last instert item.<br /> <br /></p> <p>So you have to get the data of each id passed in the loop :<br /> (I'm not sure of the smarty template syntax, but try to understand what I mean)</p> <pre><code> {$productDAO = new ProductDAO();} {foreach $cartArr as $item_id} {$item = $productDAO-&gt;getProductById($item_id);} &lt;div class="winkelkarItem"&gt; &lt;img src="{$item.image}" class="winkelkarImgPosition" alt="chimay" title="chimay"/&gt; &lt;ul class="winkelkarBeschrijving"&gt; &lt;li&gt;{$item.naam}&lt;/li&gt; &lt;li&gt;{$item.prijs}&amp;euro;&lt;/li&gt; &lt;li&gt;&lt;input class="winkelkarAmmount" type="text" value="2"/&gt;&lt;/li&gt; &lt;li&gt;7.08&amp;euro;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; {/foreach} </code></pre> <p><br /> <strong>EDIT :</strong><br /> Another solution, construct another array whith data of each "product", and pass it in you tpl.<br /></p> <p>In "Shoppingcart.php" :<br /></p> <pre><code>$productDAO = new ProductDAO(); $items_datas = array(); foreach($_SESSION['cartArr'] as $item_id) { $items_datas[] = $productDAO-&gt;getProductById($item_id); } $smarty-&gt;assign("items_datas",$items_datas); </code></pre> <p>In you "Shoppingcart.tpl" : <br /></p> <pre><code> {foreach $items_datas as $item} &lt;div class="winkelkarItem"&gt; &lt;img src="{$item.image}" class="winkelkarImgPosition" alt="chimay" title="chimay"/&gt; &lt;ul class="winkelkarBeschrijving"&gt; &lt;li&gt;{$item.naam}&lt;/li&gt; &lt;li&gt;{$item.prijs}&amp;euro;&lt;/li&gt; &lt;li&gt;&lt;input class="winkelkarAmmount" type="text" value="2"/&gt;&lt;/li&gt; &lt;li&gt;7.08&amp;euro;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; {/foreach} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload