title: Create a new Prestashop cart in custom php
body: <p>In Prestashop, I've created a custom form where I show a list with all products and the user can fill the corresponding quantities. By submitting the form, I clear the cart and fill it with the new values and finally redirect to the checkout page.</p>
  
  <p>Everything's working fine, but only when the cart already exists. In a case of an empty cart (cart_id==null), I cannot add the products. I tried with several ways to create a $cart but I didn't manage to do so.</p>
  
  <p>I don't get any exceptions, the code is executed without errors, it's just that at the end, in the checkout page, the cart remains empty; I repeat, only when the cart was already empty. In the case of a cart with products in it, then the process is just perfect!</p>
  
  <p>I would appreciate some help on this.</p>
  
  <p>Here is my small controller that gets the products and quantities from the form and adds them in the cart:</p>
  
  <pre><code>include('../../config/config.inc.php');
  include('../../header.php');
  
  // Filling the array of products
  $products = array();
  foreach ($_POST as $key =&gt; $value)
      if (substr($key, 0, 9) === 'quantity_')
          $products[substr($key, 9)] = $value;
  
  // First of all, we remove all products
  $prods = $cart-&gt;getProducts();
  foreach ($prods as $prod)
      $cart-&gt;deleteProduct($prod['id_product']);
  
  // Adding the new products
  foreach ($products as $product_id =&gt; $quantity)
      if ($quantity &gt; 0)
          $cart-&gt;updateQty($quantity, $product_id);
  
  // Redirecting to the checkout page.
  header("Location: " . $_POST['redirect']);
  exit();`
  </code></pre>
  
  <p>Thank you in advance!</p>