Exemple #1
0
		private function _CommitDiscount($DiscountId=0)
		{
			require_once(ISC_BASE_PATH.'/lib/api/discount.api.php');
			$discount = new API_DISCOUNT();
			$freeShippingMesgLocation = array();

			if ($DiscountId != 0) {
				$discount->load($DiscountId);
			}

			$_POST['discountmaxuses'] = 0;
			if (isset($_POST['discountruleexpiresuses'])) {
				$_POST['discountmaxuses'] = $_POST['discountruleexpiresusesamount'];
			}

			$_POST['discountcurrentuses'] =  0;

			$query = sprintf("select max(sortorder) from [|PREFIX|]discounts");
			$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
			$row = $GLOBALS['ISC_CLASS_DB']->Fetch($result);

			$_POST['discountenabled'] =  0;
			if (isset($_POST['enabled'])) {
				$_POST['discountenabled'] =  1;
			}

			$_POST['discountexpiry'] = 0;
			if (isset($_POST['discountruleexpiresdateamount']) && !empty($_POST['discountruleexpiresdateamount'])) {
				$_POST['discountexpiry'] = ConvertDateToTime($_POST['discountruleexpiresdateamount']);
			}

			$_POST['discountruletype'] = 0;
			$_POST['free_shipping_message'] = '';
			if (isset($_POST['RuleType']) && !empty($_POST['RuleType'])) {
				$_POST['discountruletype'] = $_POST['RuleType'];

				// if the selected rule related to free shipping, we will be collecting
				// additional message here.
				if (in_array($_POST['RuleType'], array('rule_buyxgetfreeshipping', 'rule_freeshippingwhenoverx'))) {
					if (!empty ($_POST['FreeShippingMessage']) && !empty ($_POST['ShowFreeShippingMesgOn'])) {
						$_POST['free_shipping_message'] = $_POST['FreeShippingMessage'];
						$freeShippingMesgLocation = $_POST['ShowFreeShippingMesgOn'];
					}

				}
			}

			$_POST['configdata'] = '';
			$cd = array();

			foreach($_POST as $module_id => $vars) {

				// Checkout variables start with checkout_
				if (isc_substr($module_id, 0, 4) != "var_" && isc_substr($module_id,0,5) != "varn_") {
					continue;
				}

				if (is_array($vars)) {
					$vars = implode(',', $vars);
				}

				if (isc_substr($module_id,0,5) == "varn_") {
					$vars = DefaultPriceFormat($vars);
				}

				$cd[isc_html_escape($module_id)] = isc_html_escape($vars);
			}

			$_POST['configdata'] = serialize($cd);
			$_POST['free_shipping_message_location'] = serialize($freeShippingMesgLocation);

			GetModuleById('rule', $ruleModule, $_POST['discountruletype']);
			if(!is_object($ruleModule)) {
				// Something really bad went wrong >_<
				return 'Rule Type Doesn\'t Exist';
			}

			if($DiscountId == 0) {
				$_POST['sortorder'] = $row['max(sortorder)']+1;
				$DiscountId = $discount->create();
			}
			else {
				$_POST['sortorder'] = $discount->getSortOrder();
				$discount->save();
			}

			return $discount->error;
		}
 private function _CommitDiscount($DiscountId = 0)
 {
     require_once ISC_BASE_PATH . '/lib/api/discount.api.php';
     $discount = new API_DISCOUNT();
     if ($DiscountId != 0) {
         $discount->load($DiscountId);
     }
     $_POST['discountmaxuses'] = 0;
     if (isset($_POST['discountruleexpiresuses'])) {
         $_POST['discountmaxuses'] = $_POST['discountruleexpiresusesamount'];
     }
     $_POST['discountcurrentuses'] = 0;
     $query = sprintf("select max(sortorder) from [|PREFIX|]discounts");
     $result = $GLOBALS['ISC_CLASS_DB']->Query($query);
     $row = $GLOBALS['ISC_CLASS_DB']->Fetch($result);
     $_POST['discountenabled'] = 0;
     if (isset($_POST['enabled'])) {
         $_POST['discountenabled'] = 1;
     }
     $_POST['discountexpiry'] = 0;
     if (isset($_POST['discountruleexpiresdateamount']) && !empty($_POST['discountruleexpiresdateamount'])) {
         $_POST['discountexpiry'] = ConvertDateToTimeWithHours($_POST['discountruleexpiresdateamount'], $_POST['discountruleexpireshoursamount']);
     }
     $_POST['discountstart'] = 0;
     if (isset($_POST['discountrulestartsdateamount']) && !empty($_POST['discountrulestartsdateamount'])) {
         $_POST['discountstart'] = ConvertDateToTimeWithHours($_POST['discountrulestartsdateamount'], $_POST['discountrulestartshoursamount']);
     }
     $_POST['discountruletype'] = 0;
     if (isset($_POST['RuleType']) && !empty($_POST['RuleType'])) {
         $_POST['discountruletype'] = $_POST['RuleType'];
     }
     $_POST['configdata'] = '';
     $cd = array();
     foreach ($_POST as $module_id => $vars) {
         // Checkout variables start with checkout_
         if (isc_substr($module_id, 0, 4) != "var_" && isc_substr($module_id, 0, 5) != "varn_") {
             continue;
         }
         if (is_array($vars)) {
             $vars = implode(',', $vars);
         }
         if (isc_substr($module_id, 0, 5) == "varn_") {
             $vars = DefaultPriceFormat($vars);
         }
         $cd[isc_html_escape($module_id)] = isc_html_escape($vars);
     }
     $_POST['configdata'] = serialize($cd);
     GetModuleById('rule', $ruleModule, $_POST['discountruletype']);
     if (!is_object($ruleModule)) {
         // Something really bad went wrong >_<
         return 'Rule Type Doesn\'t Exist';
     }
     if ($DiscountId == 0) {
         $_POST['sortorder'] = $row['max(sortorder)'] + 1;
         $DiscountId = $discount->create();
     } else {
         $_POST['sortorder'] = $discount->getSortOrder();
         $discount->save();
     }
     // calling the background process to update the price of the products under the discount
     if ($_POST['discountruletype'] == 'rule_percentoffitemsinseries' || $_POST['discountruletype'] == 'rule_percentoffitemsincat') {
         $this->UpdatePriceInBackground($DiscountId);
     }
     return $discount->error;
 }