Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:frankmullenger/silverstripe-swipe…

…stripe
  • Loading branch information...
commit 4d018091be299d97819725968a70f166fa037b9f 2 parents f257071 + 58e6595
@frankmullenger authored
Showing with 411 additions and 65 deletions.
  1. +10 −0 README.md
  2. +24 −5 code/customer/CheckoutPage.php
  3. +3 −1 code/form/AttributeValidator.php
  4. +66 −0 code/form/CategoriesField.php
  5. +9 −1 code/form/ModifierHiddenField.php
  6. +9 −0 code/form/ModifierSetField.php
  7. +43 −0 code/form/RegionField.php
  8. +1 −0  code/modifiers/shipping/FlatFee/FlatFeeShipping.php
  9. +1 −4 code/modifiers/shipping/FlatFee/FlatFeeShippingConfigDecorator.php
  10. +10 −0 code/modifiers/shipping/FlatFee/FlatFeeShippingField.php
  11. +11 −0 code/modifiers/shipping/Shipping.php
  12. +3 −0  code/order/Address.php
  13. +3 −2 code/order/Modification.php
  14. +66 −3 code/order/Order.php
  15. +41 −31 code/product/Product.php
  16. +22 −4 code/product/ProductCategory.php
  17. +3 −2 code/product/ProductImage.php
  18. +0 −1  javascript/FlatFeeShippingField.js
  19. +1 −1  javascript/FlatFeeTaxField.js
  20. +2 −2 javascript/OptionGroupField.js
  21. +53 −0 javascript/RegionField.js
  22. +4 −0 templates/Includes/CheckoutFormOrder.ss
  23. +14 −6 templates/Includes/Order.ss
  24. +10 −2 templates/Includes/OrderAddresses.ss
  25. +2 −0  thirdparty/BelongsManyManyComplexTableField.php
View
10 README.md
@@ -40,3 +40,13 @@ Issues
------
[Please log bugs here](https://github.com/frankmullenger/silverstripe-swipestripe/issues).
+Attribution
+-----------
+Big thanks to:
+
+* [Emogrifier](http://www.pelagodesign.com/sidecar/emogrifier/)
+* [Twitter Bootstrap](http://twitter.github.com/bootstrap/) [Licence](http://www.apache.org/licenses/LICENSE-2.0)
+* [jQuery](http://jquery.com)
+
+
+
View
29 code/customer/CheckoutPage.php
@@ -244,7 +244,14 @@ private function addShippingAddressFields(&$fields, &$validator) {
$countryField = new DropdownField('Shipping[Country]', 'Country', Shipping::supported_countries());
$countryField->setCustomValidationMessage('Please enter a country.');
if (!Member::currentUserID() && Geoip::$default_country_code) $countryField->setValue(Geoip::$default_country_code); //Should probably do a default country in Shipping
-
+
+ $regions = Shipping::supported_regions();
+ $regionField = null;
+ if (!empty($regions)) {
+ $regionField = new RegionField('Shipping[Region]', 'Region');
+ $regionField->setCustomValidationMessage('Please enter a region.');
+ }
+
$sameAddressField = new CheckboxField('ShipToBillingAddress', 'to same address?');
$sameAddressField->addExtraClass('shipping-same-address');
@@ -259,7 +266,8 @@ private function addShippingAddressFields(&$fields, &$validator) {
$cityField,
new TextField('Shipping[PostalCode]', 'Postal Code'),
new TextField('Shipping[State]', 'State'),
- $countryField
+ $countryField,
+ $regionField
);
$shippingAddressFields->setID('ShippingAddress');
@@ -346,7 +354,14 @@ private function addItemFields(&$fields, &$validator, $order) {
private function addModifierFields(&$fields, &$validator, $order) {
foreach (Modifier::combined_form_fields($order) as $field) {
- $fields['Modifiers'][] = $field;
+
+ if ($field->modifiesSubTotal()) {
+ $fields['SubTotalModifiers'][] = $field;
+ }
+ else {
+ $fields['Modifiers'][] = $field;
+ }
+
}
}
@@ -536,7 +551,7 @@ function ProcessOrder($data, $form) {
function updateOrderFormCart(SS_HTTPRequest $data) {
if ($data->isPOST()) {
-
+
$fields = array();
$validator = new OrderFormValidator();
$member = Customer::currentUser() ? Customer::currentUser() : singleton('Customer');
@@ -554,7 +569,11 @@ function updateOrderFormCart(SS_HTTPRequest $data) {
//TODO This should be constructed for non-dropdown fields as well
//Update modifier form fields so that the dropdown values are correct
$newModifierData = array();
- foreach ($fields['Modifiers'] as $field) {
+ $subTotalModifiers = (isset($fields['SubTotalModifiers'])) ? $fields['SubTotalModifiers'] : array();
+ $totalModifiers = (isset($fields['Modifiers'])) ? $fields['Modifiers'] : array();
+ $modifierFields = array_merge($subTotalModifiers, $totalModifiers);
+
+ foreach ($modifierFields as $field) {
if (method_exists($field, 'updateValue')) {
$field->updateValue($order);
View
4 code/form/AttributeValidator.php
@@ -20,13 +20,15 @@ class AttributeValidator extends RequiredFields {
function php($data) {
$valid = parent::php($data);
-
+
$newTitle = (isset($data['Title'])) ? $data['Title'] : null;
if ($newTitle) {
$existingTitles = DataObject::get('Attribute');
$existingTitles = $existingTitles->map('ID', 'Title');
+ if (isset($data['ID'])) unset($existingTitles[$data['ID']]);
+
if (in_array($newTitle, $existingTitles)) {
$valid = false;
$this->validationError("Title", "Title already exists, please choose a different one.", 'bad');
View
66 code/form/CategoriesField.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Field for picking categories for a {@link Product}.
+ *
+ * @author Frank Mullenger <frankmullenger@gmail.com>
+ * @copyright Copyright (c) 2012, Frank Mullenger
+ * @package swipestripe
+ * @subpackage form
+ * @version 1.0
+ */
+class CategoriesField extends TreeMultiselectField {
+
+ /**
+ * Set dummy callback so that filterMarking() is triggered.
+ *
+ * @param String $name
+ * @param String $title
+ * @param String $sourceObject
+ * @param String $keyField
+ * @param String $labelField
+ */
+ function __construct($name, $title, $sourceObject = "Group", $keyField = "ID", $labelField = "Title") {
+ parent::__construct($name, $title, $sourceObject, $keyField, $labelField);
+ $this->value = 'unchanged';
+ $this->filterCallback = 'dummyTrigger';
+ }
+
+ /**
+ * Overriding to display only {@link ProductCategory}s in the dropdown.
+ *
+ * @see TreeDropdownField::filterMarking()
+ */
+ function filterMarking($node) {
+
+ if ($node->ClassName === 'ProductCategory') return true;
+
+ //If node has children that are categories then include it in the tree
+ if ($node->ClassName != 'ProductCategory') {
+
+ $children = $node->AllChildren();
+ if ($children && $children->exists()) {
+ foreach ($children as $child) {
+ if ($child->ClassName === 'ProductCategory') {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ }
+ else {
+ return false;
+ }
+ }
+
+ //Ignore the callback
+ //if ($this->filterCallback && !call_user_func($this->filterCallback, $node)) return false;
+
+ if ($this->sourceObject == "Folder" && $node->ClassName != 'Folder') return false;
+ if ($this->search != "") {
+ return isset($this->searchIds[$node->ID]) && $this->searchIds[$node->ID] ? true : false;
+ }
+
+ return true;
+ }
+}
View
10 code/form/ModifierHiddenField.php
@@ -38,7 +38,6 @@ class ModifierHiddenField extends HiddenField {
* @param value The current value
* @param form The parent form
*/
-
function __construct($modifier, $title = null, $value = "", $maxLength = null, $form = null) {
$name = "Modifiers[$modifier->ClassName]";
@@ -85,4 +84,13 @@ function Description() {
return;
}
+ /**
+ * Does not modify {@link Order} sub total by default.
+ *
+ * @return Boolean False
+ */
+ function modifiesSubTotal() {
+ return false;
+ }
+
}
View
9 code/form/ModifierSetField.php
@@ -72,4 +72,13 @@ function getModifier() {
return $this->modifier;
}
+ /**
+ * Does not modify {@link Order} sub total by default.
+ *
+ * @return Boolean False
+ */
+ function modifiesSubTotal() {
+ return false;
+ }
+
}
View
43 code/form/RegionField.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * For {@link Product} {@link Option} fields to be displayed on the {@link Product} page.
+ *
+ * @author Frank Mullenger <frankmullenger@gmail.com>
+ * @copyright Copyright (c) 2011, Frank Mullenger
+ * @package swipestripe
+ * @subpackage form
+ * @version 1.0
+ */
+class RegionField extends DropdownField {
+
+ /**
+ * Create drop down field for a product option, just ensures name of field
+ * is in the format Options[OptionClassName].
+ *
+ * @param String $optionClass Class name of the product option
+ * @param String $title
+ * @param Array $source
+ * @param String $value
+ * @param Form $form
+ * @param String $emptyString
+ */
+ function __construct($name, $title = null, $source = array(), $value = "", $form = null, $emptyString = null) {
+
+ $this->addExtraClass('dropdown');
+ parent::__construct($name, $title, $source, $value, $form, $emptyString);
+ }
+
+ function FieldHolder() {
+
+ $regions = Shipping::supported_regions();
+ $jsonRegions = json_encode($regions);
+
+ Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
+ Requirements::javascriptTemplate('swipestripe/javascript/RegionField.js', array(
+ "regions" => $jsonRegions,
+ 'defaultValue' => $this->Value()
+ ));
+ return parent::FieldHolder();
+ }
+
+}
View
1  code/modifiers/shipping/FlatFee/FlatFeeShipping.php
@@ -144,6 +144,7 @@ function addToOrder($order, $value) {
$modification = new Modification();
$modification->ModifierClass = get_class($this);
$modification->ModifierOptionID = $value;
+ $modification->SubTotalModifier = true;
$modification->Amount = $this->Amount($order, $value);
$modification->Description = $this->Description($order, $value);
View
5 code/modifiers/shipping/FlatFee/FlatFeeShippingConfigDecorator.php
@@ -30,10 +30,7 @@ function extraStatics() {
*/
function updateCMSFields(FieldSet &$fields) {
- //$fields->addFieldToTab("Root", new TabSet('Shop'));
- $fields->addFieldToTab("Root.Shop",
- new TabSet('Shipping')
- );
+ $fields->findOrMakeTabSet('Root.Shop.Shipping');
$fields->addFieldToTab("Root.Shop.Shipping",
new Tab('FlatFeeShipping')
);
View
10 code/modifiers/shipping/FlatFee/FlatFeeShippingField.php
@@ -139,4 +139,14 @@ function validate($validator){
return $valid;
}
+
+ /**
+ * Shipping field modifies {@link Order} sub total by default.
+ *
+ * @see ModifierSetField::modifiesSubTotal()
+ * @return Boolean True
+ */
+ function modifiesSubTotal() {
+ return true;
+ }
}
View
11 code/modifiers/shipping/Shipping.php
@@ -20,6 +20,9 @@ class Shipping extends DataObject {
protected static $supported_countries = array(
);
+ protected static $supported_regions = array(
+ );
+
/**
* Set countries that are supported for shipping to.
*
@@ -51,5 +54,13 @@ public static function set_supported_countries(Array $countries) {
public static function supported_countries() {
return self::$supported_countries;
}
+
+ public static function set_supported_regions(Array $regions) {
+ self::$supported_regions = $regions;
+ }
+
+ public static function supported_regions() {
+ return self::$supported_regions;
+ }
}
View
3  code/order/Address.php
@@ -26,6 +26,9 @@ class Address extends DataObject {
'PostalCode' => 'Varchar(30)',
'State' => 'Varchar(100)',
'Country' => 'Varchar',
+ 'CountryName' => 'Varchar',
+ 'Region' => 'Varchar',
+ 'RegionName' => 'Varchar'
);
/**
View
5 code/order/Modification.php
@@ -25,7 +25,8 @@ class Modification extends DataObject {
'ModifierClass' => 'Varchar',
'ModifierOptionID' => 'Int',
'Amount' => 'Money',
- 'Description' => 'Text'
+ 'Description' => 'Text',
+ 'SubTotalModifier' => 'Boolean'
);
/**
@@ -80,5 +81,5 @@ public static function currency() {
function validate() {
return parent::validate();
}
-
+
}
View
69 code/order/Order.php
@@ -256,7 +256,8 @@ public function getCMSFields() {
'Addresses',
'SubTotal',
'LastActive',
- 'Notes'
+ 'Notes',
+ 'XeroInvoiceID'
);
foreach($toBeRemoved as $field) {
$fields->removeByName($field);
@@ -577,7 +578,14 @@ public function updateTotal() {
}
if ($modifications) foreach ($modifications as $modification) {
- $total += $modification->Amount->getAmount();
+
+ if ($modification->SubTotalModifier) {
+ $total += $modification->Amount->getAmount();
+ $subTotal += $modification->Amount->getAmount();
+ }
+ else {
+ $total += $modification->Amount->getAmount();
+ }
}
$this->SubTotal->setAmount($subTotal);
@@ -637,7 +645,7 @@ function addModifiersAtCheckout(Array $data) {
foreach ($existingModifications as $modification) {
$modification->delete();
}
-
+
//Save new Modifications
if (isset($data['Modifiers']) && is_array($data['Modifiers'])) foreach ($data['Modifiers'] as $modifierClass => $value) {
@@ -657,6 +665,9 @@ function addAddressesAtCheckout(Array $data) {
$member = Customer::currentUser() ? Customer::currentUser() : singleton('Customer');
$order = CartControllerExtension::get_current_order();
+ $supportedCountries = Shipping::supported_countries();
+ $supportedRegions = Shipping::supported_regions();
+
//If there is a current billing and shipping address, update them, otherwise create new ones
$existingBillingAddress = $this->BillingAddress();
$existingShippingAddress = $this->ShippingAddress();
@@ -666,6 +677,11 @@ function addAddressesAtCheckout(Array $data) {
if (isset($data['Billing']) && is_array($data['Billing'])) foreach ($data['Billing'] as $fieldName => $value) {
$newData[$fieldName] = $value;
}
+
+ $newData['CountryName'] = (in_array($newData['Country'], array_keys($supportedCountries)))
+ ? $supportedCountries[$newData['Country']]
+ : null;
+
if ($member->ID) $newData['MemberID'] = $member->ID;
$existingBillingAddress->update($newData);
$existingBillingAddress->write();
@@ -683,6 +699,11 @@ function addAddressesAtCheckout(Array $data) {
$billingAddress->PostalCode = $data['Billing']['PostalCode'];
$billingAddress->State = $data['Billing']['State'];
$billingAddress->Country = $data['Billing']['Country'];
+
+ $billingAddress->CountryName = (in_array($data['Billing']['Country'], array_keys($supportedCountries)))
+ ? $supportedCountries[$data['Billing']['Country']]
+ : null;
+
$billingAddress->Type = 'Billing';
$billingAddress->write();
}
@@ -692,6 +713,18 @@ function addAddressesAtCheckout(Array $data) {
if (isset($data['Shipping']) && is_array($data['Shipping'])) foreach ($data['Shipping'] as $fieldName => $value) {
$newData[$fieldName] = $value;
}
+
+ $newData['CountryName'] = (in_array($newData['Country'], array_keys($supportedCountries)))
+ ? $supportedCountries[$newData['Country']]
+ : null;
+
+ if (isset($newData['Region']) && isset($supportedRegions[$newData['Country']])) {
+ if (in_array($newData['Region'], array_keys($supportedRegions[$newData['Country']]))) {
+ $newData['RegionName'] = $supportedRegions[$newData['Country']][$newData['Region']];
+ }
+ }
+ else $newData['RegionName'] = null;
+
if ($member->ID) $newData['MemberID'] = $member->ID;
$existingShippingAddress->update($newData);
$existingShippingAddress->write();
@@ -709,6 +742,16 @@ function addAddressesAtCheckout(Array $data) {
$shippingAddress->PostalCode = $data['Shipping']['PostalCode'];
$shippingAddress->State = $data['Shipping']['State'];
$shippingAddress->Country = $data['Shipping']['Country'];
+ $shippingAddress->Region = (isset($data['Shipping']['Region'])) ? $data['Shipping']['Region'] : null;
+
+ $shippingAddress->CountryName = (in_array($data['Shipping']['Country'], array_keys($supportedCountries)))
+ ? $supportedCountries[$data['Shipping']['Country']]
+ : null;
+
+ $shippingAddress->RegionName = (isset($data['Shipping']['Region']) && isset($supportedRegions[$data['Shipping']['Country']]) && in_array($data['Shipping']['Region'], array_keys($supportedRegions[$data['Shipping']['Country']])))
+ ? $supportedRegions[$data['Shipping']['Country']][$data['Shipping']['Region']]
+ : null;
+
$shippingAddress->Type = 'Shipping';
$shippingAddress->write();
}
@@ -906,5 +949,25 @@ public function augmentDatabase() {
//
//SS_Log::log(new Exception(print_r("ALTER TABLE $tableName AUTO_INCREMENT = 12547", true)), SS_Log::NOTICE);
}
+
+ /**
+ * Get modifications that apply changes to the Order sub total.
+ *
+ * @return DataObjectSet Set of Modification DataObjects
+ */
+ public function SubTotalModifications() {
+ $orderID = $this->ID;
+ return DataObject::get('Modification', "\"OrderID\" = $orderID AND \"SubTotalModifier\" = 1");
+ }
+
+ /**
+ * Get modifications that apply changes to the Order total (not the order sub total).
+ *
+ * @return DataObjectSet Set of Modification DataObjects
+ */
+ public function TotalModifications() {
+ $orderID = $this->ID;
+ return DataObject::get('Modification', "\"OrderID\" = $orderID AND \"SubTotalModifier\" = 0");
+ }
}
View
72 code/product/Product.php
@@ -314,17 +314,6 @@ public function getCMSFields() {
$fields->addFieldToTab('Root.Content.Main', new StockField('Stock', null, $level, $this), 'Content');
//Product categories
- $manager = new BelongsManyManyComplexTableField(
- $this,
- 'ProductCategories',
- 'ProductCategory',
- array(),
- 'getCMSFields_forPopup',
- '',
- '"Title" ASC'
- );
- $manager->setPageSize(20);
- $manager->setPermissions(array());
$fields->addFieldToTab("Root.Content.Categories", new HeaderField(
'CategoriesHeading',
'Select categories you would like this product to appear in',
@@ -337,7 +326,24 @@ public function getCMSFields() {
</p>
EOS;
$fields->addFieldToTab("Root.Content.Categories", new LiteralField('CategoryAlert', $categoryAlert));
+
+ /*
+ $manager = new BelongsManyManyComplexTableField(
+ $this,
+ 'ProductCategories',
+ 'ProductCategory',
+ array(),
+ 'getCMSFields_forPopup',
+ '',
+ '"Title" ASC'
+ );
+ $manager->setPageSize(20);
+ $manager->setPermissions(array());
$fields->addFieldToTab("Root.Content.Categories", $manager);
+ */
+
+ $categoriesField = new CategoriesField('ProductCategories', false, 'ProductCategory');
+ $fields->addFieldToTab("Root.Content.Categories", $categoriesField);
//Attributes selection
$anyAttribute = DataObject::get_one('Attribute');
@@ -435,45 +441,49 @@ public function getCMSFields() {
$variationFieldList,
'getCMSFields_forPopup'
);
+ if (class_exists('SWS_Xero_Item_Decorator')) $manager->setPopupSize(500, 650);
$fields->addFieldToTab("Root.Content.Variations", $manager);
}
//Product ordering
$categories = $this->ProductCategories();
- if ($categories && $categories->exists()) foreach ($categories as $category) {
-
+ if ($categories && $categories->exists()) {
+
$fields->addFieldToTab("Root.Content", new Tab('Order'));
- $fields->addFieldToTab("Root.Content.Order", new HeaderField(
- 'OrderHeading',
- 'Set the order of this product in each of it\'s categories',
- 3
- ));
- $orderHelp = <<<EOS
+ $fields->addFieldToTab("Root.Content.Order", new HeaderField(
+ 'OrderHeading',
+ 'Set the order of this product in each of it\'s categories',
+ 3
+ ));
+
+ $orderHelp = <<<EOS
<p class="ProductHelp">
Products with higher order numbers in each category will appear further at the front of
that category.
</p>
EOS;
- $fields->addFieldToTab("Root.Content.Order", new LiteralField('OrderHelp', $orderHelp));
+ $fields->addFieldToTab("Root.Content.Order", new LiteralField('OrderHelp', $orderHelp));
+
+ foreach ($categories as $category) {
- $categoryTitle = $category->Title;
- $categoryID = $category->ID;
- $productID = $this->ID;
- $sql = <<<EOS
+ $categoryTitle = $category->Title;
+ $categoryID = $category->ID;
+ $productID = $this->ID;
+ $sql = <<<EOS
SELECT "ProductOrder"
FROM "ProductCategory_Products"
WHERE "ProductCategoryID" = $categoryID
AND "ProductID" = $productID
EOS;
- $query = DB::query($sql);
- $order = $query->value();
-
- $val = ($order) ? $order : 0;
- $fields->addFieldToTab('Root.Content.Order', new TextField("CategoryOrder[$categoryID]", "Order in $categoryTitle Category", $val));
- }
-
+ $query = DB::query($sql);
+ $order = $query->value();
+
+ $val = ($order) ? $order : 0;
+ $fields->addFieldToTab('Root.Content.Order', new TextField("CategoryOrder[$categoryID]", "Order in $categoryTitle Category", $val));
+ }
+ }
//Ability to edit fields added to CMS here
$this->extend('updateProductCMSFields', $fields);
View
26 code/product/ProductCategory.php
@@ -83,6 +83,21 @@ function getCMSFields() {
*/
class ProductCategory_Controller extends Page_Controller {
+ /**
+ * Set number of products per page displayed in ProductCategory pages
+ *
+ * @var Int
+ */
+ public static $products_per_page = 12;
+
+ /**
+ * Set how the products are ordered on ProductCategory pages
+ *
+ * @see ProductCategory_Controller::Products()
+ * @var String Suitable for inserting in ORDER BY clause
+ */
+ public static $products_ordered_by = "\"ProductCategory_Products\".\"ProductOrder\" DESC";
+
/**
* Include some CSS.
*
@@ -104,18 +119,21 @@ public function Products() {
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
- $SQL_start = (int)$_GET['start'];
+ $start = (int)$_GET['start'];
+ $limit = self::$products_per_page;
+ $orderBy = self::$products_ordered_by;
+
$products = DataObject::get(
'Product',
"\"ProductCategory_Products\".\"ProductCategoryID\" = '".$this->ID."' OR \"ParentID\" = '".$this->ID."'",
- "\"ProductCategory_Products\".\"ProductOrder\" DESC",
+ $orderBy,
"LEFT JOIN \"ProductCategory_Products\" ON \"ProductCategory_Products\".\"ProductID\" = \"Product\".\"ID\"",
- "{$SQL_start}, 12"
+ "{$start}, $limit"
);
$this->extend('updateCategoryProducts', $products);
- return $products ? $products : false;
+ return $products;
}
}
View
5 code/product/ProductImage.php
@@ -61,7 +61,8 @@ function SummaryOfImage() {
* @return Image|String If no image can be found returns '(No Image)'
*/
function fortemplate() {
- if ($Image = $this->Image()) return $Image->CroppedImage(40,40)->forTemplate();
- else return '(No Image)';
+ $image = $this->Image();
+ $thumb = ($image && $image->exists()) ? $image->CroppedImage(40,40) : null;
+ return ($thumb && $thumb->exists()) ? $thumb->forTemplate() : '(No Image)';
}
}
View
1  javascript/FlatFeeShippingField.js
@@ -19,7 +19,6 @@
});
}
$('#CheckoutForm_OrderForm_Shipping-Country').live('change', updateOrderFormCartAJAX).change();
- //$('div.flatfeeshipping select').live('change', updateOrderFormCartAJAX);
$('.modifier-set-field select').live('change', updateOrderFormCartAJAX);
updateOrderFormCartAJAX(); //This ruins the modifier field being set to the correct value for some reason
})
View
2  javascript/FlatFeeTaxField.js
@@ -8,7 +8,7 @@
//AJAX call to update the cart
var values = $('#CheckoutForm_OrderForm').serialize();
-
+
$.ajax({
url: window.location.pathname + '/updateOrderFormCart',
type: 'POST',
View
4 javascript/OptionGroupField.js
@@ -89,8 +89,8 @@
$('#VariationPrice').html('');
}
*/
-
- if (dataObj.totalPrice && $('.variation-prcie').length) {
+
+ if (dataObj.totalPrice) { //&& $('.variation-prcie').length) {
$('.product-price').html(dataObj.totalPrice);
}
}
View
53 javascript/RegionField.js
@@ -0,0 +1,53 @@
+
+(function($) {
+
+ //TODO need to namespace this properly
+ window.populateRegion = function() {
+
+ var regions = $.parseJSON('$regions');
+
+ var $countryField;
+ if ($('#CheckoutForm_OrderForm_Shipping-Country').length > 0) {
+ $countryField = $('#CheckoutForm_OrderForm_Shipping-Country');
+ }
+ if ($('select[name=CountryCode]').length > 0) {
+ $countryField = $('select[name=CountryCode]');
+ }
+
+ var $regionField = $('.region select');
+ var defaultValue = '$defaultValue';
+
+ if ($countryField.length > 0 && $regionField.length > 0) {
+
+ //Listen to changes on country field and reflect changes in region
+ $countryField.live('change', function() {
+
+ var countryCode = $(this).val();
+ var newRegions = regions[countryCode];
+ $('option', $regionField).remove();
+
+ if (newRegions) {
+
+ if($regionField.prop) var options = $regionField.prop('options');
+ else var options = $regionField.attr('options');
+
+ $.each(newRegions, function(key, value) {
+ options[options.length] = new Option(value, key);
+ });
+
+ if (defaultValue) {
+ $regionField.val(defaultValue);
+ }
+ else {
+ $regionField.val($("option:first", $regionField).val());
+ }
+ }
+ });
+ $countryField.change();
+ }
+ }
+
+ $(document).ready(function() {
+ populateRegion();
+ })
+})(jQuery);
View
4 templates/Includes/CheckoutFormOrder.ss
@@ -25,6 +25,10 @@
</tr>
<% end_if %>
+ <% control Top.Fields(SubTotalModifiers) %>
+ $FieldHolder
+ <% end_control %>
+
<tr>
<td colspan="4" class="row-header">Sub Total</td>
<td>$SubTotal.Nice ($SubTotal.Currency)</td>
View
20 templates/Includes/Order.ss
@@ -44,14 +44,22 @@
</tr>
<% end_control %>
- <% if Modifications %>
+ <% if SubTotalModifications %>
+ <% control SubTotalModifications %>
+ <tr>
+ <td colspan="4" class="row-header">$Description</td>
+ <td>$Amount.Nice</td>
+ </tr>
+ <% end_control %>
+ <% end_if %>
- <tr>
- <td colspan="4" class="row-header">Sub Total</td>
- <td>$SubTotal.Nice</td>
- </tr>
+ <tr>
+ <td colspan="4" class="row-header">Sub Total</td>
+ <td>$SubTotal.Nice</td>
+ </tr>
- <% control Modifications %>
+ <% if TotalModifications %>
+ <% control TotalModifications %>
<tr>
<td colspan="4" class="row-header">$Description</td>
<td>$Amount.Nice</td>
View
12 templates/Includes/OrderAddresses.ss
@@ -21,7 +21,11 @@
<% if City %> $City<br /> <% end_if %>
<% if PostalCode %> $PostalCode<br /> <% end_if %>
<% if State %> $State<br /> <% end_if %>
- <% if Country %> $Country<br /> <% end_if %>
+
+ <% if RegionName %> $RegionName<br /> <% end_if %>
+
+ <% if CountryName %> $CountryName<br /> <% else %>
+ <% if Country %> $Country<br /> <% end_if %><% end_if %>
<% end_control %>
</td>
@@ -35,7 +39,11 @@
<% if City %> $City<br /> <% end_if %>
<% if PostalCode %> $PostalCode<br /> <% end_if %>
<% if State %> $State<br /> <% end_if %>
- <% if Country %> $Country<br /> <% end_if %>
+
+ <% if RegionName %> $RegionName<br /> <% end_if %>
+
+ <% if CountryName %> $CountryName<br /> <% else %>
+ <% if Country %> $Country<br /> <% end_if %><% end_if %>
<% end_control %>
</td>
</tr>
View
2  thirdparty/BelongsManyManyComplexTableField.php
@@ -46,6 +46,8 @@ function __construct($controller, $name, $sourceClass, $fieldList = null, $detai
parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
+ //Sort by heirarchy, depending on number of parents indent
+
$classes = array_reverse(ClassInfo::ancestry($this->controllerClass()));
foreach($classes as $class) {
$singleton = singleton($class);
Please sign in to comment.
Something went wrong with that request. Please try again.