Forum

Thread tagged as: Problem, Shop

Incorrect item added to cart (when cart is on the same page as products)

I've been using Perch Shop for the first time and have run into a problem when adding items to the cart.

I have 2 categories of products displayed on the same page. The cart is shown next to them. If I add a product to the cart, then the product appears in the cart. However if I subsequently add a different product to the cart, the first product is duplicated and the different item is not added.

If I revisit the store page from the navigation and add a new item, then that new item is added to the cart. Though adding any further items will duplicate the item just added.

I've recorded a video (1 min) to better demonstrate what is happening: https://www.youtube.com/watch?v=3HGL3Eg2_IA

My templates are:

Cart

<perch:if id="product_count" match="gt" value="0">

  <perch:form id="cart" app="perch_shop">

    <perch:input type="submit" value="Update" hidden="true" aria-hidden="true" />

    <table class="cart">
      <tr>
        <th style="width: 40%;">Item</th>
        <th style="width: 20%;">Quantity</th>
        <th style="width: 20%;">Price</th>
        <th style="width: 20%;">Total</th>
      </tr>
      <perch:cartitems>
        <tr>
          <td>
            <b><perch:cartitem id="title" /></b>
            <button type="submit" class="remove_cart" name="del:<perch:cartitem id="identifier" />" value="1">
                          Remove
                        </button>
          </td>
          <td><perch:input id="qty:<perch:cartitem id="identifier" />" value="<perch:cartitem id="quantity" />" type="number" min="0" /></td>
          <td class="money"><perch:cartitem id="price_without_tax_formatted" /></td>
          <td class="money"><perch:cartitem id="total_without_tax_formatted" /></td>
        </tr>
      </perch:cartitems>

      <perch:if id="total_discounts" match="gt" value="0.00">
        <tr class="total">
          <th colspan="5">
            Discount (<perch:shop id="discount_code" />)
          </th>
          <td class="money">
            <perch:shop id="total_discounts_formatted" />
          </td>
        </tr>
        <tr class="total">
          <th colspan="3">
            Total
          </th>
          <td class="money">
            <perch:shop id="total_items_discounted_formatted" />
          </td>
        </tr>
      <perch:else />
        <tr class="total">
          <th colspan="3">
            Total
          </th>
          <td class="money">
            <perch:shop id="total_items_formatted" />
          </td>
        </tr>
      </perch:if>
      <tr class="total">
        <th colspan="3">
          Tax
        </th>
        <td class="money">
          <perch:shop id="total_tax_formatted" />
        </td>
      </tr>
      <tr class="total">
        <th colspan="3">
          Grand total
        </th>
        <td class="money">
          <perch:shop id="grand_total_formatted" />
        </td>
      </tr>
    </table>

    <perch:input class="update-button" type="submit" value="Update Cart" />

  </perch:form>

  <a class="checkout-button" href="/store/customer-details.php">Checkout</a>

<perch:else />

<p>Your shopping cart is empty.</p>

</perch:if>

Vouchers (first product category)

<perch:before>
</perch:before>

  <div class="voucher">

    <perch:if not-exists="has_variants">
      <perch:form id="add_to_cart" app="perch_shop" action="/store/#cart">
        <perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" />
        <perch:input class="buy-button" type="submit" value="<perch:shop id="price" type="shop_currency_value" />" />
      </perch:form>
    </perch:if>

  </div>

<perch:after>
</perch:after>

Experiences (second product category)

<perch:before>
</perch:before>

  <div class="store-item">

    <perch:if not-exists="has_variants">
      <h4><perch:shop id="title" type="text" /></h4>
      <p><perch:shop id="description" type="textarea" markdown="true" /></p>
      <img src="<perch:shop id="image" type="image" width="800" />" alt="<perch:shop id="title" type="text" />">
      <perch:form id="add_to_cart" app="perch_shop" action="/store/#cart">
        <perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" />
        <perch:input class="buy-button" type="submit" value="<perch:shop id="price" type="shop_currency_value" />" />
      </perch:form>
    </perch:if>

  </div>

<perch:after>
</perch:after>

I'm calling these on the store page with:

<div class="row-fluid mainHolder">
  <section class="span10 mainText">
    <div class="store">
      <h2>Store</h2>
      <p>We have a variety of Gift Vouchers and Food &amp; Drink Experiences available. Treat your family and friends to a memorable experience at The Chequers.</p>
      <div class="store-category">
        <h3>Gift Vouchers</h3>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni doloremque, cumque facere minima voluptatum at quas dolorem.</p>
        <?php
          perch_shop_products([
            'template' => 'vouchers.html',
            'category' => 'products/gift-vouchers/',
            'sort' => 'price',
            'sort-type' => 'numeric',
            'sort-order' => 'ASC',
          ]);
        ?>
      </div>
      <div class="store-category">
        <h3>Food &amp; Drink Experiences</h3>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magni doloremque, cumque facere minima voluptatum at quas dolorem.</p>
        <?php
          perch_shop_products([
            'template' => 'experiences.html',
            'category' => 'products/food-drink-experiences/',
          ]);
        ?>
      </div>
    </div>
  </section>

  <div class="span6">
    <div class="wineClub shopping-cart" id="cart">
      <h2>Shopping Cart</h2>
      <br>
      <?php perch_shop_cart(); ?>
    </div>
    <div class="quality">
      <p>Our ethos is simple</p>
      <p class="ethos">&ldquo;Quality in Every&ndash;<br>thing We Do&rdquo;</p>
    </div>
  </div>
  <img src="/img/wiFi.png" width="60" height="50" alt="Free WiFi Logo" class="wiFi">
</div>

Diagnostics

Perch: 2.8.31
Production mode: Production (100)
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_shop_orders (1.0.6), perch_shop_products (1.0.6), perch_shop (1.0.6), perch_members (1.5)
DB driver: PDO
DB tables: perch2_categories (2), perch2_category_counts (0), perch2_category_sets (1), perch2_content_index (22), perch2_content_items (9), perch2_content_regions (1), perch2_members (1), perch2_members_forms (1), perch2_members_member_tags (0), perch2_members_sessions (1), perch2_members_tags (0), perch2_navigation (0), perch2_navigation_pages (0), perch2_page_templates (0), perch2_pages (1), perch2_resource_log (16), perch2_resource_tags (0), perch2_resources (12), perch2_resources_to_tags (0), perch2_settings (24), perch2_shop_addresses (24), perch2_shop_admin_index (30), perch2_shop_brands (1), perch2_shop_cart (3), perch2_shop_cart_data (108), perch2_shop_cart_items (1), perch2_shop_countries (250), perch2_shop_currencies (152), perch2_shop_customers (3), perch2_shop_emails (1), perch2_shop_index (571), perch2_shop_option_values (2), perch2_shop_options (1), perch2_shop_order_items (28), perch2_shop_order_promotions (0), perch2_shop_order_statuses (9), perch2_shop_orders (21), perch2_shop_orders_meta (1), perch2_shop_product_files (0), perch2_shop_product_option_values (0), perch2_shop_product_options (0), perch2_shop_product_tags (0), perch2_shop_products (13), perch2_shop_promotions (0), perch2_shop_search (11), perch2_shop_shipping_zone_countries (0), perch2_shop_shipping_zones (1), perch2_shop_shippings (1), perch2_shop_tax_exhibits (21), perch2_shop_tax_group_rates (1), perch2_shop_tax_groups (1), perch2_shop_tax_locations (1), perch2_shop_tax_rates (2), perch2_shop_variants (2), perch2_user_passwords (0), perch2_user_privileges (65), perch2_user_role_privileges (16), perch2_user_roles (2), perch2_users (1), perch_contentItems (1), perch_settings (4), perch_users (2)
Users: 1
App runtimes:
<?php
  $apps_list = array(
    'content',
    'categories',
    // 'perch_blog',
    'perch_members',
    'perch_shop',
  );
?>
Editor plug-ins: markitup
H1: a21e769efd4ca6cd09a3e0a6f405351d
L1: b22587663ee7bd7e3809e20f33abd420
F1: 2edba60ed1f613d6dd804feb202456a2
headerColour: #ffffff
content_singlePageEdit: 1
helpURL:
siteURL: /
hideBranding: 0
content_collapseList: 1
lang: en-gb
update_2.8.31: done
latest_version: 2.8.15
on_sale_version: 2.8.31
perch_shop_update: 1.0.6
headerScheme: light
perch_members_login_page: /members/login.php?r={returnURL}
perch_shop_price_tax_mode: inc
perch_shop_site_url: https://
perch_shop_product_url: /shop/products/{slug}
perch_shop_default_currency: 47
perch_shop_reporting_currency: 47
perch_shop_invoice_number_format: Invoice%d
dashboard: 0
hide_pwd_reset: 0
content_hideNonEditableRegions: 0
content_frontend_edit: 0
perch_members_update: 1.4
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_DB_USERNAME: tom
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: thechequerswestoning
PERCH_DB_PREFIX: perch2_
PERCH_TZ: Europe/London
PERCH_EMAIL_FROM: tom@plusone-dg.co.uk
PERCH_EMAIL_FROM_NAME: Tom Bedford
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/tombedford/Dropbox/Plus One Digital/Sites/thechequerswestoning.co.uk/perch
PERCH_CORE: /Users/tombedford/Dropbox/Plus One Digital/Sites/thechequerswestoning.co.uk/perch/core
PERCH_RESFILEPATH: /Users/tombedford/Dropbox/Plus One Digital/Sites/thechequerswestoning.co.uk/perch/resources
PERCH_RESPATH: /perch/resources
PERCH_HTML5: 1
PERCH_RUNWAY:
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_DEBUG:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /Users/tombedford/Dropbox/Plus One Digital/Sites/thechequerswestoning.co.uk/perch/templates
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_PRODUCTION_MODE: 100
PERCH_RWD:
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SESSION_TIMEOUT_MINS: 20
PERCH_SHOP_VERSION: 1.0.6
PERCH_APPS_EDITOR_PLUGIN: markitup
PERCH_APPS_EDITOR_MARKUP_LANGUAGE: textile
HOSTING SETTINGS

PHP: 5.6.10
Zend: 2.6.0
OS: Darwin
SAPI: apache2handler
Safe mode: not detected
MySQL client: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $
MySQL server: 5.5.42
Free disk space: 62.15 GB
Extensions: Core, date, ereg, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dom, hash, fileinfo, filter, ftp, gd, SPL, iconv, intl, json, ldap, mbstring, session, standard, mysqlnd, mysqli, PDO, pdo_mysql, pdo_sqlite, Phar, posix, Reflection, mysql, SimpleXML, soap, sockets, exif, tokenizer, wddx, xml, xmlreader, xmlwriter, xsl, zip, apache2handler, imap, gettext, mcrypt, yaz, pgsql, pdo_pgsql
GD: Yes
ImageMagick: No
PHP max upload size: 32M
PHP max form post size: 32M
PHP memory limit: 128M
Total max uploadable file size: 32M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: Yes
HTTP_HOST: thechequerswestoning.plusone
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_CONNECTION: keep-alive
HTTP_COOKIE: cmsa=1; p_m=; PHPSESSID=e38bfae94e5b6eaaf1cceefe0db6c4fa
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7
HTTP_ACCEPT_LANGUAGE: en-us
HTTP_REFERER: https://thechequerswestoning.plusone/perch/core/settings/diagnostics/
HTTP_ACCEPT_ENCODING: gzip, deflate
PATH: /usr/bin:/bin:/usr/sbin:/sbin
SERVER_SOFTWARE: Apache
SERVER_NAME: thechequerswestoning.plusone
SERVER_ADDR: ::1
SERVER_PORT: 80
REMOTE_ADDR: ::1
DOCUMENT_ROOT: /Users/tombedford/Dropbox/Plus One Digital/Sites/thechequerswestoning.co.uk
SERVER_ADMIN: you@example.com
SCRIPT_FILENAME: /Users/tombedford/Dropbox/Plus One Digital/Sites/thechequerswestoning.co.uk/perch/core/settings/diagnostics/index.php
REMOTE_PORT: 58723
GATEWAY_INTERFACE: CGI/1.1
SERVER_PROTOCOL: HTTP/1.1
REQUEST_METHOD: GET
QUERY_STRING: extended
REQUEST_URI: /perch/core/settings/diagnostics/?extended
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
PHP_SELF: /perch/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1469276057.26
REQUEST_TIME: 1469276057
argc: 1
Tom Bedford

Tom Bedford 3 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I imagine that after the post, the fields are being automatically populated with the matching ID from the post.

You can prevent that with env-autofill="false" on the product ID field.

Thanks Drew that fixed it.

For anyone else with the problem, you need to add it like this in the templates:

 <perch:input env-autofill="false" id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" />