LemonStand Forum: Putting Add to Cart on the front page - LemonStand Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Putting Add to Cart on the front page

#1 User is offline   SoccerGuy3 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 118
  • Joined: 18-March 10
  • LocationNorthern California

Posted 12 September 2010 - 02:47 PM

Trying to add the 'add to cart button to the front page. Copied the code from the product_partial to the shop:product_list partial, but I am getting a product not found error. Looking closer I cannot find the form element on the product_partial page that sets the product information for the form... Help!
0

#2 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,633
  • Joined: 31-October 09

Posted 12 September 2010 - 04:02 PM

Hi!

The shop:on_addToCart handler (http://lemonstandapp...n_shop_product/) does not require a product identifier if it is called from the product details page. That is why you didn't find product-speicfic fields in the product_parital partial. If you call this handler from other pages, you need to pass the product_id parameter to the server. You can do it using a hidden field, or with the AJAX request:

<input onclick="return $(this).getForm().sendRequest('shop:on_addToCart',
{
  extraFields: {
     'product_id': <?= $product->id ?>
   }
})" type="button" value="Add to cart"/>


Thank you

#3 User is offline   SoccerGuy3 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 118
  • Joined: 18-March 10
  • LocationNorthern California

Posted 12 September 2010 - 04:28 PM

Here's what I have. After including your code I now get a product not found error.

          <input onclick="return $(this).getForm().sendRequest(
            'shop:on_addToCart', {
                update: {
                  'mini_cart': 'shop:mini_cart', 'introContent': 'shop:product_list'
                  },
                extraFields: {
                   'product_id': <?= $product->id ?>
                   }
           })" type="image" name="add_to_cart" class="add_to_cart" src="<?= root_url('/resources/images/btn_add_to_cart.gif') ?>" alt="Add to cart"/>

0

#4 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,633
  • Joined: 31-October 09

Posted 12 September 2010 - 04:29 PM

Hi!

Please check whether the product_id parameter has value. You can inspect it using FireBug, or just look to the page source code.

Thanks

#5 User is offline   SoccerGuy3 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 118
  • Joined: 18-March 10
  • LocationNorthern California

Posted 12 September 2010 - 04:32 PM

First off, sorry, wrong error message. I should have said 'Undefined Variable: Products' (bouncing between live site and dev, sorry about that).

Yes, the param has value (source listing):
          <p class="center" style="padding: 5px 0 0 0;">
                     <input onclick="return $(this).getForm().sendRequest(
            'shop:on_addToCart', {
                update: {
                  'mini_cart': 'shop:mini_cart', 'introContent': 'shop:product_list'
                  },
                extraFields: {
                   'product_id': 53                   }
           })" type="image" name="add_to_cart" class="add_to_cart" src="/resources/images/btn_add_to_cart.gif" alt="Add to cart"/>
          </p>

0

#6 User is offline   SoccerGuy3 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 118
  • Joined: 18-March 10
  • LocationNorthern California

Posted 12 September 2010 - 04:35 PM

Just noticed that the items are actually adding to the cart correctly, the error must be related to the flash message? Maybe?
0

#7 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,633
  • Joined: 31-October 09

Posted 12 September 2010 - 04:45 PM

Yes, it could be a reason. Your AJAX request updates the introContent element with the shop:product_list partial. But shop:product_list partial requires a product list to render, which is not available when you reload the partial with AJAX. How do you prepare the product list before you render the page? There should be a place in the page code, where you call the render_partial() function fro the shop:product_list partial. This call should pass a number of parameters to the partial - 'products', 'paginate', etc. When you refresh the partial using AJAX you should pass the same parameters into it. You can solve this with different ways, but they depend on the way you prepare the product list.

BTW, the simplest way is to not update the product list at all. Instead, you can create a DIV element above the list and update it with the flash message partial. It is simpler for the server as well. So, the solution is:

1. Create a new DIV element above the list and assign it some ID, for example 'flash'
2. Create a new partial with the <?= flash_message() ?> code inside and assign it some name, for example 'flash_partial'
3. In the AJAX request alter the update parameter:

update: {
     'mini_cart': 'shop:mini_cart', 'flash': 'flash_partial'
}


I hope this helps!

#8 User is offline   SoccerGuy3 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 118
  • Joined: 18-March 10
  • LocationNorthern California

Posted 12 September 2010 - 04:52 PM

Yipee! That worked. I need to spend more time with LemonStand. Dipping my toe once every month or two just isn't cutting it!!
0

#9 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,633
  • Joined: 31-October 09

Posted 12 September 2010 - 05:01 PM

Hehe. True! You registered on March and still haven't made any store on LemonStand! ;-)

#10 User is offline   SoccerGuy3 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 118
  • Joined: 18-March 10
  • LocationNorthern California

Posted 12 September 2010 - 05:06 PM

Actually have two stores 'up' at this point. One is running at http://goldbugcollectibles.com/ and the other is just about to officially launch (probably next week after I clear up a problem with the FedEx Module) at: http://store.renewskinsolutions.com... after that I am going to look at converting this site to LemonStand (too many problems with my custom cart and no real desire to reprogram it!): http://www.wolfgangint.com
0

#11 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,633
  • Joined: 31-October 09

Posted 12 September 2010 - 05:08 PM

Oh, I see. Sorry ;-)

Share this topic:


Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users