Shopping cart in Smarty

Asked

Viewed 39 times

2

I am developing a university project in which I have to develop a web site. I am using Smarty for code organization. This is a sales website and for this I am developing a shopping cart, and this is where I am having some difficulties... I added a php file with the following code:

  include_once('../../config/init.php');
  include_once ($BASE_DIR . 'database/events.php');


  if (!isset($_SESSION['cart']))
    $_SESSION['cart'] = array();

  $events = array();

  foreach ($_SESSION['cart'] as $id => $quantity) {
    $event = selectID($id);

    $event['quantity']=$quantity;
    $events[] = $event;

  }

  $types = getAllTypes();
  $smarty->assign('types', $types);
  $smarty->assign('events', $events);

  $smarty->display('shop/list_cart.tpl');

Followed by a Smarty . tpl file:

{include file='common/header.tpl'}

<section id="cart">
  <h2>Shopping Cart</h2>

  <table>
    {foreach from=$events key=id item=event}
      <tr>

        <td>{$event.preco}€</td>
        <td>{$event.nome}</td>



      </tr>
    {/foreach}
  </table>

  <form action="action_checkout.php">
    <input type="submit" value="Checkout">
  </form>

</section>


{include file='common/footer.tpl'}

However when I run the program there is an error where it says that price and name are not recognized... I think the error is in foreach template, but I’m not getting what to change.

  • There is a right way to enter the code into the question. Take a look at the tour and the part about asking questions. I see that a user had fixed his post, but it is not known why the correction was reversed.

  • in TPL d a <pre> followed by a {$Event|@print_r} please

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.