Пример #1
0
 /**
  * main action
  */
 public function mainAction()
 {
     if (!is_numeric($this->GET['promotion_id'])) {
         msg("Onxshop_Controller_Component_Ecommerce_Gift_Voucher_Generate: promotion_id isn't numeric");
         return false;
     }
     $promotion_id = $this->GET['promotion_id'];
     if ($gift_voucher_product_id = $this->getGiftVoucherProductId($order_id)) {
         require_once 'models/ecommerce/ecommerce_promotion.php';
         $Promotion = new ecommerce_promotion();
         $Promotion->setCacheable(false);
         $promotion_data = $Promotion->getDetail($promotion_id);
         if ($promotion_data) {
             $gift_voucher_directory = ONXSHOP_PROJECT_DIR . "var/vouchers/";
             $gift_voucher_filename = "{$promotion_data['code_pattern']}.png";
             $gift_voucher_filename_fullpath = $gift_voucher_directory . $gift_voucher_filename;
             $voucher_data = array();
             $voucher_data['recipient_name'] = $promotion_data['other_data']['recipient_name'];
             $voucher_data['recipient_email'] = $promotion_data['other_data']['recipient_email'];
             $voucher_data['message'] = $promotion_data['other_data']['message'];
             $voucher_data['sender_name'] = $promotion_data['other_data']['sender_name'];
             if ($promotion_data['other_data']['delivery_date']) {
                 $voucher_data['delivery_date'] = $promotion_data['other_data']['delivery_date'];
             }
             $this->sendEmail($promotion_data, $voucher_data, $gift_voucher_filename);
             msg("Email sent");
         }
     }
     return true;
 }
Пример #2
0
 /**
  * calculateDiscountAndDelivery
  */
 protected function calculateDiscountAndDelivery(&$basket)
 {
     $Delivery = new ecommerce_delivery();
     // order exists?
     if ($this->orderFinished($basket['id'], $this->GET['order_id'])) {
         $Promotion = new ecommerce_promotion();
         $Promotion->setCacheable(false);
         // get data from database
         $code = $Promotion->getPromotionCodeForOrder($this->GET['order_id']);
         $verify_code = false;
         $this->Basket->calculateBasketDiscount($basket, $code, $verify_code);
         $basket['delivery'] = $Delivery->getDeliveryByOrderId($this->GET['order_id']);
     } else {
         // calculate data
         $code = $_SESSION['promotion_code'];
         $verify_code = true;
         $promotion_detail = $this->Basket->calculateBasketDiscount($basket, $code, $verify_code);
         $this->Basket->saveDiscount($basket);
         if ($this->guest_customer) {
             $basket['delivery'] = $Delivery->calculateDeliveryForCountry($basket, $this->delivery_options['carrier_id'], $this->delivery_country, $promotion_detail);
         } else {
             $basket['delivery'] = $Delivery->calculateDelivery($basket, $this->delivery_options['carrier_id'], $this->delivery_address_id, $promotion_detail);
         }
         // this only applies when using wizard checkout
         if ($basket['delivery'] == false) {
             $this->redirectToDeliveryOptionsPage();
         }
     }
 }
Пример #3
0
 /**
  * main action
  */
 public function mainAction()
 {
     require_once 'models/ecommerce/ecommerce_promotion.php';
     $Promotion = new ecommerce_promotion();
     /**
      * Save on request
      */
     if (is_array($_POST['promotion'])) {
         $_POST['promotion']['type'] = 1;
         // can add discount coupon only
         if ($Promotion->addPromotion($_POST['promotion'])) {
             //onxshopGoTo("/backoffice/marketing");
             msg('Inserted');
         } else {
             msg('Insert failed', 'error');
         }
     }
     /**
      * Display Detail
      */
     if (count($_POST['promotion']) > 0) {
         $this->tpl->assign('PROMOTION', $_POST['promotion']);
     }
     return true;
 }
Пример #4
0
 /**
  * Reward inviting user if referrer voucher code has been used
  */
 public function referrerVoucherAction($order_id, $status)
 {
     if (!is_numeric($order_id) || !is_numeric($status)) {
         return false;
     }
     require_once "models/ecommerce/ecommerce_promotion.php";
     $Promotion = new ecommerce_promotion();
     $Promotion->rewardInvitingUser($order_id);
     return true;
 }
 /**
  * insert promotion code (apply promotion code)
  */
 public function insertPromotionCode($code, $order_id)
 {
     require_once 'models/ecommerce/ecommerce_promotion.php';
     $Promotion = new ecommerce_promotion();
     if ($compaign_data = $Promotion->checkCodeMatch($code)) {
         $data = array();
         $data['promotion_id'] = $compaign_data['id'];
         $data['code'] = $code;
         $data['order_id'] = $order_id;
         if ($inserted_code_id = $this->insert($data)) {
             return $inserted_code_id;
         }
     }
     return false;
 }
Пример #6
0
 /**
  * initialise models
  */
 protected function initModels()
 {
     $this->conf = ecommerce_promotion::initConfiguration();
     $this->Promotion = new ecommerce_promotion();
     $this->Promotion->setCacheable(false);
     $this->Promotion_Code = new ecommerce_promotion_code();
     $this->Promotion_Code->setCacheable(false);
     $this->Customer = new client_customer();
     $this->Customer->setCacheable(false);
 }
Пример #7
0
 /**
  * generateSingleVoucher
  */
 public function generateSingleVoucher($voucher_basket_item)
 {
     if (!is_array($voucher_basket_item)) {
         return false;
     }
     $voucher_data = array();
     $voucher_data['variety_id'] = $voucher_basket_item['product_variety_id'];
     $voucher_data['recipient_name'] = $voucher_basket_item['other_data']['recipient_name'];
     $voucher_data['recipient_email'] = $voucher_basket_item['other_data']['recipient_email'];
     $voucher_data['message'] = $voucher_basket_item['other_data']['message'];
     $voucher_data['sender_name'] = $voucher_basket_item['other_data']['sender_name'];
     if ($voucher_basket_item['other_data']['delivery_date']) {
         $voucher_data['delivery_date'] = $voucher_basket_item['other_data']['delivery_date'];
     }
     if (!$this->validateData($voucher_data)) {
         msg("Voucher data are not valid", 'error');
         return false;
     }
     /**
      * create discount code
      */
     $code_pattern_base = "GIFT-{$voucher_basket_item['id']}" . '-';
     $promotion_data = array();
     $promotion_data['type'] = 4;
     // Gift Voucher
     $promotion_data['code_pattern'] = $code_pattern_base . $this->randomCode();
     $promotion_data['title'] = $promotion_data['code_pattern'];
     $promotion_data['discount_percentage_value'] = 0;
     $promotion_data['discount_fixed_value'] = $voucher_basket_item['total'];
     $promotion_data['uses_per_coupon'] = $voucher_basket_item['quantity'];
     $promotion_data['other_data'] = $voucher_basket_item['other_data'];
     $promotion_data['publish'] = 1;
     $promotion_data['generated_by_order_id'] = $this->GET['order_id'];
     require_once 'models/ecommerce/ecommerce_promotion.php';
     $Promotion = new ecommerce_promotion();
     $Promotion->setCacheable(false);
     //TODO: check if the code wasn't generated before for the same order
     if ($Promotion->checkCodeMatchPartially($code_pattern_base)) {
         msg("Code {$code_pattern_base}* was previously generated", 'error');
         return false;
     }
     //preg_match("/GIFT-{$voucher_basket_item['id']}/", $all_patterns_list)
     if ($promotion_id = $Promotion->addPromotion($promotion_data)) {
         msg("Promotion code {$promotion_data['code_pattern']} generated as promotion ID {$promotion_id}", 'ok', 1);
     } else {
         msg('Promotion code generation failed', 'error');
         //return false;
     }
     /**
      * create the voucher file
      */
     $url = "http://{$_SERVER['SERVER_NAME']}/request/sys/html5.node/site/print.component/ecommerce/gift_voucher~voucher_code={$promotion_data['code_pattern']}~";
     $gift_voucher_directory = ONXSHOP_PROJECT_DIR . "var/vouchers/";
     $gift_voucher_filename = "{$promotion_data['code_pattern']}.png";
     $gift_voucher_filename_fullpath = $gift_voucher_directory . $gift_voucher_filename;
     //check directory exits
     if (!is_dir($gift_voucher_directory)) {
         mkdir($gift_voucher_directory);
     }
     $shell_command = "wkhtmltoimage {$url} {$gift_voucher_filename_fullpath}";
     if ($result = local_exec($shell_command)) {
         msg("File {$gift_voucher_filename_fullpath} generated by wkhtmltoimage", 'ok', 1);
     }
     /**
      * send email
      * postpone if delivery_date is set
      */
     if (preg_match("/[0-9]{1,2}\\/[0-9]{1,2}\\/[0-9]{4}/", $voucher_data['delivery_date'])) {
         $this->postponeDelivery($promotion_id, $voucher_data['delivery_date']);
     } else {
         $this->sendEmail($promotion_data, $voucher_data, $gift_voucher_filename);
     }
     return true;
 }
Пример #8
0
 /**
  * apply discount code
  * requires basket full detail with calculated sub totals
  */
 public function calculateBasketDiscount(&$basket, $code, $check_code = true)
 {
     $promotion_data = false;
     $basket['face_value_voucher'] = 0;
     $basket['face_value_voucher_claim'] = 0;
     $basket['discount'] = 0;
     $basket['discount_fixed_claim'] = 0;
     $basket['discount_percentage_claim'] = 0;
     foreach ($basket['items'] as &$item) {
         $item['discount'] = 0;
     }
     if ($code) {
         require_once 'models/ecommerce/ecommerce_promotion.php';
         $Promotion = new ecommerce_promotion();
         $Promotion->setCacheable(false);
         if ($check_code) {
             $promotion_data = $Promotion->checkCodeBeforeApply($code, $basket['customer_id'], $basket);
         } else {
             $promotion_data = $Promotion->checkCodeMatch($code);
         }
         if ($promotion_data) {
             $promotion_data['discount_fixed_value'] = ecommerce_price::convertCurrency($promotion_data['discount_fixed_value'], GLOBAL_DEFAULT_CURRENCY, $basket['currency']);
             if ($promotion_data['type']['taxable']) {
                 $this->calculateVoucherDiscount($basket, $promotion_data);
             } else {
                 $this->calculateCouponDiscount($basket, $promotion_data);
             }
         }
     }
     return $promotion_data;
 }
Пример #9
0
 /**
  * get promotion code
  */
 function getPromotionCode($order_id)
 {
     if (!is_numeric($order_id)) {
         return false;
     }
     require_once 'models/ecommerce/ecommerce_promotion.php';
     $Promotion = new ecommerce_promotion();
     return $Promotion->getPromotionCodeForOrder($order_id);
 }
Пример #10
0
 /**
  * main action
  */
 public function mainAction()
 {
     /**
      * find code
      */
     if ($_SESSION['promotion_code']) {
         $code = $_SESSION['promotion_code'];
     } else {
         if (trim($_POST['promotion_code']) != '') {
             $code = trim($_POST['promotion_code']);
         } else {
             $code = false;
         }
     }
     /**
      * Check Actions
      */
     if ($_POST['promotion_code_add'] && $code) {
         $_SESSION['promotion_code'] = $code;
         onxshopGoTo("/page/{$_SESSION['active_pages'][0]}");
     } else {
         if ($_POST['promotion_code_remove']) {
             $_SESSION['promotion_code'] = false;
             onxshopGoTo("/page/{$_SESSION['active_pages'][0]}");
         }
     }
     /**
      * initialize
      */
     require_once 'models/ecommerce/ecommerce_promotion.php';
     $Promotion = new ecommerce_promotion();
     $Promotion->setCacheable(false);
     require_once 'models/ecommerce/ecommerce_basket.php';
     $Basket = new ecommerce_basket();
     $Basket->setCacheable(false);
     /**
      * basket detail
      */
     if (is_numeric($_SESSION['basket']['id'])) {
         $basket = $Basket->getFullDetail($_SESSION['basket']['id']);
         $Basket->calculateBasketSubTotals($basket, $this->isVatEligible($basket['customer_id']));
         $Basket->calculateBasketDiscount($basket, $_SESSION['promotion_code']);
         $Basket->saveDiscount($basket);
     } else {
         $basket = false;
     }
     /**
      * Allow Guest Checkout
      */
     if ($basket['customer_id'] == 0 && $_SESSION['client']['customer']['guest'] == 1) {
         $customer_email = $_SESSION['client']['customer']['email'];
     } else {
         $customer_email = '';
     }
     /**
      * Display
      */
     if ($basket && ($promotion_code = $Promotion->checkCodeBeforeApply($code, $basket['customer_id'], $basket, $customer_email))) {
         $promotion_code['value'] = $code;
         $this->tpl->assign('PROMOTION_CODE', $promotion_code);
         if ($promotion_code['discount_percentage_value'] > 0) {
             $this->tpl->parse('content.applied.discount_percentage_value');
         }
         if ($promotion_code['discount_fixed_value'] > 0) {
             $this->tpl->parse('content.applied.discount_fixed_value');
         }
         if ($promotion_code['discount_free_delivery'] == 1) {
             $this->tpl->parse('content.applied.discount_free_delivery');
         }
         if ($promotion_code['free_promo_product']) {
             $this->tpl->parse('content.applied.free_item_info');
         }
         $this->tpl->parse('content.applied');
     } else {
         //remove code
         $code = false;
         $promotion_code = array();
         $promotion_code['value'] = $code;
         $this->tpl->assign('PROMOTION_CODE', $promotion_code);
         $this->tpl->parse('content.enter');
     }
     /**
      * Save to session
      */
     $_SESSION['promotion_code'] = $code;
     return true;
 }
Пример #11
0
 /**
  * Calculate delivery rate for given carrier and basket content
  * 
  * @param  Array  $basket              Basket content 
  * @param  int    $carrier_id          Carrier id
  * @param  int    $country_id          Delivery Country id
  * @return Array                       Delivery rate and VAT
  */
 function calculateDeliveryForCountry($basket, $carrier_id, $country_id, $promotion_detail)
 {
     //if there is a product with vat rate > 0, add vat to the shipping
     $add_vat = $this->findVATEligibility($basket);
     require_once 'models/ecommerce/ecommerce_delivery_carrier.php';
     $Delivery_Carrier = new ecommerce_delivery_carrier();
     // first check if there are restricted items in the basket
     if (!$this->checkDeliveryRestrictions($basket, $country_id)) {
         return false;
     }
     // check if the delivery is available for given order value and weight
     $price = $Delivery_Carrier->getDeliveryRate($carrier_id, $basket['sub_total']['price'], $basket['total_weight_gross']);
     // false means method is not available for given weight and amount
     if ($price === false) {
         return false;
     }
     // zero weight means free delivery
     if ($basket['total_weight_gross'] == 0) {
         return $this->getFreeDelivery();
     }
     // check free delivery promotion
     require_once 'models/ecommerce/ecommerce_promotion.php';
     $Promotion = new ecommerce_promotion();
     $Promotion->setCacheable(false);
     if ($Promotion->freeDeliveryAvailable($carrier_id, $country_id, $promotion_detail)) {
         return $this->getFreeDelivery($basket['total_weight_gross']);
     }
     return array('value_net' => sprintf("%0.2f", $price), 'weight' => $basket['total_weight_gross'], 'vat_rate' => $add_vat, 'vat' => $price * $add_vat / 100, 'value' => sprintf("%0.2f", $price * ($add_vat + 100) / 100));
 }
Пример #12
0
 /**
  * main action
  */
 public function mainAction()
 {
     require_once 'models/ecommerce/ecommerce_promotion.php';
     $Promotion = new ecommerce_promotion();
     /**
      * Save on request
      */
     if ($_POST['save']) {
         $promotion_data = $_POST['promotion'];
         if ($promotion_data['publish'] == 'on' || $promotion_data['publish'] == 1) {
             $promotion_data['publish'] = 1;
         } else {
             $promotion_data['publish'] = 0;
         }
         if ($promotion_data['limit_to_first_order'] == 'on' || $promotion_data['limit_to_first_order'] == 1) {
             $promotion_data['limit_to_first_order'] = 1;
         } else {
             $promotion_data['limit_to_first_order'] = 0;
         }
         if ($promotion_data['discount_free_delivery'] == 'on' || $promotion_data['discount_free_delivery'] == 1) {
             $promotion_data['discount_free_delivery'] = 1;
         } else {
             $promotion_data['discount_free_delivery'] = 0;
         }
         if (!is_numeric($promotion_data['limit_cumulative_discount'])) {
             $promotion_data['limit_cumulative_discount'] = 0;
         }
         if (is_array($promotion_data['limit_list_products'])) {
             foreach ($promotion_data['limit_list_products'] as $product_id) {
                 if (is_numeric($product_id)) {
                     $limited_ids[] = $product_id;
                 }
             }
             if (is_array($limited_ids)) {
                 $promotion_data['limit_list_products'] = implode(",", $limited_ids);
             } else {
                 $promotion_data['limit_list_products'] = '';
             }
         }
         if (is_numeric($promotion_data['free_promo_products'])) {
             $promotion_data['free_promo_products'] = array(9999 => (int) $promotion_data['free_promo_products']);
         } else {
             $promotion_data['free_promo_products'] = null;
         }
         $promotion_data['limit_delivery_country_id'] = (int) $promotion_data['limit_delivery_country_id'];
         $promotion_data['limit_delivery_carrier_id'] = (int) $promotion_data['limit_delivery_carrier_id'];
         if ($Promotion->updatePromotion($promotion_data)) {
             msg("Promotion id={$promotion_data['id']} updated");
         } else {
             msg('Update failed', 'error');
         }
     }
     /**
      * Display Detail
      */
     $promotion_detail = $Promotion->getDetail($this->GET['id']);
     if (count($promotion_detail) > 0) {
         if ($promotion_detail['publish'] == 1) {
             $promotion_detail['publish_check'] = 'checked="checked"';
         } else {
             $promotion_detail['publish_check'] = '';
         }
         if ($promotion_detail['discount_free_delivery'] == 1) {
             $promotion_detail['discount_free_delivery_check'] = 'checked="checked"';
         } else {
             $promotion_detail['discount_free_delivery_check'] = '';
         }
         if ($promotion_detail['limit_to_first_order'] == 1) {
             $promotion_detail['limit_to_first_order_check'] = 'checked="checked"';
         } else {
             $promotion_detail['limit_to_first_order_check'] = '';
         }
         $promotion_detail['free_promo_products'] = $promotion_detail['free_promo_products'][9999];
         //find product in the node
         $limited_ids = explode(",", $promotion_detail['limit_list_products']);
         if (is_array($limited_ids)) {
             require_once 'models/ecommerce/ecommerce_product.php';
             $Product = new ecommerce_product();
             foreach ($limited_ids as $product_id) {
                 //find product in the node
                 if (is_numeric($product_id)) {
                     $detail = $Product->detail($product_id);
                     if ($detail['publish'] == 0) {
                         $detail['class'] = 'notpublic';
                     }
                     $this->tpl->assign('CURRENT', $detail);
                     $this->tpl->parse('content.item');
                 }
             }
         }
         $this->tpl->assign('PROMOTION', $promotion_detail);
     }
     return true;
 }
Пример #13
0
 /**
  * getVoucherData
  */
 public function getVoucherData($voucher_code)
 {
     require_once 'models/ecommerce/ecommerce_promotion.php';
     $Promotion = new ecommerce_promotion();
     $Promotion->setCacheable(false);
     $promotion_list = $Promotion->listing("code_pattern = '{$voucher_code}'");
     $promotion_data = $Promotion->getDetail($promotion_list[0]['id']);
     $data = $promotion_data['other_data'];
     $data['variety_name'] = "£" . round($promotion_data['discount_fixed_value']);
     $data['variety_description'] = "VOUCHER CODE: {$voucher_code}";
     return $data;
 }
Пример #14
0
 /**
  * Send email after succesfull reward code allocation
  */
 public function sendRewardEmail($invited_customer_id, $rewarded_customer_id, $code, $usage)
 {
     require_once 'models/common/common_email.php';
     require_once 'models/client/client_customer.php';
     $EmailForm = new common_email();
     $Customer = new client_customer();
     $Customer->setCacheable(false);
     $rewarded_customer = $Customer->getDetail($rewarded_customer_id);
     $invited_customer = $Customer->getDetail($invited_customer_id);
     $GLOBALS['common_email']['invited_customer'] = $invited_customer;
     $GLOBALS['common_email']['rewarded_customer'] = $rewarded_customer;
     $GLOBALS['common_email']['code'] = $code;
     $GLOBALS['common_email']['total_invited'] = $usage;
     $conf = ecommerce_promotion::initConfiguration();
     $GLOBALS['common_email']['minimum_order_amount'] = $conf['minimum_order_amount'];
     $GLOBALS['common_email']['discount_value'] = $conf['discount_value'];
     $to_email = $rewarded_customer['email'];
     $to_name = $rewarded_customer['first_name'] . " " . $rewarded_customer['last_name'];
     $EmailForm->sendEmail('referral_reward', 'n/a', $to_email, $to_name);
 }