Perch Shop customer addresses not being saved
Hi,
I'm having a problem setting up a Perch Shop where customer addresses aren't being saved on submission of the registration form. Customer details are being saved in perch2_members and perch2_shop_customers but perch2_shop_addresses remains empty.
Here is my checkout.php:
<?php
if (!perch_member_logged_in()) {
PerchSystem::redirect('/fireworks/register.php');
}
if (perch_shop_cart_has_property('terms_agreed')) {
perch_shop_checkout('manual', [
'return_url' => '/fireworks/result.php',
'cancel_url' => '/fireworks',
]);
}
// Show the cart with a non-interactive template
perch_shop_cart([
'template'=>'cart/cart_static.html'
]);
// Show the order addresses
perch_shop_order_addresses();
// Display the form with the T&Cs checkbox
perch_shop_form('checkout/confirm.html');
?>
Here is register.php:
<?php
if (perch_member_logged_in()) {
PerchSystem::redirect('/fireworks/checkout.php');
}
PerchSystem::set_var('shipping_weight', perch_shop_get_shipping_weight());
perch_shop_registration_form();
?>
I've repeatedly tested with a fresh cart and then a fresh checkout with new customer details each time. This is what happens:
1) When first arriving in the checkout the registration form is presented. 2) Once I fill in the registration form I'm taken to the checkout which shows my static cart and T&C's confirmation field. But no addresses are shown. Here is the debug message at that time (no errors shown):
SELECT * FROM perch2_members_sessions WHERE sessionID='eab94f2a7a22dc46dbd20f6d088f1e9c5a48c31f' AND sessionHttpFootprint='b57a3b7c43e769ac29216f5c4ad5ba978bcb9b20' AND sessionExpires>'2016-09-12 06:05:19' LIMIT 1
User is logged in
[1] SELECT * FROM perch2_pages WHERE pagePath='/fireworks/checkout.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=11
[1] SELECT * FROM perch2_shop_cart WHERE cartID=11
[1] SELECT cartProperties FROM perch2_shop_cart WHERE cartID=11
Using cart from cache.
[34] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] Using template: /templates/shop/cart/cart_static.html
[1] SELECT billingAddress, shippingAddress FROM perch2_shop_cart WHERE billingAddress IS NOT NULL AND cartID=11
Using template: /templates/shop/checkout/confirm.html
[1] SELECT setID FROM perch2_category_sets WHERE setSlug='fireworks' LIMIT 1
[6] SELECT main.* FROM perch2_categories main WHERE 1=1 AND (catSlug!='best-sellers') AND setID=4 ORDER BY catTreePosition ASC
[6] Using template: /templates/categories/list.html
[1] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='_category' AND idx.indexValue LIKE 'fireworks/best-sellers%' OR idx.indexKey='_category' AND idx.indexValue='fireworks/best-sellers'))
[4] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='status' AND idx.indexValue='1')) GROUP BY idx.itemID HAVING COUNT(idx.itemID)=1
[4] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='parentID' AND idx.indexValue='')) GROUP BY idx.itemID HAVING COUNT(idx.itemID)=1
[1] SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch2_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='title' AND idx.itemID IN ('4') AND idx.itemID IN ('1', '2', '3', '4') AND idx.itemID IN ('1', '2', '3', '4') WHERE 1=1 AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (productDeleted IS NULL) GROUP BY itemID, sortval ORDER BY sortval ASC
[1] Using template: /templates/shop/products/link_list.html
[95] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/fireworks/checkout.php' OR regionPage='*' ORDER BY regionPage DESC
3) I then check the T&Cs checkbox and press the "pay now" button. The page refreshes, the terms_agreed checkbox is now checked but nothing else has changed. Here is how the debug message now looks:
[1] SELECT * FROM perch2_members_sessions WHERE sessionID='eab94f2a7a22dc46dbd20f6d088f1e9c5a48c31f' AND sessionHttpFootprint='b57a3b7c43e769ac29216f5c4ad5ba978bcb9b20' AND sessionExpires>'2016-09-12 06:10:04' LIMIT 1
User is logged in
[1] SELECT * FROM perch2_pages WHERE pagePath='/fireworks/checkout.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=11
[1] SELECT * FROM perch2_shop_cart WHERE cartID=11
[34] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] SELECT cartProperties FROM perch2_shop_cart WHERE cartID=11
UPDATE perch2_shop_cart SET cartProperties='{\"terms_agreed\":\"true\"}' WHERE cartID='11'
[1] SELECT cartProperties FROM perch2_shop_cart WHERE cartID=11
Checking out with manual
Member ID: 5
[1] SELECT * FROM perch2_shop_customers WHERE memberID=5
[1] SELECT billingAddress, shippingAddress FROM perch2_shop_cart WHERE billingAddress IS NOT NULL AND cartID=11
[1] SELECT * FROM perch2_shop_addresses WHERE customerID='5' AND orderID IS NULL AND addressSlug='default'
no address
INSERT INTO perch2_shop_addresses(addressDynamicFields,addressTitle,addressSlug,addressCreated) VALUES('{\"first_name\":\"Laura\",\"last_name\":\"Spurling\",\"address_1\":false,\"address_2\":false,\"postcode\":false,\"country\":false,\"company\":false,\"city\":false,\"customer\":\"5\",\"phone\":false,\"county\":false,\"instructions\":false}','default','default','2016-09-12 05:10:04')
Invalid query: SQLSTATE[HY000]: General error: 1364 Field 'countryID' doesn't have a default value
[1] SELECT * FROM perch2_shop_addresses WHERE customerID='5' AND orderID IS NULL AND addressSlug='shipping'
no address
INSERT INTO perch2_shop_addresses(addressDynamicFields,addressTitle,addressSlug,addressCreated) VALUES('{\"first_name\":\"Laura\",\"last_name\":\"Spurling\",\"address_1\":false,\"address_2\":false,\"postcode\":false,\"country\":false,\"company\":false,\"city\":false,\"customer\":\"5\",\"phone\":false,\"county\":false,\"instructions\":false}','shipping','shipping','2016-09-12 05:10:04')
Invalid query: SQLSTATE[HY000]: General error: 1364 Field 'countryID' doesn't have a default value
Customer or Address or Shipping missing
Using cart from cache.
[1] Using template: /templates/shop/cart/cart_static.html
[1] SELECT billingAddress, shippingAddress FROM perch2_shop_cart WHERE billingAddress IS NOT NULL AND cartID=11
Using template: /templates/shop/checkout/confirm.html
[1] SELECT setID FROM perch2_category_sets WHERE setSlug='fireworks' LIMIT 1
[6] SELECT main.* FROM perch2_categories main WHERE 1=1 AND (catSlug!='best-sellers') AND setID=4 ORDER BY catTreePosition ASC
[6] Using template: /templates/categories/list.html
[1] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='_category' AND idx.indexValue LIKE 'fireworks/best-sellers%' OR idx.indexKey='_category' AND idx.indexValue='fireworks/best-sellers'))
[4] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='status' AND idx.indexValue='1')) GROUP BY idx.itemID HAVING COUNT(idx.itemID)=1
[4] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='parentID' AND idx.indexValue='')) GROUP BY idx.itemID HAVING COUNT(idx.itemID)=1
[1] SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch2_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='title' AND idx.itemID IN ('4') AND idx.itemID IN ('1', '2', '3', '4') AND idx.itemID IN ('1', '2', '3', '4') WHERE 1=1 AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (productDeleted IS NULL) GROUP BY itemID, sortval ORDER BY sortval ASC
[1] Using template: /templates/shop/products/link_list.html
[95] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/fireworks/checkout.php' OR regionPage='*' ORDER BY regionPage DESC
The errors that catches my attention is: Invalid query: SQLSTATE[HY000]: General error: 1364 Field 'countryID' doesn't have a default value
Customer or Address or Shipping missing
Checking my DB the customer/member data made it's way fine into perch2_members
, perch2_member_sessions
, perch2_shop_customers
but nothing appears in perch2_shop_addresses
After being stuck on this for quite a while I attempted a reinstallation but got the exact same error in the end.
Here's my diagnostics report:
Perch: 2.8.31, PHP: 7.0.5-2+deb.sury.org~trusty+1, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: fd3bfdab644600c96b25beaf69d021447b7b4ec5 $, with PDO
Server OS: Linux, fpm-fcgi
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_blog (5.0), perch_forms (1.8.3), perch_shop_orders (1.0.8), perch_shop_products (1.0.8), perch_shop (1.0.8), perch_members (1.5)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_blog', 'perch_members', 'perch_shop', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /home/vagrant/Code/lockstock/perch
PERCH_CORE: /home/vagrant/Code/lockstock/perch/core
PERCH_RESFILEPATH: /home/vagrant/Code/lockstock/perch/resources
Image manipulation: GD
PHP limits: Max upload 100M, Max POST 100M, Memory: 512M, Total max file upload: 100M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
HTTP_HOST: lockstock.dev
DOCUMENT_ROOT: /home/vagrant/Code/lockstock
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
There are no errors showing in my PHP error log.
One more thing, here's my customer_create.html template:
<perch:form id="register" method="post" app="perch_shop" type="shop" data-address-duplicate="true">
<fieldset>
<legend>About you</legend>
<div class="cols">
<div class="col-a">
<perch:label for="first_name">First name</perch:label>
<perch:input type="text" id="first_name" required="true" label="First name" />
<perch:error for="first_name" type="required">Please add your name</perch:error>
</div>
<div class="col-b">
<perch:label for="last_name">Last name</perch:label>
<perch:input type="text" id="last_name" required="true" label="Last name" />
<perch:error for="last_name" type="required">Please add your name</perch:error>
</div>
</div>
<div class="col-a">
<perch:label for="email">Email</perch:label>
<perch:input type="email" id="email" required="true" placeholder="you@company.com" helper="PerchMembers_Members::check_email" />
<perch:error for="email" type="required">Please add your email address</perch:error>
<perch:error for="email" type="helper">That email address is already in use</perch:error>
</div>
<perch:input type="hidden" id="password" value="__auto__" />
<div class="col-b">
<perch:label for="telephone">Telephone</perch:label>
<perch:input type="text" id="telephone" label="Telephone" />
</div>
<div class="col-a">
<perch:label for="address_1">Address 1</perch:label>
<perch:input type="text" id="address_1" required="true" label="Address 1" />
<perch:error for="address_1" type="required">Please add the first line of your address</perch:error>
</div>
<div class="col-b">
<perch:label for="address_2">Address 2</perch:label>
<perch:input type="text" id="address_2" label="Address 2" />
</div>
<div class="col-a">
<perch:label for="city">City</perch:label>
<perch:input type="text" id="city" label="City" />
</div>
<div class="col-b">
<perch:label for="county">County</perch:label>
<perch:input type="text" id="county" label="County" />
</div>
<div class="col-a">
<perch:label for="postcode">Postal code</perch:label>
<perch:input type="text" id="postcode" label="Postal code" />
</div>
<div class="col-b">
<perch:label for="country">Country</perch:label>
<perch:input type="select" options="<perch:shop id="country_list" />" value="236" id="country" label="Country" />
</div>
</fieldset>
<perch:if id="shipping_weight" match="gt" value="0.00">
<fieldset>
<legend>Shipping address</legend>
<div class="col-a">
<perch:label for="shipping_first_name">First name</perch:label>
<perch:input type="text" id="shipping_first_name" label="First name" />
<perch:error for="shipping_first_name" type="required">Please add your name</perch:error>
</div>
<div class="col-b">
<perch:label for="shipping_last_name">Last name</perch:label>
<perch:input type="text" id="shipping_last_name" label="Last name" />
<perch:error for="shipping_last_name" type="required">Please add your name</perch:error>
</div>
<div>
<perch:label for="company">Company</perch:label>
<perch:input type="text" id="shipping_company" label="Company" />
</div>
<div class="col-a">
<perch:label for="shipping_address_1">Address 1</perch:label>
<perch:input type="text" id="shipping_address_1" label="Address 1" />
<perch:error for="shipping_address_1" type="required">Please add the first line of your address</perch:error>
</div>
<div class="col-b">
<perch:label for="shipping_address_2">Address 2</perch:label>
<perch:input type="text" id="shipping_address_2" label="Address 2" />
</div>
<div class="col-a">
<perch:label for="shipping_city">City</perch:label>
<perch:input type="text" id="shipping_city" label="City" />
</div>
<div class="col-b">
<perch:label for="shipping_county">State or County</perch:label>
<perch:input type="text" id="shipping_county" label="County" />
</div>
<div class="col-a">
<perch:label for="shipping_postcode">Postal code</perch:label>
<perch:input type="text" id="shipping_postcode" label="Postal code" />
</div>
<div class="col-b">
<perch:label for="shipping_country">Country</perch:label>
<perch:input type="select" options="<perch:shop id="country_list" />" value="236" id="shipping_country" label="Country" />
</div>
</fieldset>
</perch:if>
<div>
<perch:input type="submit" value="Continue" class="btn" />
</div>
<perch:success>
<p>Thanks!</p>
</perch:success>
</perch:form>
Are the countries displaying correctly on the registration form?
Yes. Populating fine for both country fields.
Sorry to hassle - but does anybody have any further ideas of where I could look for the problem? Totally stuck on this.
I'm looking into it as a priority.
Thank you
Sorry to nag... but I'm just wondering if there's perhaps a temporary workaround to this that I can use while you look into the root cause of the problem?
Do you have a step in your checkout process where an address is selected?
No. First step is checkout.php (template in original post)... which detects if the user is logged in. If not, they are redirected to register.php (template for that in my original post). Submission of that registration form then loads the checkout after the redirect code but perch_shop_order_addresses(); has no output.
The problem is nothing gets saved in
perch2_shop_addresses
so I wouldn't be able to offer a choice of addresses if I wanted to.Am I following you correctly?
Ok, I'll try again to reproduce it.
Hi Drew. Is there anything I can do to help you with reproducing/diagnosing the issue? I'm very keen to get this sorted.
Not yet - but I'll let you know if that's the case.
Hi,
I believe I have seen this, but only on my 'localhost' machine. I'm still in the early stages of playing with the Shop but
is returning just the two <h4> headings for billing and shipping address without any details or radio buttons on the default template. The user was created with the shop user creation form and both addresses set. The other difference between the localhost dev machine and the staging environment where the user addresses were stored is that the redirection to paypal at the checkout didn't work (I didn't have PHP cUrl installed).
Could you run this query and let me know what it outputs?
Here is my output for DESCRIBE perch2_shop_addresses;
Field Type Null Key Default Extra addressID int(10) unsigned NO PRI NULL auto_increment
addressTitle char(128) YES Default
addressSlug char(128) YES default
addressFirstName char(128) NO
addressLastName char(128) NO
addressCompany char(128) NO
addressLine1 char(255) NO
addressDynamicFields mediumtext YES NULL
addressCreated datetime NO 20150101 00:00:00
addressUpdated datetime NO 20150101 00:00:00
addressDeleted datetime YES NULL
customerID int(10) unsigned NO MUL 0
countryID int(10) NO NULL
regionID int(10) YES NULL
orderID int(10) unsigned YES NULL
Mine too, in case it helps:
Thanks Joseph. Can you run this and try the problem again?
Hi Drew,
Sorry to jump on the thread but I was seeing the same errors. I ran the ALTER table query above and that seems to have solved my issue (the countryID error message has gone and I was successfully redirected to my success url after a Stripe checkout)
Works for me too
The good news: that worked, in that it fixed the issue with creating customers.
The bad news: I have a new (possibly related?) problem now. Although customer details are created fine (and displayed fine in the checkout), I am getting redirected to a blank results page (here's the template:)
Here's the debug output on the cart page:
And here's the debug output when looking at the "manage orders" page in the Perch admin:
Can you go to the Shop app, and then Statuses and let me know what you see?
There should be a list of about 9 statuses from Created to Refunded.