Forum

Thread tagged as: Problem, Error, Shop

perch_shop_customer_edit_form() Creating Multiple Addresses

I've come across an issue where calling perch_shop_customer_edit_form() is creating an address each time it is called.

I've created a reduced test case:

<?php perch_layout('header'); ?>

<?php if (perch_member_logged_in()) : ?>
<?php perch_shop_customer_edit_form(); ?>
<?php endif; ?>

<?php perch_layout('footer'); ?>

But on each page refresh, it created a new address for the logged in customer. Even if I remove the address fields from customer_update.html it still creates a new address in the database and therefore multiple addresses are listed using perch_shop_customer_addresses().

As a workaround, is there another edit form for just editing the customer name, email, and password. Then I could use that in combination with perch_shop_edit_address_form instead?

Perch Runway: 3.0.8
Production mode: Production (100)
Installed apps: content (3.0.8), assets (3.0.8), categories (3.0.8), perch_forms (1.9.1), perch_shop_orders (1.2.5), perch_shop_products (1.2.5), perch_shop (1.2.5), perch_members (1.6.2)
DB driver: PDO
DB tables: perch2_backup_plans (1), perch2_backup_resources (0), perch2_backup_runs (20), perch2_categories (7), perch2_category_counts (0), perch2_category_sets (1), perch2_collection_index (0), perch2_collection_items (0), perch2_collection_revisions (0), perch2_collections (0), perch2_content_index (91), perch2_content_items (35), perch2_content_locks (0), perch2_content_regions (7), perch2_forms (2), perch2_forms_responses (2), perch2_members (1), perch2_members_forms (1), perch2_members_member_tags (0), perch2_members_sessions (2), perch2_members_tags (0), perch2_menu_items (15), perch2_navigation (0), perch2_navigation_pages (0), perch2_page_routes (6), perch2_page_templates (18), perch2_pages (17), perch2_resource_log (442), perch2_resource_tags (0), perch2_resources (507), perch2_resources_to_tags (0), perch2_settings (32), perch2_shop_addresses (147), perch2_shop_admin_index (64), perch2_shop_brands (1), perch2_shop_cart (672), perch2_shop_cart_data (147), perch2_shop_cart_items (43), perch2_shop_countries (250), perch2_shop_currencies (152), perch2_shop_customers (8), perch2_shop_emails (2), perch2_shop_index (6141), perch2_shop_option_values (5), perch2_shop_options (2), perch2_shop_order_items (69), perch2_shop_order_promotions (0), perch2_shop_order_statuses (9), perch2_shop_orders (35), perch2_shop_orders_meta (1), perch2_shop_product_files (0), perch2_shop_product_option_values (5), perch2_shop_product_options (2), perch2_shop_product_tags (0), perch2_shop_products (118), perch2_shop_promotions (0), perch2_shop_sales (0), perch2_shop_search (104), perch2_shop_shipping_zone_countries (1), perch2_shop_shipping_zones (1), perch2_shop_shippings (2), perch2_shop_tax_exhibits (113), perch2_shop_tax_group_rates (1), perch2_shop_tax_groups (1), perch2_shop_tax_locations (1), perch2_shop_tax_rates (1), perch2_shop_variants (31), perch2_user_passwords (1), perch2_user_privileges (72), perch2_user_role_privileges (24), perch2_user_roles (2), perch2_users (3)
Users: 3
App runtimes:
<?php
  $apps_list = [
        'perch_forms',
        'perch_members',
        'perch_shop',
    ];
Scheduled tasks for Backup: plan_1 (10 mins)
Editor plug-ins: config-min.js, config.js
H1: c2c0d4c862fcff0f53f3e20e7722906e
L1: f899c27a816b3d0ca13740231ae2f081
F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
content_singlePageEdit: 1
helpURL:
hideBranding: 1
content_collapseList: 1
lang: en-gb
update_2.8.34: done
headerColour: #000000
headerScheme: dark
update_runway_2.8.34: done
perch_shop_update: 1.2.5
perch_members_login_page: /members/login.php?r={returnURL}
perch_shop_price_tax_mode: inc
perch_shop_trade_price_tax_mode: inc
perch_shop_product_url: /products/{slug}
perch_shop_default_currency: 47
perch_shop_reporting_currency: 47
perch_shop_invoice_number_format: #1DW%d
dashboard: 0
hide_pwd_reset: 0
content_hideNonEditableRegions: 0
content_frontend_edit: 0
latest_version:
on_sale_version: 3.0.10
update_runway_3.0.8: done
perch_members_update: 1.4
keyboardShortcuts: 0
siteOffline: 0
content_skip_region_list: 1
siteURL: /
perch_shop_site_url: https://1dw.creativemonster.co.uk
logoPath: /admin/resources/logo-2.svg
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_SITEPATH: /Users/Toby/Sites/1dw
PERCH_SCHEDULE_SECRET: eXybvCZ4wDfAzr9F
PERCH_DB_USERNAME: root
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: perch_1dw_local
PERCH_DB_PREFIX: perch2_
PERCH_EMAIL_FROM: admin@1daywow.com
PERCH_EMAIL_FROM_NAME: 1 Day Wow
PERCH_LOGINPATH: /admin
PERCH_PATH: /Users/Toby/Sites/1-day-wow/admin
PERCH_CORE: /Users/Toby/Sites/1-day-wow/admin/core
PERCH_RESFILEPATH: /Users/Toby/Sites/1-day-wow/admin/resources
PERCH_RESPATH: /admin/resources
PERCH_HTML5: 1
PERCH_TZ: europe/london
PERCH_DEBUG:
PERCH_CUSTOM_EDITOR_CONFIGS: 1
PERCH_RUNWAY: 1
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_ASSET_VERSION: 5163d57ff611b3cf853b
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /Users/Toby/Sites/1-day-wow/admin/templates
PERCH_TEMPLATE_FILTERS:
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_PRODUCTION_MODE: 100
PERCH_XHTML_MARKUP:
PERCH_RWD: 1
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_DEFAULT_BUCKET: default
PERCH_TRANSLATION_ASSIST:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_PRIV_ASSIST:
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SHOP_VERSION: 1.2.5
PERCH_APPS_EDITOR_PLUGIN: markitup
PERCH_APPS_EDITOR_MARKUP_LANGUAGE: markdown
Hosting settings

PHP: 7.1.6
Zend: 3.1.0
OS: Darwin
SAPI: cgi-fcgi
Safe mode: not detected
MySQL client: mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $
MySQL server: 5.6.35
Free disk space: 37.22 GB
Extensions: Core, date, 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, PDO, pdo_mysql, pdo_sqlite, Phar, posix, readline, Reflection, mysqli, SimpleXML, soap, sockets, exif, tokenizer, wddx, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, cgi-fcgi, imap, gettext, mcrypt, pgsql, pdo_pgsql, igbinary, memcached
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
PHP_FCGI_CHILDREN: 4
PWD: /Applications/MAMP/fcgi-bin
PHP_FCGI_MAX_REQUESTS: 200
__CF_USER_TEXT_ENCODING: 0x1F5:0x0:0x2
ORIG_SCRIPT_NAME: /fcgi-bin/php7.1.6.fcgi
ORIG_PATH_TRANSLATED: /Users/Toby/Sites/1-day-wow/admin/core/settings/diagnostics/index.php
ORIG_PATH_INFO: /admin/core/settings/diagnostics/index.php
ORIG_SCRIPT_FILENAME: /Applications/MAMP/fcgi-bin/php7.1.6.fcgi
SCRIPT_NAME: /admin/core/settings/diagnostics/index.php
REQUEST_URI: /admin/core/settings/diagnostics/?extended
QUERY_STRING: extended
REQUEST_METHOD: GET
SERVER_PROTOCOL: HTTP/1.1
GATEWAY_INTERFACE: CGI/1.1
REDIRECT_URL: /admin/core/settings/diagnostics/index.php
REDIRECT_QUERY_STRING: extended
REMOTE_PORT: 65353
SCRIPT_FILENAME: /Users/Toby/Sites/1-day-wow/admin/core/settings/diagnostics/index.php
SERVER_ADMIN: you@example.com
DOCUMENT_ROOT: /Users/Toby/Sites/1-day-wow
REMOTE_ADDR: ::1
SERVER_PORT: 8888
SERVER_ADDR: ::1
SERVER_NAME: 1dw.loc
SERVER_SOFTWARE: Apache
PATH: /usr/bin:/bin:/usr/sbin:/sbin
HTTP_COOKIE: cmsa=1; p_m=465042ec8efd08c4a92f290d6ed6b3fac00d3eac; PHPSESSID=07f69dfc58ba7898848d36672fb308cf
HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.8
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_REFERER: https://1dw.loc:8888/admin/core/settings/diagnostics/add-ons/
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
HTTP_UPGRADE_INSECURE_REQUESTS: 1
HTTP_CONNECTION: keep-alive
HTTP_HOST: 1dw.loc:8888
REDIRECT_STATUS: 200
REDIRECT_HANDLER: php-fastcgi
FCGI_ROLE: RESPONDER
PHP_SELF: /admin/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1506965194.39
REQUEST_TIME: 1506965194
argc: 1
Toby Martin

Toby Martin 1 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you tried on an up to date version?

Yes, I knew you going to ask that so I tried last night. After further testing, it appears to be happening if you strip the address fields out of customer_create.html

Are addresses required to sign-up as a customer? I would like to only prompt for an address if/when they get to the checkout.

Drew McLellan

Drew McLellan 2638 points
Perch Support

They're not required to sign a customer up. They maybe expected when editing a customer though.

So therefore, there is no point in letting a customer sign-up without an address because as soon as they need to edit their account, they'd need to add an address?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You could add a hidden field for the first address field - I think that should be all you need to do.

Okay, but what about when they need to add an address?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It works in that case doesn't it?

Ah maybe I misunderstood what you meant my 'hidden field for the first address field' then.

Did you mean pre-fill the address but have it as a hidden input field? If so, then what about when they need view their addresses?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which is it? What one do you need?

I don't understand the question.

I would like a user to be able to sign-up, but not forced to enter an address until they want to make a purchase, or choose to add an address to their account.

Drew McLellan

Drew McLellan 2638 points
Perch Support

As long as you know their location for tax, that should be absolutely fine.

But I still have the original issue.

If they don't enter an address on sign up, and they go to their edit account screen using perch_shop_customer_edit_form(), an empty default and shipping address is created. Then on subsequent page load's another address gets added each time.