Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
Hello everyone,

I was wondering if the Couch Cart has a function to add products to the basket without the form tag. I need something like the <cms:db_persist where I can add the product without leave the page.

I'm thinking in make a form for each product and put the AJAX code to send each form, but it is an ugly solution, someone has a better idea?

Thank you,

RafaelNC
Hi Rafael,

Having a tag like <cms:db_persist /> for the cart would be useful if you wanted to add items to the cart programmatically i.e. without those being selected manually by the visitor from the front-end.

Somehow, I think that is not what you are looking for.
Could you please try to explain a bit more about how you wish things to happen?
Perhaps we can find a better solution.

Thanks.
Hello KK,

Actually is exactly what 'm looking for haha I'm sorry if I was not clear in my question.

I want to add products programmatically without the user interaction.

Thank you for the fast reply KK
@RafaelNC, while you are waiting for the answer from @KK, you might post some more info about your desired solution. This will make it easier for the rest of us and maybe you can get a solution sooner :)
unlimited time premium coding support $99 per project - PM or email me or discuss in topic
active topics
@trendoman Ok! The clients have a list of products they buy regularly, I call this list: regular-order.

Code: Select all
<cms:template clonable='1' title='Regular - Order' hidden='1' access_level='4'>
   <cms:editable
      name='product'
      type='relation'
      masterpage='products.php'
      label='Products'
      orderby='page_title'
      order='asc'
      has='one'
   />
   <cms:editable
      name='member'
      type='relation'
      masterpage='members/index.php'
      label='Member'
      orderby='page_title'
      order='asc'
      has='one'
   />
   <cms:editable type='text' name='qty' label='QTY'/>
   <cms:editable type='text' name='variants' label='Variants'/>
</cms:template>


I made a script that sends to the client a link to add these products at the basket and apply 10% of discount. The link sends the client to this code:

Code: Select all
<cms:if "<cms:gpc 'id' method='post' />">

   <cms:pages masterpage='members/index.php' id="<cms:gpc 'id' method='post' />">
      <cms:reverse_related_pages 'member' masterpage='members/regular-order.php' >
         


            HERE
      </cms:reverse_related_pages>   
      
      <cms:set_session name='coupon_found' value='1' />
    <cms:set_session name='coupon_code' value='58679' />
    <cms:set_session name='coupon_discount' value='10' />
    <cms:set_session name='coupon_type' value='0' />
    <cms:set_session name='coupon_min_amount' value='0' />
    <cms:set_session name='coupon_free_shipping' value='0' />
         
   </cms:pages>
</cms:if>


In 'HERE' I need something to add the product at the basket. I thought in create multiple forms for each product and use the AJAX method to add the products, but this is an ugly solution :( and I couldn't think in another solution.

Thank you
Ok, then any solution will be based on PHP.
Code: Select all
   <pre>
       <cms:php>$data = $_SESSION['kcart']; print_r($data);</cms:php>
   </pre>

Try to add some product to cart and run the code above. You will see all available products and their fields, stored in current session ("cart"). The solution would be to send data to those fields in array to modify the session. Once all products are there, you can safely use couch tags to list products in cart and take desired actions.

If you happen to know some PHP, then probably this link can help to properly send data to cart.php http://www.html-form-guide.com/php-form ... ubmit.html I know, this is not what you'd like to see as the final answer. I hope to learn something from this thread too :)
unlimited time premium coding support $99 per project - PM or email me or discuss in topic
active topics
@trendoman Thank you very much! Worked perfectly!

Here is the code if someone needs:

Code: Select all
<cms:php>
          $data = $_SESSION['kcart'];
          <cms:reverse_related_pages 'member' masterpage='regular-order.php' >
             <cms:set qty="<cms:show qty />" 'global' />
             <cms:related_pages 'product'>
                $productCount += <cms:show qty />;
                $subTotal += <cms:mul qty pp_price />;
                
                
                $newItem = array
                (
                   "line_id" => md5("c"."<cms:show k_page_name />"),
                      "id" => "<cms:show k_page_id />",
                      "name" => "<cms:show k_page_name />",
                      "title" => "<cms:show k_page_title />",
                      "link" => "<cms:show k_page_link />",
                      "price" => "<cms:show pp_price />",
                      "quantity" => "<cms:show qty />",
                      "line_total" => "<cms:mul qty pp_price />",
                      "skip_line_total" => "0",
                      "options" => "Array()",
                      "requires_shipping" => "1",
                      "product_thumb" => "<cms:show pp_product_thumb />",
                      "previous_price" => "<cms:show pp_previous_price />",
                      "discount_scale" => "",
                      "shipping_scale" => "",
                      "orig_price" => "<cms:show pp_price />",
                      "line_discount" => "0"
                );
                $data['items']['c'.'<cms:show k_page_name />'] = $newItem;
         
      
             </cms:related_pages>
          </cms:reverse_related_pages>   
          
             $discount = round($subTotal * 0.1,
             $shipping = 0;
             
             
          $data['count_items'] = $productCount;
          $data['count_shippable_items'] = $productCount;
          $data['sub_total'] = $subTotal;
          $data['discount'] = $discount;
          $data['sub_total_discounted'] = round($subTotal - $discount, 2);
          $data['shipping'] = $shipping;
          $data['total'] = round($subTotal - $discount + $shipping, 2);
          
          
          $_SESSION['kcart'] = $data;
       </cms:php>
Wow! Congrats!

I am so glad my little investigation helped :D

Thanks for getting back and sharing, @RafaelNC!
unlimited time premium coding support $99 per project - PM or email me or discuss in topic
active topics
8 posts Page 1 of 1

Who is online

In total there are 8 users online :: 0 registered, 0 hidden and 8 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 8 guests