Open bobbingwide opened 1 year ago
select p.post_title, m.post_id, m.meta_key, m.meta_value from vgcwp_postmeta
m , vgcwp_posts
p where m.post_id = p.ID
and p.post_type = 'brands'
and meta_key in ( 'postcodes_excluded', 'delivery_cost', 'delivery_cost_band_1', 'delivery_cost_band_2', 'delivery_cost_band_3', 'delivery_cost_band_4', 'installation_cost_override', 'offer_base_options' )
order by meta_key, post_title;
Here's a summary of the Brands data, produced in Excel from the output of a query similar to above.
Notes from our meeting on Wed am14th June.
Passmores and Regency have delivery charges depending on the band assigned to the delivery post code
If the post code is not in one of the 4 bands, then delivery is not supported.
I've investigated what happens if the logic to display the options is displayed without regard to the post code. I did this without changing any of the logic that checks the post code; I just moved it to earlier in the template.
This is because the View Options button submits a different request ( form action=#options_area method=post ) rather than the form submitted for Add to cart ( form method=post id=select-addons. )
It might be possible to change the code to say "Please confirm your post code before selecting your options", but this might not be a better experience for the user compared to the current.
One alternative is to
Note: With the current logic, when the post code is not supported, the Current Cart is displayed but the Add to cart button isn't disabled.
Pedantic note: It's not really the current cart, it's the current selection for this viewing of the product.
The current cart is displayed when viewing /cart/
Re: post code bands
Band | Codes |
---|---|
1 | GU5 GU7 GU8 GU26 GU27 GU28 GU29 GU30 GU31 GU32 GU33 GU35 |
2 | GU1 GU2 GU3 GU4 GU7 GU9 GU10 GU11 GU12 GU14 GU34 GU51 GU52 PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO14 PO15 PO16 PO17 PO18 PO19 PO20 RH14 RH20 |
3 | GU6 GU15 GU16 GU17 GU18 GU19 GU20 GU21 GU22 GU23 GU24 GU46 GU47 PO11 PO12 PO13 PO21 PO22 RG21 RG22 RG23 RG24 RG25 RG26 RG27 RG28 RG29 SO14 SO15 SO16 SO17 SO18 SO19 SO20 SO21 SO22 SO23 SO24 SO30 SO31 SO32 SO50 SO51 SO52 SO53 SP9 SP10 SP11 |
4 | PO30 PO31 PO32 PO33 PO34 PO35 PO36 PO37 PO38 PO39 PO40 PO41 |
GU7 is in both bands 1 and 2.
The current logic treats it as being in band 2. See define_addons_by_postcode::checkPostcode()
Is this correct?
GU25 is missing. Could this possibly go in Band 3 or 4?
Are there any others?
Passmores and Regency have delivery charges depending on the band assigned to the delivery post code
I've prototyped some JavaScript that demonstrates hiding and unhiding of HTML based on the delivery band determined from the postcode.
For the JavaScript to work....
The form is similar to before. It needs the id="postcode"
attribute on the post code entry field
and class="submit_pc"
on the button for the JavaScript to work.
<form method="post">
<input type="text" name="postcode" placeholder="Enter here..." maxlength="4" value="" id="postcode">
<input type="submit" value="VIEW OPTIONS" class="submit_pc" >
</form>
The HTML for the different options is wrapped within a div with id="delivery_wrapper"
<div class="delivery delivery_band_not_set" id="delivery_wrapper">
<div class="delivery_band_not_set">Delivery band not set</div>
<div class="delivery_band_0">Delivery to elsewhere</div>
<div class="delivery_band_1">Delivery to band 1</div>
<div class="delivery_band_2">Delivery to band 2</div>
<div class="delivery_band_3">Delivery to band 3</div>
<div class="delivery_excluded">Delivery excluded</div>
<div class="removal delivery_band_1 delivery_band_2 delivery_band_3">Removal options - bands 1,2,3</div>
</div>
The CSS hides each nested div until the parent div has a class that matches one of the child div's classes.
<style>
#delivery_wrapper div { display:none;}
#delivery_wrapper.delivery_band_not_set .delivery_band_not_set { display: block; }
#delivery_wrapper.delivery_band_0 .delivery_band_0 { display: block; }
#delivery_wrapper.delivery_band_1 .delivery_band_1 { display: block; }
#delivery_wrapper.delivery_band_2 .delivery_band_2 { display: block; }
#delivery_wrapper.delivery_band_3 .delivery_band_3 { display: block; }
#delivery_wrapper.delivery_band_4 .delivery_band_4 { display: block; }
#delivery_wrapper.delivery_excluded .delivery_excluded { display: block; }
</style>
The JavaScript refers to some constants that will be enqueued by the server code.
<script type='text/javascript' id='vgccodes-js-extra'>
var vgccodes = {
"postcodes": [['GU1'], ['GU2'], ['PO9'], ['PO30']],
"excluded": ['AB10']
};
</script>
Attaches an event listener to the submit_pc
input button.
This calls setbands()
to change the class name based on the post code entered.
And it prevents the form from being submitted.
<script>
document.querySelector('input.submit_pc').addEventListener('click', function () {
setbands();
event.preventDefault();
});
The class name being set is returned in band
. It defaults to delivery_band_not_set
.
/**
* Sets the delivery band code given the post code.
*
*/
function setbands() {
var postcode = document.getElementById('postcode').value;
postcode = postcode.toUpperCase();
postcode = postcode.trim();
if ( postcode) {
var band = get_delivery_band_code(postcode);
} else {
var band = 'delivery_band_not_set';
}
console.log( band);
setClasses( band );
}
The get_delivery_band_code()
looks up the post code in the exluded list first, then in the 4 different post code bands.
function get_delivery_band_code( postcode ) {
var bandcode = 'delivery_excluded';
if (vgccodes.excluded.includes(postcode))
return bandcode;
//let index = 0;
bandcode = 'delivery_band_0';
for ( let index = 0; index < vgccodes.postcodes.length; index++) {
let bandcodes = vgccodes.postcodes[ index];
console.log( bandcodes);
if (bandcodes.includes(postcode)) {
bandcode = 'delivery_band_' + (index + 1);
}
}
return bandcode;
}
The new class is applied to the outer div with id delivery_wrapper
function setClasses( band ) {
var delivery_wrapper = document.getElementById( 'delivery_wrapper');
// Unset current classes
// Add new band
console.log( delivery_wrapper.classList);
delivery_wrapper.classList.remove('delivery_band_not_set' );
delivery_wrapper.classList.remove('delivery_band_0' );
delivery_wrapper.classList.remove('delivery_band_1' );
delivery_wrapper.classList.remove('delivery_band_2' );
delivery_wrapper.classList.remove('delivery_band_3' );
delivery_wrapper.classList.remove('delivery_band_4' );
delivery_wrapper.classList.remove('delivery_excluded' );
console.log( delivery_wrapper.classList);
delivery_wrapper.classList.add( band );
console.log( delivery_wrapper.classList);
//delivery_wrapper.setAttribute( 'class', 'delivery_wrapper.classList);
}
</script>
The above prototyped logic needs to be converted into:
My first pass attempt at implementing the solution uncovered a few glitches, leading me to pose these questions...
Regarding Delivery Options, I notice that the current logic requires the checkbox for Add Delivery to be checked. It's configured as addon-select-required
When this is set the current JavaScript logic automatically adds the Add Delivery item to the Current Cart.
Q: Where delivery charges are applicable, how important is it for customers to have to choose to have the product delivered?
Q: And should there be sanity check at checkout that the delivery option chosen matches their delivery address?
Q: Or even that the product is deliverable to their postcode?
Section displayed when no post code has been entered.
Free delivery for this brand to GU33
£60 delivery for Passmores to band 1. Note: Having added a Delivery cost of £222 to Passmores ( see https://github.com/bobbingwide/vgc/issues/59 ) then for any post code that's not listed in any band and when not excluded this is the price for Band 0
Postcode excluded
Q: Where delivery charges are applicable, how important is it for customers to have to choose to have the product delivered?
When an option has the class addon-select-required
the current JavaScript automatically adds the first item in the list of options to the current cart item. This is performed on initial page load.
When the user has entered their post code the delivery price may change...
but this is not reflected in the current cart item.
If it's mandatory that the customer has to choose the Delivery option then I'll need to add extra code to update the current cart when the post code's been entered.
If not, then, we can switch the addon-select-required
class off and then the user can choose to have the product delivered or not.
Q: And should there be sanity check at checkout that the delivery option chosen matches their delivery address? Q: Or even that the product is deliverable to their postcode?
The current system allows products to be added to the cart both before and after post code validation.
Q: I noticed that the Delivery Options section isn't toggleable. Other sections, including Building Removal, can be toggled. Should this be changed to be consistent?
Q: Should Building Removal be moved to below Delivery Options?
Base options should be OK regardless of the customer's post code
This is not exactly true.
Q: Are bases available for post code band 4 or 0?
A: Values for https://gardenvista.co.uk/store/alton-cambridge-hb-9-x-8-ft-greenhouse/#options_area
Post code | Band | Concrete base | Surcharge is |
---|---|---|---|
GU5 | 1 | 929.22 | Not applied |
GU1 | 2 | 969.22 | 40 |
GU6 | 3 | 999.22 | 70 |
PO30 | 4 | 929.22 | Not applied |
PL10 | 0 | 929.22 | Not applied |
My question is now:
Question posed in an email....
Going forward, can base surcharges for bands 2 and 3 be removed?
Or are they still needed, and if so, what's the surcharge for bands 4 and 0 - elsewhere
Q: Should Building Removal be moved to below Delivery Options?
In the latest incarnation I have move the postcode search into the options list so that it appears before Delivery Options and Building Removal.
In order to do this I had to remove the logic to display the single-product-sidebar-top
dynamic widget area.
I also removed the section that instructs the user to enter their post code
IMO these sections weren't all that necessary.
A full width version of the "we pride ourselves..." message appears after the options and Add to cart sidebar. plus a GO TO CHECKOUT button.
Instead of looking like this...
It now looks like this
The Postcode Search Text dynamic side bar is still available.
Currently, there's an intermittent problem with the display of the Building Removal section when the post code is changed and the band changes. This may be due to the height not being recalculated when the section that's hidden is changed.
Revisting base options...
I needed to change the addon-scripts.js
to determine the visible add-on price, which is the price displayed based on the band for the selected postcode.
This is fine for the user who only enters their post code once. But after the post code has been changed, there's a problem with cart addition and removal for the Choose Your Base section.
Product has a Concrete base price of 1200 for postcode band 1 (GU5) and 1240 for postcode band 2 (PO9).
Please enter the first part of your postcode (e.g. GU33) to check base options
PO9
and View optionsGU5
and View optionsThere are two problems
When the post code is changed the prices are not recalculated for currently selected items in the Current Cart.
In vgccodes.js
the prices should be recalculated when the post code is changed.
Calling setupDefaultAddons()
after setbands()
doesn't resolve the problem.
But a function similar to it could be used to adjustPricesofSelectedOptions()
I've developed the adjustPricesofSelectedOptions()
JavaScript code to adjust the prices of the selected options after a post code change.
Product has a Concrete base price of 1200 for postcode band 1 (GU5) and 1240 for postcode band 2 (PO9).
Please enter the first part of your postcode (e.g. GU33) to check base options
Same product as above. https://gvg.co.uk/store/a-test-product-2/
Continue above scenario where left off ( ie postcode GU5 ) with Concrete Base selected
Steps 8. and 11. to 13. are not as expected. But, there are at least workarounds which enable the user to get the desired results without having to reload the product.
Continuing from step 13.
Scenario with a product which is not a test product and that has many options. I chose https://gvg.co.uk/store/regency-valencia-summerhouse-7-x-5/ and had problems with the first option "Wood Types", which is a required addon, but doesn't display the price of 0.00 for Softwood.
The improved logic in getVisibleAddonPrice()
didn't cater for the fact that the price is given a class of hidden
in vgc_single_addon_prices()
.
Once that was fixed the problems that remained were:
If you set it to 0 then delivery will be FREE for any postcode that's not in bands 1 to 4. I think this would be an odd thing to do.
Agreed. Delivery to band 0 is not supported when the price is not set but other delivery bands have a price. The message should be "Sorry we cannot supply this to your location"
See https://github.com/bobbingwide/vgc/issues/59#issuecomment-1610943514
Agreed. Delivery to band 0 is not supported when the price is not set but other delivery bands have a price. The message should be "Sorry we cannot supply this to your location"
I checked in my local installation.
This logic doesn't need any further changes.
But we do need to update the JavaScript to support options which have a class of addon-select-required
.
The add-to-cart action requires the following data to be passed to the server.
_REQUEST Array
[single-single-addon-wood-types:softwood] => (string) "true"
[multi-single-addon-window-options:add-double-side-opening-window] => (string) ""
[multi-single-addon-verandah-option:monte-carlo-10-x-3-verandah-] => (string) ""
[base_extra] => (string) "0"
[building_removal_removal-and-taking-away-of-timber-building] => (string) ""
[building_removal_removal-of-greenhouses] => (string) ""
[installation] => (string) "no"
[base-type] => (string) "no base"
[b] => (string) "2"
[delivery] => (string) "2"
[awcdp_deposit_option] => (string) "no"
[add-to-cart] => (string) "4877"
Currently the new JavaScript is setting the value for delivery to "on". This either needs to be changed to the correct value for the selected post code band in the JavaScript or the server code needs to cater for it.
This either needs to be changed to the correct value for the selected post code band in the JavaScript or the server code needs to cater for it.
The correct value for the band is now set on the checkbox input field's value.
If it's mandatory that the customer has to choose the Delivery option then I'll need to add extra code to update the current cart when the post code's been entered.
At our meeting on 20th Sept it was confirmed that the Delivery and Base options should treated as addon-select-required
.
I've been working on the JavaScript to implement this.
It all seems to be working fine until you click on the currently selected checkbox for Delivery Options or Choose Your Base after changing the post code to a different band.
The add-to-cart action requires the following data to be passed to the server.
[base-type] => (string) "no base"
[b] => (string) "2"
For the Choose Your Base the value of the b field must be set correctly as well.
Currently the value being passed for b
is 0
Currently the value being passed for b is 0
I changed the server code that calculates the base price so that it uses the value for delivery
.
It all seems to be working fine until you click on the currently selected checkbox for Delivery Options or Choose Your Base after changing the post code to a different band.
Rather than attempt to change the code when the user clicks on an already selected checkbox I added logic to disable the checkbox when it was selected and enable any checkbox that was not. I discovered that this prevented the field from being passed to the server when the user pressed the Add to cart button.
To resolve this issue I added an event listener on 'click'. When the Add to cart button is pressed it enables any checkbox that's checked, allowing the value to be passed to the server. This solution also necessitated the change in https://github.com/bobbingwide/vgc/issues/59#issuecomment-1737009500
It now makes sense to revisit the logic that should prevent use of the Add to cart button when the conditions for submission have not been satisfied.
There is already logic that attempts to disable the Add to cart button ( runRequiredAddonValidation) but I had to change it so that it only looks at the main
set of optional addons, not the post code dependent ones.
I'm not sure how relevant this routine is now that I've prevented the option from being unchecked.
I'll try to add some logic to disable the Add to cart button when the the post code maps to
delivery_band_not_set
or delivery_excluded
.
When the post code maps to delivery_band_0
then sometimes delivery is supported and other times it's not.
There is already logic that attempts to disable the Add to cart button
When writing the replacement logic to enable or disable the Add to cart button I discovered that if the button is disabled then setting the style to "cursor: not-allowed" and title to "Please enter a valid postcode" would appear to be a pointless exercise since the disabled status takes priority. I wonder if the original code ever did the right thing?
When the post code maps to
delivery_band_0
then sometimes delivery is supported and other times it's not.
In order to detect this we'll have to look for a delivery checkbox for the current delivery band code.
If there is one then that implies that the Add to cart button should be enabled. Otherwise, it should be disabled.
Note: When the delivery band is 0, but delivery is not supported because no Delivery cost has been set
See https://github.com/bobbingwide/vgc/issues/59#issuecomment-1611227392
Revisiting this scenario since the logic to ensure that a required addon checkbox is set now causes the Choose Your Base option to revert to No base(*).
https://gvg.co.uk/store/a-test-product-2/
Product has a Concrete base price of 1200 for postcode band 1 (GU5) and 1240 for postcode band 2 (PO9).
Same product as above. https://gvg.co.uk/store/a-test-product-2/ repeat steps up to 15.
Steps 7. to 10. may not be as expected. But, there are at least workarounds which enable the user to get the desired results without having to reload the product.
(*) Does this mean that the code written to adjust the price - adjust PricesofSelectedOptions()
- is now invalid?
I changed the server code that calculates the base price so that it uses the value for delivery.
This also needed changing in calculate_price_on_cart_addition()
Re https://github.com/bobbingwide/vgc/issues/59#issuecomment-1611227392
Base options should be OK regardless of the customer's post code Q: Are bases available for post code band 4 or 0?
A: With VGC v1.7.1 the base price ( with no surcharge ) is still shown for band 0. Delivery is FREE since the delivery cost is 0.
Note: this comment updated since retesting after applying the fix mentioned in https://github.com/bobbingwide/vgc/issues/59#issuecomment-1790381380
Values for https://gardenvista.co.uk/store/alton-cambridge-hb-9-x-8-ft-greenhouse
Post code | Band | Concrete base | Surcharge is |
---|---|---|---|
GU5 | 1 | 929.22 | Not applied |
GU1 | 2 | 969.22 | 40 |
GU6 | 3 | 999.22 | 70 |
PO30 | 4 | 929.22 | Not applied |
PL10 | 0 | 929.22 | Not applied |
I found a problem when testing https://gardenvista.co.uk/store/deponti-bosco-veranda-6060x3000mm/
There was a minor problem in the code. Fixed in 73395ec
New version of brands.xlsx
updated from Live
Re: testing of delivery cost for a product in each brand
Note: For Milwood, even though the delivery cost is not set delivery is FREE to all post code bands. For Passmores: Delivery is FREE for band 0. But for Regency we get Sorry we cannot supply...
This is inconsistent. ie wrong!
For Passmores: Delivery is FREE for band 0. But for Regency we get Sorry we cannot supply... This is inconsistent. ie wrong!
This is due to the fact that when the Brand is first created, the delivery_cost
field is not set if no value is entered.
But when it has been set and then blanked out again the value stored is an empty string. This empty string needs to be treated as null.
There was also a problem when the excluded postcodes were not set. When determining the post code band the JavaScript would fail when it encountered a null value for the excluded postcodes array. The fix is to correctly set this variable in the server side code to an empty array when applicable.
The solution for VGC v1.7.2 delivery to post code band 0 can be summarised as below
Delivery Cost | Delivery cost bands 1 to 4 | Delivery to band 0 |
---|---|---|
not set | not set | Not supported |
0 | not set | FREE |
nn | not set | nn to all bands, incl. 0 |
not set | ww xx yy zz | Not supported |
vv | ww xx yy zz | vv |
There are several challenges to address related to delivery, installation, removal and base.
Delivery options
Options - including Installation, removal and base
There's specific logic to cater for certain building types.