Forum

Thread tagged as: Problem, Runway, Shop

"add-to-cart" not working inside block (?)

Hello,

I am trying to show an "add-to-cart" button inside a block. The behaviour is not correct. Tried moving the "env-autofill="false" as per https://forum.grabaperch.com/forum/05-16-2016-product-without-variant-not-added-to-cart#reply_form but didn't help.

I noticed that the productID is not being printed as value of the generated hidden input.

When I duplicate the "add-to-cart" code outside of the block it prints the value and works as expected.

The not working template

 <perch:block type="cta-panels" label="Panel con atc button">
            <div class="panels__item panels--cta panels--<perch:shop id="panel-color" type="radio" required="true" label="Color" options="Rosa|rosa, Gris|gris" />  ">
                <perch:shop id="text" type="text" label="Text" required="true" title="true" />
                <perch:form id="add_to_cart" app="perch_shop" action="/cart">
                    <perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" env-autofill="false" />
                    <perch:input type="submit" class="cta cta-adc" value="Decidido. Lo compro ya!" />
                </perch:form>
            </div>
          </perch:block>

Diagnostics from the empty card

Debug Message
[15] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC, p.pagePath ASC
Matched page: /cart, so not using routes.
Using master page: /templates/pages/shop/cart.php
[1] SELECT * FROM perch2_members_sessions WHERE sessionID='8cc634264e73fc66dcfbde9d193feff2fea77862' AND sessionHttpFootprint='b57a3b7c43e769ac29216f5c4ad5ba978bcb9b20' AND sessionExpires>'2016-08-28 13:24:04' LIMIT 1
User is logged in
[1] SELECT * FROM perch2_pages WHERE pagePath='/cart' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=48
[1] SELECT * FROM perch2_shop_cart WHERE cartID=48
[36] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
Using sub-template: /templates/shop/products/servicio/listwithtitle.html
Using sub-template: /templates/shop/products/socialproof.html
Using sub-template: /templates/shop/products/servicio/listwithimage.html
[1] SELECT itemID, itemQty FROM perch2_shop_cart_items WHERE cartID=48 AND productID=0
[1] SELECT * FROM perch2_shop_products WHERE productID=0 AND productDeleted IS NULL LIMIT 1
Limiting based on stock.
------------------------------ Calculating cart ------------------------------
[1] SELECT * FROM perch2_shop_cart WHERE cartID=48
[1] SELECT * FROM perch2_shop_cart WHERE cartID=48
[1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
[1] SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
[1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch2_shop_customers WHERE memberID=1
[1] SELECT * FROM perch2_shop_currencies WHERE currencyID=44 LIMIT 1
[1] SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=48
Tax mode: inc
[nil] SELECT * FROM perch2_shop_cart_items WHERE cartID=48 ORDER BY itemID ASC
UPDATE perch2_shop_cart SET cartTotalItems=NULL, cartTotalProducts='0', cartTotalWithTax='0.00', cartTotalWithoutTax='0.00' WHERE cartID='48'
INSERT INTO perch2_shop_cart_data(cartID,productID,cartData) VALUES('48','','{\"product\":\"\"}')
Using template: /templates/pages/attributes/default.html
Using sub-template: /templates/pages/attributes/seo.html
Using template: /templates/members/login/login_form.html
[3] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
[1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/cart' LIMIT 1
[1] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-010', '000') ORDER BY pageTreePosition DESC
[3] Using template: /templates/navigation/item.html
[2] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/cart' OR regionPage='*' ORDER BY regionPage DESC
Using template: /templates/shop/cart/cart.html

Could you please help?

Proko Mountrichas

Proko Mountrichas 3 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Can you post your Diagnostics Report please, you'll find this under Settings in the Perch Control Panel and we need this with each post to the forum - thanks!

Sure, there you are

Perch Runway: 2.8.31, PHP: 5.6.18, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_blog (5.0), perch_shop_orders (1.0.8), perch_shop_products (1.0.8), perch_shop (1.0.8), perch_members (1.5), perch_mailchimp (3.0.1)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', 'perch_members', 'perch_shop', 'perch_mailchimp', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/proko/Sites/annaand.co/perch
PERCH_CORE: /Users/proko/Sites/annaand.co/perch/core
PERCH_RESFILEPATH: /Users/proko/Sites/annaand.co/perch/resources
Image manipulation: GD
PHP limits: Max upload 8M, Max POST 128M, Memory: 256M, Total max file upload: 8M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
HTTP_HOST: annaandco.dev
DOCUMENT_ROOT: /Users/proko/Sites/annaand.co
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Drew McLellan

Drew McLellan 2638 points
Perch Support

Take a look at the section "Accessing content outside the blocks" in the docs - does it help?

https://docs.grabaperch.com/docs/templates/blocks/

Yes! Thanks Drew.

I had to use the scope-parent="true" attribute on the perch:blocks tag and the "parent" prefix but only for the productID as follows

<perch:form id="add_to_cart" app="perch_shop" action="/cart">
    <perch:input id="product" type="hidden" value="<perch:shop id="parent.productID" type="hidden" />" env-autofill="false" />
    <perch:input type="submit" class="cta cta-adc" value="Decidido. Lo compro ya!" />
</perch:form>