/** * 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; }
/** * 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; }
/** * 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; }