Index: branches/5.1.x/admin_templates/discounts/coupon_clone_selector.tpl
===================================================================
diff -u -r13100 -r14149
--- branches/5.1.x/admin_templates/discounts/coupon_clone_selector.tpl (.../coupon_clone_selector.tpl) (revision 13100)
+++ branches/5.1.x/admin_templates/discounts/coupon_clone_selector.tpl (.../coupon_clone_selector.tpl) (revision 14149)
@@ -31,42 +31,10 @@
-
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
Index: branches/5.1.x/units/coupons/coupons_event_handler.php
===================================================================
diff -u -r13100 -r14149
--- branches/5.1.x/units/coupons/coupons_event_handler.php (.../coupons_event_handler.php) (revision 13100)
+++ branches/5.1.x/units/coupons/coupons_event_handler.php (.../coupons_event_handler.php) (revision 14149)
@@ -1,6 +1,6 @@
Array('self' => true),
+ 'OnApplyClone' => Array('self' => 'add'),
+ 'OnPrepareClone' => Array('self' => 'view'),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
}
-
- function OnApplyClone(&$event)
+ /**
+ * Prepares coupon cloning
+ *
+ * @param kEvent $event
+ */
+ function OnPrepareClone(&$event)
{
- $item = &$event->getObject();
- $clone_count = $this->Application->GetVar('clone_items_count');
- $table = $this->Application->getUnitOption($event->Prefix, 'TableName');
- if ($clone_count && $clone_count>0){
- $this->Application->StoreVar('CoupLastCloneCount', $clone_count);
- for ($i=0; $i<$clone_count; $i++) {
- $this->SetNewCode($item);
+ $this->StoreSelectedIDs($event);
- $item->SetField('Expiration_date', $this->Application->GetVar('clone_exp_date'));
- $item->SetField('Expiration_time', $this->Application->GetVar('clone_exp_time'));
- $item->NameCopy();
- $validated = $item->Create();
+ $event->CallSubEvent('OnNew');
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
- }
+ $this->setCloningRequired($object);
+ $clone_count = $this->Application->RecallVar('CoupLastCloneCount');
+
+ if ( is_numeric($clone_count) && $clone_count > 0 ) {
+ $object->SetDBField('CouponCount', $clone_count);
}
- if ($validated){
- $this->finalizePopup($event);
- }else{
- $event->redirect = false;
+ $expire_days = $this->Application->ConfigValue('Comm_DefaultCouponDuration');
+ $default_expiration = strtotime('+' . $expire_days . ' days');
+
+ $object->SetDBField('DefaultExpiration_date', $default_expiration);
+ $object->SetDBField('DefaultExpiration_time', $default_expiration);
+ }
+
+
+ function OnBeforeClone(&$event)
+ {
+ parent::OnBeforeClone($event);
+
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ $this->SetNewCode($object);
+
+ $object->SetDBField('LastUsedBy', NULL);
+ $object->SetDBField('LastUsedOn', NULL);
+ $object->SetDBField('NumberOfUses', NULL);
+
+ $expiration = $this->Application->GetVar('clone_coupon_expiration');
+ $object->SetDBField('Expiration_date', $expiration);
+ $object->SetDBField('Expiration_time', $expiration);
+ }
+
+ function OnApplyClone(&$event)
+ {
+ if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) {
+ $event->status = erFAIL;
+ return;
}
+
+ $object =& $event->getObject( Array ('skip_autoload' => true) );
+ /* @var $object kDBItem */
+
+ $this->setCloningRequired($object);
+
+ $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
+ list($id, $field_values) = each($items_info);
+ $object->SetFieldsFromHash($field_values);
+ $object->setID($id);
+
+ if ( !$object->Validate() ) {
+ $event->status = erFAIL;
+ return ;
+ }
+
+ $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler');
+ /* @var $temp kTempTablesHandler */
+
+ $original_coupon_ids = $this->getSelectedIDs($event, true);
+ $clone_count = $object->GetDBField('CouponCount');
+ $this->Application->StoreVar('CoupLastCloneCount', $clone_count);
+ $this->Application->SetVar('clone_coupon_expiration', $object->GetDBField('DefaultExpiration'));
+
+ for ($i = 0; $i < $clone_count; $i++) {
+ $temp->CloneItems($event->Prefix, $event->Special, $original_coupon_ids);
+ }
+
+ $this->finalizePopup($event);
}
+ function setCloningRequired(&$object)
+ {
+ $this->RemoveRequiredFields($object);
+ $object->setRequired('CouponCount');
+ $object->setRequired('DefaultExpiration');
+ }
+
function SetNewCode(&$item)
{
do{
Index: branches/5.1.x/units/coupon_items/coupon_items_config.php
===================================================================
diff -u -r14028 -r14149
--- branches/5.1.x/units/coupon_items/coupon_items_config.php (.../coupon_items_config.php) (revision 14028)
+++ branches/5.1.x/units/coupon_items/coupon_items_config.php (.../coupon_items_config.php) (revision 14149)
@@ -1,6 +1,6 @@
'CouponItemId',
- 'StatusField' => Array('Status'),
- 'TitleField' => 'Name',
+ 'StatusField' => Array('Status'),
'TableName' => TABLE_PREFIX . 'ProductsCouponItems',
'ForeignKey' => 'CouponId',
Index: branches/5.1.x/units/gift_certificates/gift_certificates_tp.php
===================================================================
diff -u -r13100 -r14149
--- branches/5.1.x/units/gift_certificates/gift_certificates_tp.php (.../gift_certificates_tp.php) (revision 13100)
+++ branches/5.1.x/units/gift_certificates/gift_certificates_tp.php (.../gift_certificates_tp.php) (revision 14149)
@@ -1,6 +1,6 @@
Application->RecallVar('CoupLastCloneCount');
- if (!$clone_count){
- $clone_count = 1;
- }
- return $clone_count;
- }
-
- function DefaultExpDate($params)
- {
- $object = &$this->Application->recallObject($this->getPrefixSpecial());
- $formatter =& $this->Application->makeClass('kDateFormatter');
- return $formatter->Format( adodb_mktime() + $this->Application->ConfigValue('Comm_DefaultCouponDuration') * 3600 * 24, 'Expiration_date', $object);
- }
-
- function DefaultExpTime($params)
- {
- $object = &$this->Application->recallObject($this->getPrefixSpecial());
- $formatter =& $this->Application->makeClass('kDateFormatter');
- return $formatter->Format( adodb_mktime() + $this->Application->ConfigValue('Comm_DefaultCouponDuration') * 3600 * 24, 'Expiration_time', $object);
- }
-
+
function HasOrder($params)
{
if ($this->IsNewItem($params)) {
Index: branches/5.1.x/units/coupons/coupons_config.php
===================================================================
diff -u -r13938 -r14149
--- branches/5.1.x/units/coupons/coupons_config.php (.../coupons_config.php) (revision 13938)
+++ branches/5.1.x/units/coupons/coupons_config.php (.../coupons_config.php) (revision 14149)
@@ -1,6 +1,6 @@
Array ('type' => 'int', 'default' => 1),
),
+ 'VirtualFields' => Array (
+ 'CouponCount' => Array ('type' => 'int', 'min_value_inc' => 1, 'default' => 1),
+ 'DefaultExpiration' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => NULL),
+ ),
+
'Grids' => Array(
'Default' => Array(
'Icons' => Array(
Index: branches/5.1.x/units/coupons/coupons_tag_processor.php
===================================================================
diff -u -r13100 -r14149
--- branches/5.1.x/units/coupons/coupons_tag_processor.php (.../coupons_tag_processor.php) (revision 13100)
+++ branches/5.1.x/units/coupons/coupons_tag_processor.php (.../coupons_tag_processor.php) (revision 14149)
@@ -1,6 +1,6 @@
Application->RecallVar('CoupLastCloneCount');
- if (!$clone_count){
- $clone_count = 1;
- }
- return $clone_count;
- }
-
- function DefaultExpDate($params){
- $object = &$this->Application->recallObject($this->getPrefixSpecial());
- $formatter =& $this->Application->makeClass('kDateFormatter');
- return $formatter->Format( adodb_mktime() + $this->Application->ConfigValue('Comm_DefaultCouponDuration') * 3600 * 24, 'Expiration_date', $object);
- }
-
- function DefaultExpTime($params){
- $object = &$this->Application->recallObject($this->getPrefixSpecial());
- $formatter =& $this->Application->makeClass('kDateFormatter');
- return $formatter->Format( adodb_mktime() + $this->Application->ConfigValue('Comm_DefaultCouponDuration') * 3600 * 24, 'Expiration_time', $object);
- }
}
\ No newline at end of file
Index: branches/5.1.x/admin_templates/discounts/coupons_list.tpl
===================================================================
diff -u -r13938 -r14149
--- branches/5.1.x/admin_templates/discounts/coupons_list.tpl (.../coupons_list.tpl) (revision 13938)
+++ branches/5.1.x/admin_templates/discounts/coupons_list.tpl (.../coupons_list.tpl) (revision 14149)
@@ -28,7 +28,7 @@
a_toolbar.AddButton( new ToolBarButton('clone', '',
function() {
//set_event('sc', 'OnSaveCreated');
- openSelector('coup', '', '', '500x260');
+ openSelector('coup', '', '', '600x260', 'OnPrepareClone');
} ) );
a_toolbar.AddButton( new ToolBarSeparator('sep1') );
Index: branches/5.1.x/units/gift_certificates/gift_certificates_eh.php
===================================================================
diff -u -r13100 -r14149
--- branches/5.1.x/units/gift_certificates/gift_certificates_eh.php (.../gift_certificates_eh.php) (revision 13100)
+++ branches/5.1.x/units/gift_certificates/gift_certificates_eh.php (.../gift_certificates_eh.php) (revision 14149)
@@ -1,6 +1,6 @@
permMapping = array_merge($this->permMapping, $permissions);
}
- function OnApplyClone(&$event)
- {
- $item = &$event->getObject();
- $clone_count = $this->Application->GetVar('clone_items_count');
- $table = $this->Application->getUnitOption($event->Prefix, 'TableName');
- if ($clone_count && $clone_count>0){
- $this->Application->StoreVar('CoupLastCloneCount', $clone_count);
- for ($i=0; $i<$clone_count; $i++) {
- $this->SetNewCode($item);
-
- $item->SetField('Expiration_date', $this->Application->GetVar('clone_exp_date'));
- $item->SetField('Expiration_time', $this->Application->GetVar('clone_exp_time'));
- $item->NameCopy();
- $validated = $item->Create();
-
-
- }
- }
-
- if ($validated){
- $this->finalizePopup($event);
- }else{
- $event->redirect = false;
- }
- }
-
- function SetNewCode(&$item)
- {
- do{
- $new_code = $this->RandomCouponCode(10);
- $exists = $this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'ProductsCoupons WHERE Code='.$this->Conn->qstr($new_code));
- if ($exists){
- $new_code = false;
- }
- } while (!$new_code);
-
- $item->SetDBField('Code', $new_code);
- }
-
- function RandomCouponCode($size)
- {
- $rand_code = "";
- for ($i=0; $i<10; $i++){
- $is_letter = rand(0,1);
- if ($is_letter){
- $rand_char = chr(rand(65,90));
- }else{
- $rand_char = rand(0,9);
- }
- $rand_code .= $rand_char;
- }
- return $rand_code;
- }
-
/**
* Enter description here...
*
@@ -133,12 +79,13 @@
{
parent::OnPreCreate($event);
- $object = &$event->getObject();
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
$exp_date = adodb_mktime();
-
$default_duration = $this->Application->ConfigValue('Comm_DefaultCouponDuration');
-
- if ($default_duration && $default_duration > 0){
+
+ if ($default_duration){
$exp_date += (int)$default_duration * 86400;
}
$object->SetDBField('Expiration_date', $exp_date);