Skip to content

Commit

Permalink
Remove confirm page; order details form on Cart page; simplify gatewa…
Browse files Browse the repository at this point in the history
…y snippets; reusable transaction summary snippet
  • Loading branch information
samnabi committed Nov 28, 2017
1 parent c506f7d commit 9b28c24
Show file tree
Hide file tree
Showing 36 changed files with 681 additions and 738 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -18,7 +18,6 @@
# Ignore non-default content files
/content/1-shop/*
!/content/1-shop/cart
!/content/1-shop/confirm
!/content/1-shop/countries
!/content/1-shop/terms-conditions
/content/1-shop/orders/*
Expand Down
5 changes: 0 additions & 5 deletions content/1-shop/confirm/confirm.en.txt

This file was deleted.

6 changes: 5 additions & 1 deletion content/site.en.txt
Expand Up @@ -190,4 +190,8 @@ Square-token-live:

----

Square-location:
Square-location:

----

Tax-included: 0
138 changes: 70 additions & 68 deletions site/plugins/shopkit/assets/css/shopkit.00a8e6.0077dd.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions site/plugins/shopkit/assets/css/shopkit.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion site/plugins/shopkit/assets/css/shopkit.css.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions site/plugins/shopkit/assets/css/shopkit.scss
Expand Up @@ -61,6 +61,8 @@ $warningPale: desaturate(lighten($warning, 30), 10);
$success: #2ecc40;
$successPale: desaturate(lighten($success, 30), 10);

$danger: #CC1F1A;

$text-s: 0.8rem;

$breakpoint-xs-s: 30em;
Expand Down Expand Up @@ -608,6 +610,10 @@ fieldset {
margin-bottom: 3em;
}

[aria-invalid="true"]:not(:focus):not(:valid) {
box-shadow: 0 0 0 2px $danger;
}

// Honeypot field
.forRobots {
visibility: hidden;
Expand Down
2 changes: 1 addition & 1 deletion site/plugins/shopkit/assets/js/cart.js
Expand Up @@ -23,7 +23,7 @@
// Attach listeners to <main> because its child elements may be replaced by new DOM
document.querySelector('main').addEventListener('submit', function(event){

// Only continue if it's an add/remove action
// Handle add/remove actions with ajax
if (event.target.action.value != 'add' && event.target.action.value != 'remove') return true;

// Stop standard submit action
Expand Down
1 change: 0 additions & 1 deletion site/plugins/shopkit/assets/js/expand-collapse-min.js

This file was deleted.

10 changes: 0 additions & 10 deletions site/plugins/shopkit/blueprints/confirm.yml

This file was deleted.

5 changes: 5 additions & 0 deletions site/plugins/shopkit/blueprints/order.yml
Expand Up @@ -50,9 +50,14 @@ fields:
type: text
readonly: true
width: 1/2
taxes:
label: taxes
type: textarea
readonly: true
tax:
label: tax
type: text
help: total tax
readonly: true
discount:
label: discount
Expand Down
37 changes: 23 additions & 14 deletions site/plugins/shopkit/controllers/cart.php
Expand Up @@ -31,27 +31,35 @@
if ($action == 'delete') delete($id);
}

// Set txn object
$txn = page(s::get('txn'));

// Set country
$countries = page('/shop/countries')->children()->invisible();
if ($country = get('country')) {
$countries = page('shop/countries')->children()->invisible();
if ($txn->shipping_address()->isNotEmpty()) {
$txn_shipping_address = $txn->shipping_address()->yaml();
} else {
$txn_shipping_address = [];
}
if ($country = esc(get('country'))) {
// First: See if country was sent through a form submission.
if ($c = $countries->filterBy('countrycode',$country)->first()) {
// Translate country code to UID if needed
$country = $c->uid();
}
page(s::get('txn'))->update(['country' => $country], $site->defaultLanguage()->code());
$txn_shipping_address['country'] = $country;
$txn->update(['shipping_address' => yaml::encode($txn_shipping_address)], $site->defaultLanguage()->code());
} else if (page(s::get('txn'))->country()->isNotEmpty()) {
// Second option: the country has already been set in the session.
// Do nothing.
} else if ($user and $user->country() != '') {
// Third option: get country from user profile
page(s::get('txn'))->update(['country' => $user->country()], $site->defaultLanguage()->code());
$txn_shipping_address['country'] = $user->country();
$txn->update(['shipping_address' => yaml::encode($txn_shipping_address)], $site->defaultLanguage()->code());
} else if ($site->defaultcountry()->isNotEmpty()) {
// Fourth option: get default country from site options
page(s::get('txn'))->update(['country' => $site->defaultcountry()], $site->defaultLanguage()->code());
$txn_shipping_address['country'] = $site->defaultcountry();
$txn->update(['shipping_address' => yaml::encode($txn_shipping_address)], $site->defaultLanguage()->code());
} else {
// Last resort: choose the first available country
page(s::get('txn'))->update(['country' => $countries->first()->uid()], $site->defaultLanguage()->code());
$txn_shipping_address['country'] = $countries->first()->uid();
$txn->update(['shipping_address' => yaml::encode($txn_shipping_address)], $site->defaultLanguage()->code());
}

// Get shipping rates
Expand All @@ -75,7 +83,7 @@
}
} else if (page(s::get('txn'))->shippingmethod()->isNotEmpty() and !empty($shippingMethods) and !get('country')) {
// Second option: the shipping has already been set in the session, and the country hasn't changed
$currentMethod = page(s::get('txn'))->shippingmethod();
$currentMethod = $txn->shippingmethod();
foreach ($shippingMethods as $key => $method) {
if ($currentMethod == $method['title']) {
$shippingMethod = $method;
Expand All @@ -85,7 +93,7 @@
// Last resort: choose the first shipping method
$shippingMethod = array_shift($shippingMethods);
}
page(s::get('txn'))->update([
$txn->update([
'shippingmethod' => $shippingMethod['title'],
'shipping' => $shippingMethod['rate'],
], $site->defaultLanguage()->code());
Expand All @@ -94,7 +102,7 @@
$discount = getDiscount();

// Get cart total
$total = cartSubtotal(getItems()) + (float) page(s::get('txn'))->shipping()->value;
$total = cartSubtotal(getItems()) + (float) $txn->shipping()->value;
if (!$site->tax_included()->bool()) $total = $total + cartTax()['total'];

// Handle discount codes
Expand All @@ -106,13 +114,14 @@


return [
'items' => getItems(),
'user' => $user,
'countries' => $countries,
'shipping_rates' => $shipping_rates,
'discount' => $discount,
'total' => $total,
'giftCertificate' => $giftCertificate,
'gateways' => $gateways,
'txn' => $txn
];
}
};
96 changes: 0 additions & 96 deletions site/plugins/shopkit/controllers/confirm.php

This file was deleted.

3 changes: 3 additions & 0 deletions site/plugins/shopkit/controllers/orders.php
Expand Up @@ -15,6 +15,9 @@
if (get('txn_id') != '') {
// If single transaction ID passed, show just that one order
$orders = $page->children()->sortBy('txn_date','desc')->filterBy('txn_id',get('txn_id'));

// Empty the cart by setting a new txn id (successful payment gateway callbacks will end up here)
s::destroy();
} else if ($user and $user->role() == 'admin') {
// If admin, show all orders except abandoned
$orders = $page->children()->sortBy('txn_date','desc');
Expand Down
65 changes: 53 additions & 12 deletions site/plugins/shopkit/controllers/process.php
Expand Up @@ -8,9 +8,60 @@
// Honeypot trap for robots
if (get('subject') != '') go(page('error')->url());

// Start the validation
$invalidFields = '';

// Validate personal details
$fieldsToValidate = [
'firstname' => v::minLength(esc(get('firstname')), 1),
'lastname' => v::minLength(esc(get('lastname')), 1),
'email' => v::email(esc(get('email')))
];
foreach ($fieldsToValidate as $key => $value) {
if ($value === false) {
$invalidFields .= $key.',';
}
}

// Validate mailing address
if ($site->mailing_address()->bool()) {
$fieldsToValidate = [
'address1' => v::minLength(esc(get('address1')), 1),
'city' => v::minLength(esc(get('city')), 1),
'state' => v::minLength(esc(get('state')), 1),
'postcode' => v::minLength(esc(get('postcode'), 1))
];
foreach ($fieldsToValidate as $key => $value) {
if ($value === false) {
$invalidFields .= $key.',';
}
}
}

// Validate terms and conditions checkbox
if ($tc = page('shop/terms-conditions') and $tc->text()->isNotEmpty() and get('tac') !== 'agree') {
go(page('shop/cart')->url().'/valid'.url::paramSeparator().'false/#tac');
$invalidFields .= 'tac,';
}

// Write personal details & mailing address to the transaction file
page(s::get('txn'))->update([
'payer-id' => $user ? $user->username() : '',
'payer-firstname' => esc(get('firstname')),
'payer-lastname' => esc(get('lastname')),
'payer-email' => esc(get('email')),
'shipping-address' => yaml::encode([
'address1' => esc(get('address1')),
'address2' => esc(get('address2')),
'city' => esc(get('city')),
'state' => esc(get('state')),
'country' => esc(get('country')),
'postcode' => esc(get('postcode'))
])
], $site->defaultLanguage()->code());

// Return to cart if there are invalid fields
if ($invalidFields != '') {
go(page('shop/cart')->url().'/invalid'.url::paramSeparator().substr($invalidFields, 0, -1).'#details');
}

// Set up variables
Expand All @@ -37,19 +88,9 @@
'tax' => number_format(cartTax()['total'],$decimal_places,'.',''),
'taxes' => yaml::encode(cartTax()),
'giftcode' => s::get('giftcode'),
'giftcertificate' => null !== get('giftCertificateAmount') ? number_format(get('giftCertificateAmount'),$decimal_places,'.','') : '0.00',
'giftcertificate' => null !== get('giftCertificateAmount') ? number_format(get('giftCertificateAmount'),$decimal_places,'.','') : '0.00'
], $site->defaultLanguage()->code());

// Add payer info if it's available at this point
if ($user) {
page(s::get('txn'))->update([
'payer-id' => $user->username(),
'payer-name' => $user->firstname().' '.$user->lastname(),
'payer-email' => $user->email(),
'payer-address' => page('shop/countries/'.$user->country())->title()
], $site->defaultLanguage()->code());
}

// Update the site's giftcard balance
if ($giftCertificateRemaining = get('giftCertificateRemaining')) {
$certificates = $site->gift_certificates()->yaml();
Expand Down

0 comments on commit 9b28c24

Please sign in to comment.