Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1026152
in-commerce
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jun 13, 9:14 PM
Size
40 KB
Mime Type
text/x-diff
Expires
Sun, Jun 15, 9:14 PM (6 h, 29 m)
Engine
blob
Format
Raw Data
Handle
661768
Attached To
rMINC Modules.In-Commerce
in-commerce
View Options
Index: branches/5.1.x/units/coupons/coupons_config.php
===================================================================
--- branches/5.1.x/units/coupons/coupons_config.php (revision 14148)
+++ branches/5.1.x/units/coupons/coupons_config.php (revision 14149)
@@ -1,181 +1,186 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
$config = Array(
'Prefix' => 'coup',
'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
'EventHandlerClass' => Array('class'=>'CouponsEventHandler','file'=>'coupons_event_handler.php','build_event'=>'OnBuild'),
'TagProcessorClass' => Array('class'=>'CouponsTagProcessor','file'=>'coupons_tag_processor.php','build_event'=>'OnBuild'),
'AutoLoad' => true,
'Hooks' => Array(
Array(
'Mode' => hBEFORE,
'Conditional' => false,
'HookToPrefix' => 'ord',
'HookToSpecial' => '',
'HookToEvent' => Array( 'OnUpdateCart', 'OnCheckout' ),
'DoPrefix' => '',
'DoSpecial' => '',
'DoEvent' => 'OnApplyCoupon',
),
),
'QueryString' => Array(
1 => 'id',
2 => 'Page',
3 => 'PerPage',
4 => 'event',
5 => 'mode',
),
'IDField' => 'CouponId',
'StatusField' => Array('Status'),
'TitleField' => 'Name',
'TableName' => TABLE_PREFIX.'ProductsCoupons',
'SubItems' => Array('coupi'),
'TitlePresets' => Array(
'default' => Array( 'new_status_labels' => Array('coup'=>'!la_title_Adding_Coupon!'),
'edit_status_labels' => Array('coup'=>'!la_title_Editing_Coupon!'),
'new_titlefield' => Array('coup'=>'!la_title_New_Coupon!'),
),
'coupons_list'=>Array('prefixes' => Array('coup_List'),
'format' => "!la_title_Coupons!",
),
'coupons_edit'=>Array( 'prefixes' => Array('coup'),
'format' => "#coup_status# '#coup_titlefield#' - !la_title_General!",
),
'coupons_items'=>Array('prefixes' => Array('coup','coupi_List'),
'format' => "#coup_status# '#coup_titlefield#' - !la_title_CouponItems!",
),
'coupons_clone'=>Array('prefixes' => Array('coup'),
'format' => "!la_CloneCoupon!",
),
'coupon_selector' => Array('format' => '!la_title_CouponSelector!'),
),
'EditTabPresets' => Array (
'Default' => Array (
'general' => Array ('title' => 'la_tab_General', 't' => 'in-commerce/discounts/coupon_edit', 'priority' => 1),
'items' => Array ('title' => 'la_tab_CouponsItems', 't' => 'in-commerce/discounts/coupon_items', 'priority' => 2),
),
),
'PermSection' => Array('main' => 'in-commerce:coupons'),
'Sections' => Array(
'in-commerce:coupons' => Array(
'parent' => 'in-commerce:discounts_folder',
'icon' => 'discounts_coupons',
'label' => 'la_tab_Coupons',
'url' => Array('t' => 'in-commerce/discounts/coupons_list', 'pass' => 'm'),
'permissions' => Array('view', 'add', 'edit', 'delete', 'advanced:approve', 'advanced:decline'),
'priority' => 3.2, // <parent_priority>.<own_priority>, because this section replaces parent in tree
'type' => stTAB,
),
),
'ListSQLs' => Array( ''=>'SELECT %1$s.* %2$s FROM %1$s',
), // key - special, value - list select sql
'ItemSQLs' => Array( ''=>'SELECT * FROM %1$s',
),
'ListSortings' => Array (
'' => Array(
'Sorting' => Array('Name' => 'asc'),
)
),
'Fields' => Array(
'CouponId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'Status' => Array (
'type' => 'int', 'formatter' => 'kOptionsFormatter',
'options' => Array ( 1 => 'la_Enabled', 2 => 'la_Used', 0 => 'la_Disabled' ),
'use_phrases' => 1, 'not_null' => 1, 'default' => 1
),
'Name' => Array ( 'type' =>'string', 'required' => 1, 'default' => null, 'max_len' => 255),
'Code' => Array (
'type' => 'string', 'required' => 1, 'default' => null,
'max_len' => 255, 'unique' => Array ('Code'),
),
'Expiration' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => null,),
'GroupId' => Array ('type' => 'int', 'default' => null, ),
'Type' => Array (
'type' => 'int', 'formatter' => 'kOptionsFormatter', 'use_phrases' => 1,
'options' => Array ( 1 => 'la_Flat', 2 => 'la_Percent'/*, 3 => 'la_FreeShipping'*/),
'not_null' => 1, 'default' => 1,
),
'Amount' => Array ('type' => 'double', 'default' => null),
'LastUsedBy' => Array (
'type' => 'int', 'formatter' => 'kLEFTFormatter',
'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'),
'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'),
'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'PortalUser
WHERE `%s` = \'%s\'','left_key_field'=>'PortalUserId',
'left_title_field' => 'Login', 'required' => 0, 'default' => null,
),
'LastUsedOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => NULL),
'NumberOfUses' => 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(
'default' => 'icon16_item.png',
0 => 'icon16_disabled.png',
1 => 'icon16_item.png',
2 => 'icon16_pending.png',
'module' => 'core',
),
'Fields' => Array(
'CouponId' => Array ('title'=>'la_col_Id', 'data_block' => 'grid_radio_td', 'filter_block' => 'grid_range_filter', 'width' => 60, ),
'Name' => Array( 'title'=>'la_col_Name', 'filter_block' => 'grid_like_filter', 'width' => 150, ),
'Code' => Array( 'title'=>'la_col_CouponCode', 'filter_block' => 'grid_like_filter', 'width' => 100, ),
'Expiration' => Array( 'title'=>'la_col_Expiration', 'filter_block' => 'grid_date_range_filter', 'width' => 145, ),
'Type' => Array( 'title'=>'la_col_Type', 'filter_block' => 'grid_options_filter', 'width' => 100, ),
'Status' => Array( 'title'=>'la_col_Status', 'filter_block' => 'grid_options_filter', 'width' => 100, ),
'Amount' => Array( 'title'=>'la_col_Amount', 'filter_block' => 'grid_float_range_filter', 'width' => 100, ),
'LastUsedBy' => Array('title'=>'la_col_LastUsedBy', 'filter_block' => 'grid_like_filter', 'width' => 140, ),
'LastUsedOn' => Array('title'=>'la_col_LastUsedOn', 'filter_block' => 'grid_date_range_filter', 'width' => 140, ),
'NumberOfUses' => Array('title'=>'la_col_NumberOfUses', 'filter_block' => 'grid_range_filter', 'width' => 130, ),
),
),
'Radio' => Array(
'Icons' => Array(
'default' => 'icon16_item.png',
0 => 'icon16_disabled.png',
1 => 'icon16_item.png',
2 => 'icon16_pending.png',
'module' => 'core',
),
'Fields' => Array(
'CouponId' => Array ('title'=>'la_col_Id', 'data_block' => 'grid_radio_td', 'filter_block' => 'grid_range_filter', 'width' => 60, ),
'Name' => Array( 'title'=>'la_col_Name', 'filter_block' => 'grid_like_filter', 'width' => 150, ),
'Code' => Array( 'title'=>'la_col_CouponCode', 'filter_block' => 'grid_like_filter', 'width' => 100, ),
'Expiration' => Array( 'title'=>'la_col_Expiration', 'filter_block' => 'grid_date_range_filter', 'width' => 145, ),
'Type' => Array( 'title'=>'la_col_Type', 'filter_block' => 'grid_options_filter', 'width' => 100, ),
'Status' => Array( 'title'=>'la_col_Status', 'filter_block' => 'grid_options_filter', 'width' => 100, ),
'Amount' => Array( 'title'=>'la_col_Amount', 'filter_block' => 'grid_float_range_filter', 'width' => 100, ),
'LastUsedBy' => Array('title'=>'la_col_LastUsedBy', 'filter_block' => 'grid_like_filter', 'width' => 140, ),
'LastUsedOn' => Array('title'=>'la_col_LastUsedOn', 'filter_block' => 'grid_date_range_filter', 'width' => 140, ),
'NumberOfUses' => Array('title'=>'la_col_NumberOfUses', 'filter_block' => 'grid_range_filter', 'width' => 130, ),
),
),
),
);
\ No newline at end of file
Index: branches/5.1.x/units/coupons/coupons_tag_processor.php
===================================================================
--- branches/5.1.x/units/coupons/coupons_tag_processor.php (revision 14148)
+++ branches/5.1.x/units/coupons/coupons_tag_processor.php (revision 14149)
@@ -1,38 +1,18 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class CouponsTagProcessor extends kDBTagProcessor {
- function LastCloneCount($params){
-
- $clone_count = $this->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/units/coupons/coupons_event_handler.php
===================================================================
--- branches/5.1.x/units/coupons/coupons_event_handler.php (revision 14148)
+++ branches/5.1.x/units/coupons/coupons_event_handler.php (revision 14149)
@@ -1,174 +1,240 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class CouponsEventHandler extends kDBEventHandler {
/**
* Allows to override standart permission mapping
*
*/
function mapPermissions()
{
parent::mapPermissions();
$permissions = Array(
'OnItemBuild' => 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);
-
- $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();
+ $this->StoreSelectedIDs($event);
+ $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);
+ }
+
+ $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);
- if ($validated){
- $this->finalizePopup($event);
- }else{
- $event->redirect = false;
+ $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{
$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...
*
* @param kEvent $event
*/
function OnApplyCoupon(&$event)
{
$code = $this->Application->GetVar('coupon_code');
if ($code == '') {
return ;
}
$object =& $event->getObject(Array('skip_autoload' => true));
$object->Load($code, 'Code');
if (!$object->isLoaded()) {
$event->status = erFAIL;
$this->Application->SetVar('set_checkout_error', 4);
$event->redirect = false; // check!!!
return ;
}
// $object->IDField = $this->Application->getUnitOption($event->Prefix, 'IDField');
// $object->ID = $object->GetDBField( $object->IDField );
$expire_date = $object->GetDBField('Expiration');
$number_of_use = $object->GetDBField('NumberOfUses');
if( $object->GetDBField('Status') != 1 || ($expire_date && $expire_date < adodb_mktime()) ||
(isset($number_of_use) && $number_of_use <= 0))
{
$event->status = erFAIL;
$this->Application->SetVar('set_checkout_error', 5);
$event->redirect->false;
return ;
}
$last_used = adodb_mktime();
$object->SetDBField('LastUsedBy', $this->Application->RecallVar('user_id'));
$object->SetDBField('LastUsedOn_date', $last_used);
$object->SetDBField('LastUsedOn_time', $last_used);
if(isset($number_of_use))
{
$object->SetDBField('NumberOfUses', $number_of_use - 1);
if($number_of_use == 1)
{
$object->SetDBField('Status', 2);
}
}
$object->Update();
$this->Application->setUnitOption('ord', 'AutoLoad', true);
$order =& $this->Application->recallObject('ord');
$order->SetDBField('CouponId', $object->GetDBField('CouponId'));
$order->Update();
$this->Application->SetVar('set_checkout_error', 10);
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnPreCreate(&$event){
parent::OnPreCreate($event);
$object = &$event->getObject();
$exp_date = adodb_mktime();
$default_duration = $this->Application->ConfigValue('Comm_DefaultCouponDuration');
if ($default_duration && $default_duration>0){
$exp_date += (int)$default_duration*86400;
}
$object->SetDBField('Expiration_date', $exp_date);
}
function OnBeforeItemUpdate(&$event)
{
$object =& $event->getObject();
$object->SetDBField( 'Amount', abs($object->GetDBField('Amount')) );
}
function OnBeforeItemCreate(&$event)
{
$this->OnBeforeItemUpdate($event);
}
}
\ No newline at end of file
Index: branches/5.1.x/units/coupon_items/coupon_items_config.php
===================================================================
--- branches/5.1.x/units/coupon_items/coupon_items_config.php (revision 14148)
+++ branches/5.1.x/units/coupon_items/coupon_items_config.php (revision 14149)
@@ -1,151 +1,150 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
$config = Array(
'Prefix' => 'coupi',
'ItemClass' => Array('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'),
'ListClass' => Array('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'),
'EventHandlerClass' => Array('class' => 'CouponItemsEventHandler', 'file' => 'coupon_items_event_handler.php', 'build_event' => 'OnBuild'),
'TagProcessorClass' => Array('class' => 'CouponItemsTagProcessor', 'file' => 'coupon_items_tag_processor.php', 'build_event' => 'OnBuild'),
'AutoLoad' => true,
'Hooks' => Array(
Array(
'Mode' => hAFTER,
'Conditional' => false,
'HookToPrefix' => 'p',
'HookToSpecial' => '-item',
'HookToEvent' => Array('OnAfterItemDelete'),
'DoPrefix' => '',
'DoSpecial' => '',
'DoEvent' => 'OnDeleteCouponItem',
),
),
'QueryString' => Array(
1 => 'id',
2 => 'Page',
3 => 'PerPage',
4 => 'event',
),
'IDField' => 'CouponItemId',
- 'StatusField' => Array('Status'),
- 'TitleField' => 'Name',
+ 'StatusField' => Array('Status'),
'TableName' => TABLE_PREFIX . 'ProductsCouponItems',
'ForeignKey' => 'CouponId',
'ParentTableKey' => 'CouponId',
'ParentPrefix' => 'coup',
'AutoDelete' => true,
'AutoClone' => true,
'ListSQLs' => Array(
'' => ' SELECT %1$s.* %2$s
FROM %1$s
LEFT JOIN ' . TABLE_PREFIX . 'Products p ON %1$s.ItemResourceId = p.ResourceId
LEFT JOIN ' . TABLE_PREFIX . 'Category c ON %1$s.ItemResourceId = c.ResourceId',
), // key - special, value - list select sql
'ItemSQLs' => Array(
'' => 'SELECT * FROM %s',
),
/*'BelongsTo' => Array(
Array(
'prefix' => 'd', 'key' => 'DiscountId', 'ForeignKey' => 'DiscountId'),
),*/
'ListSortings' => Array(
'' => Array(
'Sorting' => Array('ItemName' => 'asc'),
),
),
'CalculatedFields' => Array(
'' => Array(
'ProductId' => 'p.ProductId',
'ItemName' => 'IF(p.Name IS NULL,c.Name,p.l1_Name)',
'SKU' => 'p.SKU',
'Weight' => 'p.Weight',
'CreatedOn' => 'p.CreatedOn',
'BackOrderDate' => 'p.BackOrderDate',
'Status' => 'p.Status',
'CategoryId' => 'c.CategoryId',
),
),
'Fields' => Array (
'CouponItemId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0,),
'CouponId' => Array('type' => 'int', 'default' => null, ),
'ItemResourceId' => Array('type' => 'int', 'default' => null, ),
'ItemType' => Array(
'type' => 'int',
'formatter' => 'kOptionsFormatter',
'options' => Array (1 => 'la_Product', 2 => 'la_Category', 0 => 'la_WholeOrder'), 'use_phrases' => 1,
'not_null' => 1, 'default' => 1
),
),
'VirtualFields' => Array(
'ProductId' => Array('type' => 'int', 'default' => 0),
'ItemName' => Array('type' => 'string', 'default' => ''),
'SKU' => Array('type' => 'string', 'default' => ''),
'Weight' => Array(
'type' => 'float',
'formatter' => 'kFormatter', 'format' => '%0.2f',
'min_value_exc' => 0, 'default' => NULL,
),
'CreatedOn' => Array(
'type' => 'int',
'formatter' => 'kDateFormatter',
'default' => '#NOW#',
),
'BackOrderDate' => Array(
'type' => 'int',
'formatter' => 'kDateFormatter',
'default' => NULL,
),
'Status' => Array (
'type' => 'int',
'formatter' => 'kOptionsFormatter',
'options' => Array (1 => 'la_Active', 2 => 'la_Pending', 0 => 'la_Disabled'), 'use_phrases' => 1,
'default' => 2,
),
'CategoryId' => Array ('type' => 'int', 'default' => 0),
),
'Grids' => Array(
'Default' => Array(
'Icons' => Array('default'=>'icon16_entire_order.gif'),
'Fields' => Array(
'ItemType' => Array( 'title'=>'la_col_ItemType', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_empty_filter', 'width' => 200, ),
),
),
'CouponItems' => Array(
'Icons' => Array(
'default' => 'icon16_product.png',
0 => 'icon16_product_disabled.png',
1 => 'icon16_product.png',
2 => 'icon16_product_pending.png',
),
'Fields' => Array(
'ProductId' => Array( 'title'=>'la_col_Id', 'data_block' => 'grid_item_td', 'filter_block' => 'grid_range_filter', 'width' => 60, ),
'ItemName' => Array( 'title'=>'la_col_ItemName', 'filter_block' => 'grid_like_filter', 'width' => 250, ),
'ItemType' => Array( 'title'=>'la_col_CouponItemType', 'filter_block' => 'grid_options_filter', 'width' => 150, ),
),
),
),
);
\ No newline at end of file
Index: branches/5.1.x/units/gift_certificates/gift_certificates_eh.php
===================================================================
--- branches/5.1.x/units/gift_certificates/gift_certificates_eh.php (revision 14148)
+++ branches/5.1.x/units/gift_certificates/gift_certificates_eh.php (revision 14149)
@@ -1,256 +1,203 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class GiftCertificateEventHandler extends kDBEventHandler {
/**
* Allows to override standart permission mapping
*
*/
function mapPermissions()
{
parent::mapPermissions();
$permissions = Array(
'OnItemBuild' => Array('self' => true),
);
$this->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...
*
* @param kEvent $event
*/
function OnApplyGiftCertificate(&$event)
{
$code = $this->Application->GetVar('giftcert_code');
if ($code == '') {
return ;
}
$object =& $event->getObject(Array('skip_autoload' => true));
$object->Load($code, 'Code');
if (!$object->isLoaded()) {
$event->status = erFAIL;
$this->Application->SetVar('set_checkout_error', 104);
$event->redirect = false; // check!!!
return ;
}
$expire_date = $object->GetDBField('Expiration');
$debit = $object->GetDBField('Debit');
if( $object->GetDBField('Status') != 1 || ($expire_date && $expire_date < adodb_mktime()) ||
($debit <= 0))
{
$event->status = erFAIL;
$this->Application->SetVar('set_checkout_error', 105);
$event->redirect->false;
return ;
}
$this->Application->setUnitOption('ord', 'AutoLoad', true);
$order =& $this->Application->recallObject('ord');
$order->SetDBField('GiftCertificateId', $object->GetDBField('GiftCertificateId'));
$order->Update();
$this->Application->SetVar('set_checkout_error', 110);
}
/**
* Enter description here...
*
* @param kEvent $event
*/
function OnPreCreate(&$event)
{
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);
}
function OnBeforeItemUpdate(&$event)
{
$object =& $event->getObject();
/* @var $object kDBItem */
$amount = abs($object->GetDBField('Amount'));
$debit = abs($object->GetDBField('Debit'));
if ($debit > $amount) {
$debit = $amount;
}
$object->SetDBField('Amount', $amount);
$object->SetDBField('Debit', $debit);
if ($object->GetDBField('SendVia') == 1) {
// by postal mail
if ($this->Application->GetVar('email_certificate') == 0) {
$object->setRequired('RecipientEmail', false);
}
$cs_helper =& $this->Application->recallObject('CountryStatesHelper');
/* @var $cs_helper kCountryStatesHelper */
if (!$cs_helper->CountryHasStates($object->GetDBField('RecipientCountry'))) {
$object->setRequired('RecipientState', false);
}
$cs_helper->CheckStateField($event, 'RecipientState', 'RecipientCountry');
} else {
$non_required_fields = Array (
'RecipientState', 'RecipientCity', 'RecipientCountry',
'RecipientZipcode', 'RecipientAddress1', 'RecipientFirstname',
'RecipientLastname',
);
foreach ($non_required_fields as $non_required_field) {
$object->setRequired($non_required_field, false);
}
}
}
function OnBeforeItemCreate(&$event)
{
$this->OnBeforeItemUpdate($event);
$object =& $event->getObject();
/* @var $object kDBItem */
$object->SetDBField('Debit', $object->GetDBField('Amount'));
}
/**
* Print current gift certiicate
*
* @param kEvent $event
*/
function OnSave(&$event)
{
parent::OnSave($event);
if ($event->status == erSUCCESS) {
$object =& $event->getObject();
/* @var $object kDBItem */
if ($this->Application->GetVar('print_certificate') == 1) {
// get object id by unique field Code
$sql = 'SELECT '.$object->IDField.'
FROM '.$this->Application->GetLiveName($object->TableName).'
WHERE Code = '.$this->Conn->qstr($object->GetDBField('Code'));
$id = $this->Conn->GetOne($sql);
$this->Application->StoreVar('print_certificate_id', $id);
}
}
}
/**
* Email selected gift certificate
*
* @param kEvent $event
*/
function OnEmailGiftCertificate(&$event)
{
$ids = $this->StoreSelectedIDs($event);
if (!$ids) {
return ;
}
$object =& $event->getObject( Array ('skip_autoload' => true) );
/* @var $object kDBItem */
foreach ($ids as $id) {
$object->Load($id);
$send_params = Array (
'from_email' => $this->Application->ConfigValue('Smtp_AdminMailFrom'),
'from_name' => $object->GetDBField('Purchaser'),
'to_email' => $object->GetDBField('RecipientEmail'),
'to_name' => $object->GetDBField('Recipient'),
'message' => $object->GetDBField('Message'),
'amount' => $object->GetField('Amount'),
'gifcert_id' => $object->GetDBField('Code'),
);
$this->Application->EmailEventUser('USER.GIFTCERTIFICATE', null, $send_params);
$this->Application->EmailEventAdmin('USER.GIFTCERTIFICATE', null, $send_params);
}
$this->clearSelectedIDs($event);
}
}
\ No newline at end of file
Index: branches/5.1.x/units/gift_certificates/gift_certificates_tp.php
===================================================================
--- branches/5.1.x/units/gift_certificates/gift_certificates_tp.php (revision 14148)
+++ branches/5.1.x/units/gift_certificates/gift_certificates_tp.php (revision 14149)
@@ -1,70 +1,47 @@
<?php
/**
* @version $Id$
* @package In-Commerce
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license Commercial License
* This software is protected by copyright law and international treaties.
* Unauthorized reproduction or unlicensed usage of the code of this program,
* or any portion of it may result in severe civil and criminal penalties,
* and will be prosecuted to the maximum extent possible under the law
* See http://www.in-portal.org/commercial-license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class GiftCertificateTagProcessor extends kDBTagProcessor {
-
- function LastCloneCount($params)
- {
- $clone_count = $this->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)) {
return 0;
}
$object =& $this->getObject($params);
$sql = 'SELECT COUNT(OrderId)
FROM '.TABLE_PREFIX.'Orders
WHERE GiftCertificateId = '.$object->GetID();
return $this->Conn->GetOne($sql);
}
/**
* Print link for gift certificate (admin only)
*
* @param Array $params
*/
function PrintLink($params)
{
$params[$this->getPrefixSpecial().'_id'] = $this->Application->RecallVar('print_certificate_id');
$this->Application->RemoveVar('print_certificate_id');
$main_processor =& $this->Application->recallTagProcessor('m');
/* @var $main_processor kMainTagProcessor */
return $main_processor->Link($params);
}
}
\ No newline at end of file
Index: branches/5.1.x/admin_templates/discounts/coupons_list.tpl
===================================================================
--- branches/5.1.x/admin_templates/discounts/coupons_list.tpl (revision 14148)
+++ branches/5.1.x/admin_templates/discounts/coupons_list.tpl (revision 14149)
@@ -1,67 +1,67 @@
<inp2:m_include t="incs/header"/>
<inp2:m_RenderElement name="combined_header" prefix="coup" section="in-commerce:coupons" title_preset="coupons_list" pagination="1" tabs="in-commerce/discounts/discounts_list_tabs"/>
<!-- ToolBar -->
<table class="toolbar" height="30" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td>
<script type="text/javascript">
//do not rename - this function is used in default grid for double click!
function edit()
{
std_edit_item('coup', 'in-commerce/discounts/coupon_edit');
}
var a_toolbar = new ToolBar();
a_toolbar.AddButton( new ToolBarButton('new_item', '<inp2:m_phrase label="la_ToolTip_New_Coupon" escape="1"/>::<inp2:m_phrase label="la_ToolTip_Add" escape="1"/>',
function() {
std_precreate_item('coup', 'in-commerce/discounts/coupon_edit')
} ) );
a_toolbar.AddButton( new ToolBarButton('edit', '<inp2:m_phrase label="la_ToolTip_Edit" escape="1"/>', edit) );
a_toolbar.AddButton( new ToolBarButton('delete', '<inp2:m_phrase label="la_ToolTip_Delete" escape="1"/>',
function() {
std_delete_items('coup')
} ) );
a_toolbar.AddButton( new ToolBarButton('clone', '<inp2:m_phrase label="la_ToolTip_Clone" escape="1"/>',
function() {
//set_event('sc', 'OnSaveCreated');
- openSelector('coup', '<inp2:m_t t="in-commerce/discounts/coupon_clone_selector" pass="all"/>', '', '500x260');
+ openSelector('coup', '<inp2:m_Link template="in-commerce/discounts/coupon_clone_selector" pass="all"/>', '', '600x260', 'OnPrepareClone');
} ) );
a_toolbar.AddButton( new ToolBarSeparator('sep1') );
a_toolbar.AddButton( new ToolBarButton('approve', '<inp2:m_phrase label="la_ToolTip_Approve" escape="1"/>', function() {
submit_event('coup','OnMassApprove');
}
) );
a_toolbar.AddButton( new ToolBarButton('decline', '<inp2:m_phrase label="la_ToolTip_Decline" escape="1"/>', function() {
submit_event('coup','OnMassDecline');
}
) );
a_toolbar.AddButton( new ToolBarSeparator('sep2') );
a_toolbar.AddButton( new ToolBarButton('view', '<inp2:m_phrase label="la_ToolTip_View" escape="1"/>', function() {
show_viewmenu(a_toolbar,'view');
}
) );
a_toolbar.Render();
</script>
</td>
<inp2:m_RenderElement name="search_main_toolbar" prefix="coup" grid="Default"/>
</tr>
</tbody>
</table>
<inp2:m_RenderElement name="grid" PrefixSpecial="coup" IdField="CouponId" grid="Default"/>
<script type="text/javascript">
Grids['coup'].SetDependantToolbarButtons( new Array('edit','delete','approve','decline','clone') );
</script>
<inp2:m_include t="incs/footer"/>
\ No newline at end of file
Index: branches/5.1.x/admin_templates/discounts/coupon_clone_selector.tpl
===================================================================
--- branches/5.1.x/admin_templates/discounts/coupon_clone_selector.tpl (revision 14148)
+++ branches/5.1.x/admin_templates/discounts/coupon_clone_selector.tpl (revision 14149)
@@ -1,72 +1,40 @@
<inp2:m_include t="incs/header"/>
<inp2:m_RenderElement name="combined_header" prefix="coup" section="in-commerce:coupons" title_preset="coupons_clone"/>
<!-- ToolBar -->
<table class="toolbar" height="30" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td>
<script type="text/javascript">
a_toolbar = new ToolBar();
a_toolbar.AddButton( new ToolBarButton('select', '<inp2:m_phrase label="la_ToolTip_Save" escape="1"/>', function() {
submit_event('coup', 'OnApplyClone');
}
) );
a_toolbar.AddButton( new ToolBarButton('cancel', '<inp2:m_phrase label="la_ToolTip_Cancel" escape="1"/>', function() {
window_close();
}
) );
a_toolbar.Render();
</script>
</td>
</tr>
</tbody>
</table>
<inp2:coup_SaveWarning name="grid_save_warning"/>
<inp2:coup_ErrorWarning name="form_error_warning"/>
<div id="scroll_container">
<table class="edit-form">
- <tr class="<inp2:m_odd_even odd='edit-form-odd' even='edit-form-even'/>">
- <inp2:m_inc param="tab_index" by="1"/>
- <td class="label-cell">
- <label for="clone_items_count"><inp2:m_phrase label="la_EnterNumberOfCopies"/>:</label>
- </td>
- <td class="control-mid"> </td>
- <td class="control-cell">
- <input name="clone_items_count" id="clone_items_count" value="<inp2:coup_LastCloneCount />" size="5">
- </td>
- </tr>
- <tr class="<inp2:m_odd_even odd='edit-form-odd' even='edit-form-even'/>">
- <inp2:m_inc param="tab_index" by="1"/>
- <td class="label-cell">
- <inp2:m_Phrase label="la_Expiration" />:
- </td>
- <td class="control-mid"> </td>
- <td class="control-cell">
- <input type="text" name="clone_exp_date" id="clone_exp_date" value="<inp2:coup_DefaultExpDate />" datepickerIcon="<inp2:m_ProjectBase/>admin/images/ddarrow.gif" size="9">
- <span class="small">(mm.dd.yy)</span>
- <script type="text/javascript">
- initCalendar("clone_exp_date", "m.d.y");
- </script>
- <input type="text" name="clone_exp_time" id="clone_exp_time" value="<inp2:coup_DefaultExpTime />" size="9"><span class="small"> (h:mm:ss AM)</span>
- <br>
-
- </td>
- <inp2:m_RenderElement name="inp_edit_error" prefix="coup" field="Expiration"/>
- </tr>
+ <inp2:m_RenderElement name="inp_edit_box" prefix="coup" field="CouponCount" title="la_EnterNumberOfCopies" style="width: 50px;"/>
+ <inp2:m_RenderElement name="inp_edit_date_time" prefix="coup" field="DefaultExpiration" title="la_Expiration"/>
<inp2:m_RenderElement name="inp_edit_filler"/>
</table>
</div>
-<!-- <inp2:coup_HiddenSelection /> -->
-
-<inp2:m_include t="incs/footer"/>
-
-<script type="text/javascript">
- set_event('coup', '');
-</script>
\ No newline at end of file
+<inp2:m_include t="incs/footer"/>
\ No newline at end of file
Event Timeline
Log In to Comment