Problems, need help? Have a tip or advice? Post it here.
13 posts Page 1 of 2
Hi
After some good practice with the base features of Couch, I started with a Shopping Cart Project.
Thanks to the good tutorial I've configured a lot of steps without a problem, but know I'm stuck at the point of adding items to the cart.

In this case, the cart is on the same page as the productpage. (gerechten.php)
So I have to change to following setting from cart.php to gerechten.php, am I right?

Code: Select all
$pp['tpl_cart'] = 'gerechten.php';
$pp['tpl_products'] = 'gerechten.php';


I followed the instructions of working with pp_product_form and pp_cart_items, and I added some basic variables like the title and image in there.

The cart is implemented in the sidebar, but after clicking at "Add to cart", nothing happens.
In the page source there isn't any content loaded in the sidebar.

Am I missing some steps here?
Thanks for looking into it!

Here is the full code off my productpage/cartpage "gerechten.php".

Code: Select all
<?php require_once ('dashboard/cms.php'); ?>

<cms:embed 'lang_getter.html' />

<cms:template title="Gerechten" order="10" clonable="1" dynamic_folders="1">

  <cms:editable name="productimg" label="Afbeelding (200x200)" type="image" order="1" width="200" width="200" crop="1" />
  <cms:editable name="pp_price" label="Prijs (per 100gr.)" desc="Geen euroteken toevoegen" type="text" order="2" />

  <cms:editable name="nederlands" label="Nederlands" type="group" order="10"/>
    <cms:editable name="page_title_nl" group="nederlands" label="Naam gerecht (NL)" type='text' order="10"/>
    <cms:editable name="page_content_nl" group="nederlands" label="Beschrijving gerecht (NL)" type="richtext" order="10" />

  <cms:editable name="engels" group="engels" label="Engels" type="group" order="20"/>
    <cms:editable name="page_title_en" group="engels" label="Naam gerecht (EN)" type='text' order="20"/>
    <cms:editable name="page_content_en" group="engels" label="Beschrijving gerecht (EN)" type="richtext" order="20"/>
 
  <cms:editable name="frans" group="frans" label="Frans" type="group" order="30"/>
    <cms:editable name="page_title_fr" group="frans" label="Naam gerecht (FR)" type='text' order="30"/>
    <cms:editable name="page_content_fr" group="frans" label="Beschrijving gerecht (FR)" type="richtext" order="30" />

  <cms:editable name="indonesie" group="indonesie" label="Bahasa Indonesia" type="group" order="40"/>
    <cms:editable name="page_title_in" group="indonesie" label="Naam gerecht (BA)" type='text' order="40"/>
    <cms:editable name="page_content_in" group="indonesie" label="Beschrijving gerecht (BA)" type="richtext" order="40"/>

</cms:template>

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Achtergrond - Casa Di Batavia</title>
    <meta name="description" content="Naast de schitterende natuurlandschappen, de prachtige kustlijnen en de indrukwekkende cultuur staat
    Indonesië bekend om haar heerlijke keuken. Dit komt voornamelijk door de zeer uiteenlopende specerijen die beschikbaar zijn in het land. Vandaag
    brengt Casa di Batavia deze keuken voor u tot in Gent.">
    <cms:embed 'styles.html'/>
  </head>
  <body>
    <div id="wrapper" class="container">
      <header>
        <cms:embed 'header.html'/>
      </header>
      <div class="row">
        <div id="content" class="col-md-9">
             <cms:pages order='asc'>
             <div class="row product-item">
              <div class="col-md-3 col-xs-3 product-img">
                <img src="<cms:show productimg />">
              </div>
              <div class="col-md-6 col-xs-6">
                <h2>
                  <cms:if my_lang='nl'><cms:show page_title_nl /></cms:if>
                  <cms:if my_lang='en'><cms:show page_title_en /></cms:if>
                  <cms:if my_lang='fr'><cms:show page_title_fr /></cms:if>
                  <cms:if my_lang='in'><cms:show page_title_in /></cms:if>
                </h2>
                <p>
                  <cms:if my_lang='nl'><cms:show page_content_nl /></cms:if>
                  <cms:if my_lang='en'><cms:show page_content_en /></cms:if>
                  <cms:if my_lang='fr'><cms:show page_content_fr /></cms:if>
                  <cms:if my_lang='in'><cms:show page_content_in /></cms:if>
                </p>
              </div>
              <div class="col-md-3 col-xs-3">
                <h3>
                  € <cms:show pp_price />
                </h3>
                <cms:pp_product_form class="cart-form">
                    <input class="product-quantity" name="qty" id="quantity" type="number" step="50" value="100" title="Quantity">
                    <input class="button product-add" type="submit" value="Add to Cart">
                </cms:pp_product_form>
                <h4>
                  <cms:folders>
                      <cms:show k_folder_title /> <br>
                  </cms:folders>
                </h4>
              </div>
            </div>
          </cms:pages>
        </div>
        <aside id="sidebar" class="col-md-3">
          <cms:pp_cart_items>
            <cms:show page_title_nl />
            <img src="<cms:show productimg />">
            <cms:if my_lang='nl'><cms:show page_content_nl /></cms:if>
          </cms:pp_cart_items>
          <cms:embed 'sidebar.html' />
        </aside>
      </div>
    </div>   
    <footer class="container-fluid">
      <cms:embed 'footer.html' />
    </footer>
    <cms:embed 'scripts.html' />
  </body>
</html>

<?php COUCH::invoke(); ?>   
Hi Sam,

I installed and tried out your template on my system.
You need to make two amendments for it work correctly -

1. Please modify the definition of 'pp_price' to make it a required field like this -
Code: Select all
<cms:editable name="pp_price" label="Prijs (per 100gr.)" desc="Geen euroteken toevoegen" type="text" order="2" 
    maxlength='10'
    required='1'
    search_type='decimal'
    validator='non_zero_decimal'
    width='150'
/>


2. Your code in the sidebar (that should show the cart) is currently this -
Code: Select all
<cms:pp_cart_items>
    <cms:show page_title_nl />
    <img src="<cms:show productimg />">
    <cms:if my_lang='nl'><cms:show page_content_nl /></cms:if>
</cms:pp_cart_items>   
As can be seen, you are attempting to loop through the items in cart (as exposed by cms:pp_cart_items) and then show the custom fields defined for the items (e.g. page_title_nl, productimg) etc.

To understand why your code is not showing the desired data, please place a cms:dump within the <cms:pp_cart_items> like this -
Code: Select all
<cms:pp_cart_items>

    <cms:dump />
   
    <cms:show page_title_nl />
    <img src="<cms:show productimg />">
    <cms:if my_lang='nl'><cms:show page_content_nl /></cms:if>
</cms:pp_cart_items> 

- and watch which variables are available for each cart item.

I think you'll see that your code *is* working (i.e. the items added the cart are being looped through) but you don't get any output because the variables you are trying to show are *not made available* by cms:pp_cart_items.

That is because, cms:pp_cart_items has to keep everything in session so it keeps only bare necessary properties of items in memory (as opposed to storing entire pages).

So how do we get the data you want?
Two ways -
1. Specify to cms:pp_cart_items the editable-regions that you need it to store in cart. To to this we need to prefix those editable regions by 'pp_'. E.g. 'productimg' should be defined as 'pp_productimg' (please note that while accessing this property, you'll still use 'productimg' e.g. <cms:show productimg />

2. In the cms:dump output you'll notice that we have the 'id' and 'name' of the items (cloned-pages) available. We can use any of these unique identifiers with cms:pages tag to fetch the full page data.

I suggest you please go with the second option as it won't require any change to your definitions.

Please modify your sidebar code to this and you should able to see the data you want -
Code: Select all
<cms:pp_cart_items>

    <cms:pages id=id limit='1'>
        <cms:show page_title_nl />
        <img src="<cms:show productimg />">
        <cms:if my_lang='nl'><cms:show page_content_nl /></cms:if>
    </cms:pages>

</cms:pp_cart_items>

Hope this helps.
Thanks!
This helps me a lot!

Other question: because the shop will sell foodproducts, my single unit value isn't 1, but 100 gr.
Is it possible to change this? Because now the total price is ofcourse wrong.

Thanks for looking into it.
the shop will sell foodproducts, my single unit value isn't 1, but 100 gr.
Is it possible to change this? Because now the total price is ofcourse wrong.
Yes, Sam, I noticed that and was wondering how to handle such scenario.

One way, I suppose, would be to declare 'pp_price' as 'decimal' and then set the price per gram.
On the front-end we can then enforce that the visitor inputs weight in increments of 50 grams or 100 grams.

Another would be to let the price be as it is (i.e. per 100 grams) and then use PHP code to calculate per gram price and multiply it with the inputted weight. This will require some custom programming, though.

Please let me know your thoughts.
Because I'm not that handy (yet) with custom PHP programming, I like to choose for option one. :-)

How exactly do I set the price per gram?
How exactly do I set the price per gram?
The pp_price region is already defined to be a decimal. Just change the 'label' from '100gr' to '1gr'
<cms:editable name="pp_price" label="Prijs (per 100gr.)" desc="Geen euroteken toevoegen" type="text" order="2"
maxlength='10'
required='1'
search_type='decimal'
validator='non_zero_decimal'
width='150'
/>

You need to simply feed in the value per gram now.

As for the frontend, you'll have to use JS to enforce only increments of 50 (50gms ,100gms, 150gms. etc.) are inputted.
I misunderstood your first solution, I thought we could set the value of 1 unit tot 100 grams.

Is a PHP way of working a difficult solution?
Any recommended forumposts that could help me with this? :)
Shouldn't be difficult if you can work with PHP.

Will require tweaking the 'cart/cart_ex.php' which basically allows over-riding all calculations.
The file itself is profusely documented so give it a look.
One example of it on the forum is this - viewtopic.php?p=14159#p14159
Adding to my last post -

Sam, in case you find it a little too difficult for you, please go ahead and complete your site.
Once that is done, let me know and I'll implement that code for you.
That's a really nice offer, thank you very much.
I'm gonna try first myself, would like to teach myself some programming. :-)

To be continued.. 8-)
13 posts Page 1 of 2