Index: branches/5.1.x/install/install_schema.sql
===================================================================
diff -u -r13100 -r13558
--- branches/5.1.x/install/install_schema.sql (.../install_schema.sql) (revision 13100)
+++ branches/5.1.x/install/install_schema.sql (.../install_schema.sql) (revision 13558)
@@ -711,4 +711,18 @@
ResourceId int(10) unsigned NOT NULL default '0',
KEY ResourceId (ResourceId),
PRIMARY KEY (CustomDataId)
-);
\ No newline at end of file
+);
+
+ALTER TABLE SiteDomains
+ ADD COLUMN BillingCountry varchar(3) NOT NULL DEFAULT '',
+ ADD COLUMN ShippingCountry varchar(3) NOT NULL DEFAULT '',
+ ADD COLUMN PrimaryCurrencyId int(11) NOT NULL DEFAULT '0',
+ ADD COLUMN Currencies varchar(255) NOT NULL DEFAULT '',
+ ADD COLUMN PrimaryPaymentTypeId int(11) NOT NULL DEFAULT '0',
+ ADD COLUMN PaymentTypes varchar(255) NOT NULL DEFAULT '',
+ ADD INDEX (BillingCountry),
+ ADD INDEX (ShippingCountry),
+ ADD INDEX (PrimaryCurrencyId),
+ ADD INDEX (Currencies),
+ ADD INDEX (PrimaryPaymentTypeId),
+ ADD INDEX (PaymentTypes);
\ No newline at end of file
Index: branches/5.1.x/install/upgrades.sql
===================================================================
diff -u -r13549 -r13558
--- branches/5.1.x/install/upgrades.sql (.../upgrades.sql) (revision 13549)
+++ branches/5.1.x/install/upgrades.sql (.../upgrades.sql) (revision 13558)
@@ -140,4 +140,18 @@
UPDATE ConfigurationValues
SET ValueList = '0=lu_none||SELECT l%3$s_Name AS OptionName, CountryStateId AS OptionValue FROM CountryStates WHERE Type = 1 ORDER BY OptionName'
-WHERE ValueList = '0=lu_none||SELECT DestName AS OptionName, DestAbbr AS OptionValue FROM StdDestinations WHERE DestParentId IS NULL Order BY OptionName';
\ No newline at end of file
+WHERE ValueList = '0=lu_none||SELECT DestName AS OptionName, DestAbbr AS OptionValue FROM StdDestinations WHERE DestParentId IS NULL Order BY OptionName';
+
+ALTER TABLE SiteDomains
+ ADD COLUMN BillingCountry varchar(3) NOT NULL DEFAULT '',
+ ADD COLUMN ShippingCountry varchar(3) NOT NULL DEFAULT '',
+ ADD COLUMN PrimaryCurrencyId int(11) NOT NULL DEFAULT '0',
+ ADD COLUMN Currencies varchar(255) NOT NULL DEFAULT '',
+ ADD COLUMN PrimaryPaymentTypeId int(11) NOT NULL DEFAULT '0',
+ ADD COLUMN PaymentTypes varchar(255) NOT NULL DEFAULT '',
+ ADD INDEX (BillingCountry),
+ ADD INDEX (ShippingCountry),
+ ADD INDEX (PrimaryCurrencyId),
+ ADD INDEX (Currencies),
+ ADD INDEX (PrimaryPaymentTypeId),
+ ADD INDEX (PaymentTypes);
\ No newline at end of file
Index: branches/5.1.x/units/sections/sections_config.php
===================================================================
diff -u
--- branches/5.1.x/units/sections/sections_config.php (revision 0)
+++ branches/5.1.x/units/sections/sections_config.php (revision 13558)
@@ -0,0 +1,34 @@
+ 'in-commerce-sections',
+
+ 'EventHandlerClass' => Array ('class' => 'InCommerceEventHandler', 'file' => 'section_eh.php', 'build_event' => 'OnBuild'), // for OnAfterConfigRead event
+ 'TagProcessorClass' => Array ('class' => 'kTagProcessor', 'file' => '', 'build_event' => 'OnBuild'), // for tree drawing
+
+ 'Hooks' => Array (
+ Array (
+ 'Mode' => hAFTER,
+ 'Conditional' => false,
+ 'HookToPrefix' => 'site-domain',
+ 'HookToSpecial' => '*',
+ 'HookToEvent' => Array ('OnAfterConfigRead'),
+ 'DoPrefix' => '',
+ 'DoSpecial' => '*',
+ 'DoEvent' => 'OnModifySiteDomainConfig',
+ ),
+ ),
+ );
Index: branches/5.1.x/units/orders/orders_event_handler.php
===================================================================
diff -u -r13549 -r13558
--- branches/5.1.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 13549)
+++ branches/5.1.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 13558)
@@ -1,6 +1,6 @@
Application->GetVar( $event->getPrefixSpecial(true) );
- if($items_info)
- {
- list($id,$field_values) = each($items_info);
+ if ($items_info) {
+ list($id, $field_values) = each($items_info);
$object =& $event->getObject();
$payment_type_id = $object->GetDBField('PaymentType');
- if(!$payment_type_id)
- {
- $default_type = $this->Conn->GetOne('SELECT PaymentTypeId FROM '.TABLE_PREFIX.'PaymentTypes WHERE IsPrimary = 1');
- if($default_type)
- {
+
+ if (!$payment_type_id) {
+ $default_type = $this->_getDefaultPaymentType();
+
+ if ($default_type) {
$field_values['PaymentType'] = $default_type;
$items_info[$id] = $field_values;
$this->Application->SetVar( $event->getPrefixSpecial(true), $items_info );
@@ -1115,7 +1114,8 @@
}
// get payment type
- $default_type = $this->Conn->GetOne('SELECT PaymentTypeId FROM '.TABLE_PREFIX.'PaymentTypes WHERE IsPrimary = 1');
+ $default_type = $this->_getDefaultPaymentType();
+
if ($default_type) {
$object->SetDBField('PaymentType', $default_type);
}
@@ -1133,6 +1133,25 @@
return 0;
}
+ /**
+ * Returns default payment type for order
+ *
+ * @return int
+ */
+ function _getDefaultPaymentType()
+ {
+ $default_type = $this->Application->siteDomainField('PrimaryPaymentTypeId');
+
+ if (!$default_type) {
+ $sql = 'SELECT PaymentTypeId
+ FROM ' . TABLE_PREFIX . 'PaymentTypes
+ WHERE IsPrimary = 1';
+ $default_type = $this->Conn->GetOne($sql);
+ }
+
+ return $default_type;
+ }
+
function StoreContinueShoppingLink()
{
$this->Application->StoreVar('continue_shopping', 'external:'.PROTOCOL.SERVER_NAME.$this->Application->RecallVar('last_url'));
@@ -1975,6 +1994,21 @@
$object =& $event->getObject();
/* @var $object OrdersItem */
+ $old_payment_type = $object->GetOriginalField('PaymentType');
+ $new_payment_type = $object->GetDBField('PaymentType');
+
+ if ($new_payment_type != $old_payment_type) {
+ // payment type changed -> check that it's allowed
+ $available_payment_types = $this->Application->siteDomainField('PaymentTypes');
+
+ if ($available_payment_types) {
+ if (strpos($available_payment_types, '|' . $new_payment_type . '|') === false) {
+ // payment type isn't allowed in site domain
+ $object->SetDBField('PaymentType', $old_payment_type);
+ }
+ }
+ }
+
$cs_helper =& $this->Application->recallObject('CountryStatesHelper');
/* @var $cs_helper kCountryStatesHelper */
@@ -3824,22 +3858,40 @@
$fields['Number']['format'] = str_replace('%06d', '%0'.$order_number.'d', $fields['Number']['format']);
$fields['SubNumber']['format'] = str_replace('%03d', '%0'.$order_sub_number.'d', $fields['SubNumber']['format']);
+ $site_helper =& $this->Application->recallObject('SiteHelper');
+ /* @var $site_helper SiteHelper */
+
+ $fields['BillingCountry']['default'] = $site_helper->getDefaultCountry('Billing');
+ $fields['ShippingCountry']['default'] = $site_helper->getDefaultCountry('Shipping');
+
if (!$this->Application->isAdminUser) {
$user_groups = explode(',', $this->Application->RecallVar('UserGroups'));
$default_group = $this->Application->ConfigValue('User_LoggedInGroup');
if (!in_array($default_group, $user_groups)){
$user_groups[] = $default_group;
}
+
+ $sql_part = '';
+
+ // limit payment types by domain
+ $payment_types = $this->Application->siteDomainField('PaymentTypes');
+
+ if (strlen($payment_types)) {
+ $payment_types = explode('|', substr($payment_types, 1, -1));
+ $sql_part .= ' AND PaymentTypeId IN (' . implode(',', $payment_types) . ')';
+ }
+
+ // limit payment types by user group
+ $sql_part .= ' AND (PortalGroups LIKE "%%,'.implode(',%%" OR PortalGroups LIKE "%%,', $user_groups).',%%")';
+
$fields['PaymentType']['options_sql'] = str_replace(
'ORDER BY ',
- 'AND (PortalGroups LIKE "%%,'.implode(',%%" OR PortalGroups LIKE "%%,', $user_groups).',%%") ORDER BY ',
+ $sql_part . ' ORDER BY ',
$fields['PaymentType']['options_sql']
);
}
$this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
-
-
}
/**
Index: branches/5.1.x/units/payment_type/payment_type_event_handler.php
===================================================================
diff -u -r13100 -r13558
--- branches/5.1.x/units/payment_type/payment_type_event_handler.php (.../payment_type_event_handler.php) (revision 13100)
+++ branches/5.1.x/units/payment_type/payment_type_event_handler.php (.../payment_type_event_handler.php) (revision 13558)
@@ -1,6 +1,6 @@
getObject();
+ /* @var $object kDBList */
+
+ if (in_array($event->Special, Array ('enabled', 'selected', 'available')) || !$this->Application->isAdminUser) {
+ // "enabled" special or Front-End
+ $object->addFilter('enabled_filter', '%1$s.Status = ' . STATUS_ACTIVE);
+ }
+
+ // site domain payment type picker
+ if ($event->Special == 'selected' || $event->Special == 'available') {
+ $edit_picker_helper =& $this->Application->recallObject('EditPickerHelper');
+ /* @var $edit_picker_helper EditPickerHelper */
+
+ $edit_picker_helper->applyFilter($event, 'PaymentTypes');
+ }
+
+ // apply domain-based payment type filtering
+ $payment_types = $this->Application->siteDomainField('PaymentTypes');
+
+ if (strlen($payment_types)) {
+ $payment_types = explode('|', substr($payment_types, 1, -1));
+ $object->addFilter('domain_filter', '%1$s.PaymentTypeId IN (' . implode(',', $payment_types) . ')');
+ }
+ }
+
}
\ No newline at end of file
Index: branches/5.1.x/units/currencies/currencies_event_handler.php
===================================================================
diff -u -r13147 -r13558
--- branches/5.1.x/units/currencies/currencies_event_handler.php (.../currencies_event_handler.php) (revision 13147)
+++ branches/5.1.x/units/currencies/currencies_event_handler.php (.../currencies_event_handler.php) (revision 13558)
@@ -1,6 +1,6 @@
Application->isAdminUser) {
$object->addFilter('status_filter', $object->TableName.'.Status = 1');
}
+
+ // site domain currency picker
+ if ($event->Special == 'selected' || $event->Special == 'available') {
+ $edit_picker_helper =& $this->Application->recallObject('EditPickerHelper');
+ /* @var $edit_picker_helper EditPickerHelper */
+
+ $edit_picker_helper->applyFilter($event, 'Currencies');
+ $object->addFilter('status_filter', '%1$s.Status = ' . STATUS_ACTIVE);
+ }
+
+ // apply domain-based currency filtering
+ $currencies = $this->Application->siteDomainField('Currencies');
+
+ if (strlen($currencies)) {
+ $currencies = explode('|', substr($currencies, 1, -1));
+ $object->addFilter('domain_filter', '%1$s.CurrencyId IN (' . implode(',', $currencies) . ')');
+ }
}
/**
@@ -208,7 +225,17 @@
function OnChangeCurrency(&$event)
{
- $this->Application->StoreVar('curr_iso', $this->Application->GetVar('curr_iso'));
+ $currency_iso = $this->Application->GetVar('curr_iso');
+ $available_currencies = $this->Application->siteDomainField('Currencies');
+
+ if ($available_currencies) {
+ if (strpos($available_currencies, '|' . $currency_iso . '|') === false) {
+ // currency isn't allowed in site domain
+ return ;
+ }
+ }
+
+ $this->Application->StoreVar('curr_iso', $currency_iso);
}
/**
Index: branches/5.1.x/admin_templates/site_domains/site_domain_edit.tpl
===================================================================
diff -u
--- branches/5.1.x/admin_templates/site_domains/site_domain_edit.tpl (revision 0)
+++ branches/5.1.x/admin_templates/site_domains/site_domain_edit.tpl (revision 13558)
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: branches/5.1.x/install/english.lang
===================================================================
diff -u -r13549 -r13558
--- branches/5.1.x/install/english.lang (.../english.lang) (revision 13549)
+++ branches/5.1.x/install/english.lang (.../english.lang) (revision 13558)
@@ -90,6 +90,7 @@
QW1vdW50
QXZhaWwu
QmFzZSBGZWU=
+ QmlsbGluZyBDb3VudHJ5
QnVpbHQtSW4=
Q09EIEFsbG93ZWQ=
Q29kZQ==
@@ -103,6 +104,7 @@
Q291cG9uIENvZGU=
Q291cG9uIEl0ZW0gVHlwZQ==
Q3JlZGl0IENhcmQgTnVtYmVy
+ Q3VycmVuY3k=
TmFtZQ==
U3ltYm9s
U3ltYm9sIFBvc2l0aW9u
@@ -178,6 +180,7 @@
UmV0LiBEYXRl
UmV0LiBUeXBl
U2hpcHBpbmc=
+ U2hpcHBpbmcgQ291bnRyeQ==
RnJvbSBMb2NhdGlvbg==
TmFtZQ==
TmFtZQ==
@@ -309,6 +312,8 @@
Q29zdCBUeXBl
Q291cG9uIENvZGU=
Q3JlZGl0IENhcmQgTnVtYmVy
+ Q3VycmVuY2llcw==
+ Q3VycmVuY3k=
TmFtZQ==
U3ltYm9s
U3ltYm9sIFBvc2l0aW9u
@@ -378,6 +383,7 @@
UGF5bWVudCBUeXBl
QXZhaWxhYmxlIEN1cnJlbmNpZXM=
UGF5bWVudCBUeXBlIElk
+ UGF5bWVudCBUeXBlcw==
UGVyY2VudCBTdXJjaGFyZ2U=
UGVyaW9k
QWxsb3cgUGxhY2VkIE9yZGVycyBFZGl0aW5n
Index: branches/5.1.x/units/addresses/addresses_event_handler.php
===================================================================
diff -u -r13465 -r13558
--- branches/5.1.x/units/addresses/addresses_event_handler.php (.../addresses_event_handler.php) (revision 13465)
+++ branches/5.1.x/units/addresses/addresses_event_handler.php (.../addresses_event_handler.php) (revision 13558)
@@ -1,6 +1,6 @@
Application->recallObject('SiteHelper');
+ /* @var $site_helper SiteHelper */
+
+ $fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
+ $fields['Country']['default'] = $site_helper->getDefaultCountry('Shipping');
+ $this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
+ }
}
\ No newline at end of file
Index: branches/5.1.x/units/sections/section_eh.php
===================================================================
diff -u
--- branches/5.1.x/units/sections/section_eh.php (revision 0)
+++ branches/5.1.x/units/sections/section_eh.php (revision 13558)
@@ -0,0 +1,101 @@
+Application->getUnitOption($event->MasterEvent->Prefix, 'EditTabPresets');
+ $edit_tab_presets['Default']['in-commerce'] = Array (
+ 'title' => 'la_title_In-Commerce', 't' => 'in-commerce/site_domains/site_domain_edit', 'priority' => 2.1
+ );
+ $this->Application->setUnitOption($event->MasterEvent->Prefix, 'EditTabPresets', $edit_tab_presets);
+
+ $title_presets = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'TitlePresets');
+ $title_presets['site_domain_edit_in_commerce'] = Array (
+ 'prefixes' => Array ('site-domain'), 'format' => "#site-domain_status# '#site-domain_titlefield#' - !la_title_In-Commerce!",
+ 'toolbar_buttons' => Array ('select', 'cancel', 'reset_edit', 'prev', 'next'),
+ );
+ $this->Application->setUnitOption($event->MasterEvent->Prefix, 'TitlePresets', $title_presets);
+
+ $new_fields = Array (
+ 'BillingCountry' => Array (
+ 'type' => 'string', 'max_len' => 3,
+ 'formatter' => 'kOptionsFormatter',
+ 'options_sql' => ' SELECT IF(l%2$s_Name = "", l%3$s_Name, l%2$s_Name) AS Name, IsoCode
+ FROM ' . TABLE_PREFIX . 'CountryStates
+ WHERE Type = ' . DESTINATION_TYPE_COUNTRY . '
+ ORDER BY Name',
+ 'option_key_field' => 'IsoCode', 'option_title_field' => 'Name',
+ 'not_null' => 1, 'default' => ''
+ ),
+ 'ShippingCountry' => Array (
+ 'type' => 'string', 'max_len' => 3,
+ 'formatter' => 'kOptionsFormatter',
+ 'options_sql' => ' SELECT IF(l%2$s_Name = "", l%3$s_Name, l%2$s_Name) AS Name, IsoCode
+ FROM ' . TABLE_PREFIX . 'CountryStates
+ WHERE Type = ' . DESTINATION_TYPE_COUNTRY . '
+ ORDER BY Name',
+ 'option_key_field' => 'IsoCode', 'option_title_field' => 'Name',
+ 'not_null' => 1, 'default' => ''
+ ),
+ 'PrimaryCurrencyId' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Currencies WHERE Status = 1 ORDER BY ISO', 'option_key_field' => 'CurrencyId', 'option_title_field' => 'Name', 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => 0
+ ),
+ 'Currencies' => Array (
+ 'type' => 'string', 'max_len' => 255,
+ 'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Currencies WHERE Status = 1 ORDER BY ISO', 'option_key_field' => 'CurrencyId', 'option_title_field' => 'Name', 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => ''
+ ),
+ 'PrimaryPaymentTypeId' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'PaymentTypes WHERE Status = 1 ORDER BY Name ASC', 'option_key_field' => 'PaymentTypeId', 'option_title_field' => 'Name',
+ 'not_null' => 1, 'default' => 0
+ ),
+ 'PaymentTypes' => Array (
+ 'type' => 'string', 'max_len' => 255,
+ 'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'PaymentTypes WHERE Status = 1 ORDER BY Name ASC', 'option_key_field' => 'PaymentTypeId', 'option_title_field' => 'Name',
+ 'not_null' => 1, 'default' => ''
+ ),
+ );
+
+ $fields = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'Fields');
+ $this->Application->setUnitOption($event->MasterEvent->Prefix, 'Fields', array_merge_recursive2($fields, $new_fields));
+
+ $new_columns = Array (
+ 'BillingCountry' => Array ('title' => 'la_col_BillingCountry', 'filter_block' => 'grid_options_filter', 'width' => 250, ),
+ 'ShippingCountry' => Array ('title' => 'la_col_ShippingCountry', 'filter_block' => 'grid_options_filter', 'width' => 250, ),
+ 'PrimaryCurrencyId' => Array ('title' => 'la_col_Currency', 'filter_block' => 'grid_options_filter', 'width' => 250, ),
+ 'PrimaryPaymentTypeId' => Array ('title' => 'la_col_PaymentType', 'filter_block' => 'grid_options_filter', 'width' => 250, ),
+ );
+
+ $grids = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'Grids');
+ $grids['Default']['Fields'] = array_merge_recursive2($grids['Default']['Fields'], $new_columns);
+ $this->Application->setUnitOption($event->MasterEvent->Prefix, 'Grids', $grids);
+
+ if (!$this->Application->isAdmin) {
+ // re-configure object, because it's recalled before kUnitConfigReader::AfterConfigRead is called
+ $this->Application->siteDomain->defineFields();
+ }
+ }
+
+ }