/** * actionAfterLogin */ public function actionAfterLogin() { //update basket if ($_SESSION['basket']['id'] > 0 && is_numeric($_SESSION['basket']['id'])) { require_once 'models/ecommerce/ecommerce_basket.php'; $Basket = new ecommerce_basket(); $Basket->setCacheable(false); $basket_data = $Basket->detail($_SESSION['basket']['id']); $basket_data['customer_id'] = $_SESSION['client']['customer']['id']; if (!$Basket->update($basket_data)) { msg('Basket updated failed', 'error'); } } msg('you are successfully in', 'ok', 2); /** * forward */ $this->forwardAfterLogin(); }
/** * check if gift wrap is in basket */ public function checkGiftWrapSelected($variety_id) { require_once 'models/ecommerce/ecommerce_basket.php'; $Basket = new ecommerce_basket(); $Basket->setCacheable(false); $variety_id_list = $Basket->getContentItemsVarietyIdList($_SESSION['basket']['id']); if (in_array($variety_id, $variety_id_list)) { return true; } else { return false; } }
/** * main action */ public function mainAction() { //do nothing if basket is not initialized if (!is_numeric($_SESSION['basket']['id'])) { return true; } /** * create object */ require_once 'models/ecommerce/ecommerce_basket.php'; $Basket = new ecommerce_basket(); $basket_content_ids = $Basket->getContentItemsProductIdList($_SESSION['basket']['id']); $viewed_list_ids = array(); $Node = new common_node(); $viewed_products = array(); /** * go through history */ foreach ($_SESSION['history'] as $item) { if (is_numeric($item['node_id'])) { $node_data = $Node->nodeDetail($item['node_id']); if ($node_data['node_controller'] == 'product') { if (!in_array($node_data['content'], $basket_content_ids) && !in_array($node_data['content'], $viewed_list_ids) && $_SESSION['active_pages'][0] != $node_data['id']) { $viewed_products[] = $node_data['content']; } } } } /** * Pass product_id_list to product_list controller */ if (is_array($viewed_products) && count($viewed_products) > 0) { /** * prepare HTTP query for product_list component */ $viewed_list['product_id_list'] = $viewed_products; $query = http_build_query($viewed_list, '', ':'); /** * detect controller for product list */ switch ($this->GET['template']) { case 'scroll': $controller = 'product_list_scroll'; break; case '3col': $controller = 'product_list_3columns'; break; case '2col': $controller = 'product_list_2columns'; break; case '1col': default: $controller = 'product_list'; break; } /** * call controller */ $_Onxshop_Request = new Onxshop_Request("component/ecommerce/{$controller}~{$query}:image_width={$this->GET['image_width']}~"); $this->tpl->assign('ITEMS', $_Onxshop_Request->getContent()); $this->tpl->parse('content.recently_viewed'); } return true; }
/** * insert delivery */ function insertDelivery($order_data) { require_once 'models/ecommerce/ecommerce_basket.php'; $Basket = new ecommerce_basket(); $Basket->setCacheable(false); $basket = $Basket->getFullDetail($order_data['basket_id']); $include_vat = $this->isVatEligible($order_data['delivery_address_id'], $basket['customer_id']); $Basket->calculateBasketSubTotals($basket, $include_vat); $code = $order_data['other_data']['promotion_code']; $verify_code = false; $promotion_detail = $Basket->calculateBasketDiscount($basket, $code, $verify_code); require_once 'models/ecommerce/ecommerce_delivery.php'; $Delivery = new ecommerce_delivery(); $delivery = $Delivery->calculateDelivery($basket, $order_data['other_data']['delivery_options']['carrier_id'], $order_data['delivery_address_id'], $promotion_detail); //prepare object require_once 'models/ecommerce/ecommerce_delivery.php'; $Ecommerce_Delivery = new ecommerce_delivery(); //format data $delivery_data['order_id'] = $order_data['id']; $delivery_data['carrier_id'] = $order_data['other_data']['delivery_options']['carrier_id']; $delivery_data['value_net'] = $delivery['value_net']; $delivery_data['vat'] = $delivery['vat']; $delivery_data['vat_rate'] = $delivery['vat_rate']; $delivery_data['required_datetime'] = $order_data['other_data']['delivery_options']['required_datetime']; $delivery_data['note_customer'] = ''; $delivery_data['note_backoffice'] = ''; $delivery_data['other_data'] = $order_data['other_data']['delivery_options']['other_data']; $delivery_data['weight'] = $delivery['weight']; //insert if ($id = $Ecommerce_Delivery->insertDelivery($delivery_data)) { return $id; } else { return false; } }
/** * 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; }
/** * main action */ public function mainAction() { /** * get input */ if (is_array($_POST['order'])) { $order_data = $_POST['order']; } else { $order_data = array(); } /** * get node configuration */ require_once 'models/common/common_node.php'; $node_conf = common_node::initConfiguration(); $this->tpl->assign('NODE_CONF', $node_conf); /** * init basket */ require_once 'models/ecommerce/ecommerce_order.php'; require_once 'models/ecommerce/ecommerce_basket.php'; $Order = new ecommerce_order(); $Basket = new ecommerce_basket(); $Order->setCacheable(false); $Basket->setCacheable(false); //temp if ($_POST['client']['customer']['currency_code']) { $currency_code = $_POST['client']['customer']['currency_code']; } else { $currency_code = $_SESSION['client']['customer']['currency_code']; } if ($_SESSION['client']['customer']['id'] > 0) { if (is_numeric($basket_id = $_SESSION['basket']['id'])) { //update basket $basket_detail = $Basket->detail($basket_id); $basket_detail['customer_id'] = $_SESSION['client']['customer']['id']; $Basket->update($basket_detail); //insert order if (isset($_POST['confirm'])) { if ($_POST['order_terms_agreed'] == 'on') { //insert only orders with some items in the basket :) $basket_content = $Basket->getFullDetail($basket_id); if (count($basket_content['items']) > 0) { $order_data = $_POST['order']; $order_data['basket_id'] = $_SESSION['basket']['id']; $order_data['invoices_address_id'] = $_SESSION['client']['customer']['invoices_address_id']; $order_data['delivery_address_id'] = $_SESSION['client']['customer']['delivery_address_id']; $order_data['other_data']['delivery_options'] = $_SESSION['delivery_options']; $order_data['other_data']['promotion_code'] = $_SESSION['promotion_code']; $order_data['php_session_id'] = session_id(); if ($inserted_order_id = $Order->insertOrder($order_data)) { $_SESSION['promotion_code'] = null; $_SESSION['basket']['id'] = null; //forward to payment page with pre-selected payment method //onxshopGoTo("page/" . $node_conf['id_map-payment'] . "?order_id=$inserted_order_id&selected_poyment_type={$order_data['payment_type']}"); onxshopGoTo("page/" . $node_conf['id_map-payment'] . "?order_id={$inserted_order_id}"); } } else { msg("Can't insert an empty order.", 'error'); } } else { msg("You must agree with our Terms & Conditions", 'error'); } } } /** * prepare list of payment options */ require_once 'models/ecommerce/ecommerce_transaction.php'; $Transaction = new ecommerce_transaction(); $transaction_type_allowed = $Transaction->conf['allowed_types']; foreach ($transaction_type_allowed as $type) { $this->tpl->parse("content.{$type}"); } /** * gift option */ if ($_SESSION['gift'] == 1) { $this->tpl->assign("GIFT", 1); $this->tpl->parse('content.gift'); } else { $this->tpl->assign('GIFT', 0); } /** * gift message */ if ($_SESSION['gift_message'] != '') { $this->tpl->assign("GIFT_MESSAGE", $_SESSION['gift_message']); $this->tpl->parse('content.gift_message'); } else { $this->tpl->assign("GIFT_MESSAGE", ''); } } else { //msg('You must be logged in first.', 'error'); $_SESSION['to'] = "page/" . $node_conf['id_map-checkout']; onxshopGoTo("page/" . $node_conf['id_map-login']); } $this->tpl->assign("ORDER", $_POST['order']); /** * display virtual product option */ if ($this->isBasketVirtualProductOnly()) { $this->tpl->parse('content.virtual_product'); } return true; }
/** * main action */ public function mainAction() { /** * create objects */ require_once 'models/ecommerce/ecommerce_basket.php'; require_once 'models/ecommerce/ecommerce_product_to_product.php'; $Basket = new ecommerce_basket(); $PtP = new ecommerce_product_to_product(); /** * Set variables */ switch ($this->GET['type']) { case 'static': $type = 'static'; $this->tpl->assign("TITLE", I18N_RELATED_PRODUCTS_STATIC); break; case 'dynamic': default: $type = 'dynamic'; $this->tpl->assign("TITLE", I18N_RELATED_PRODUCTS_DYNAMIC); break; } $related = array(); //limit for each product - how many related products to show to each product in basket if (is_numeric($this->GET['limit_each'])) { $limit_each = $this->GET['limit_each']; } else { $limit_each = 2; } /** * get product list */ $basket_content_ids = $Basket->getContentItemsProductIdList($_SESSION['basket']['id']); /** * Get list */ if (is_array($basket_content_ids)) { foreach ($basket_content_ids as $id) { $related_to_one = $PtP->getRelatedProduct($id, $limit_each, $type); if (is_array($related_to_one)) { //make sure we don't add duplicates foreach ($related_to_one as $item_one) { if (!is_array($related['product_list'])) { $related[] = $item_one; } else { $exists = 0; foreach ($related['product_list'] as $item) { if ($item['id'] == $item_one['id']) { $exists = 1; } } if ($exists == 0) { $related[] = $item_one; } } } } } } /** * Pass product_id_list to product_list controller */ if (is_array($related) && count($related) > 0) { /** * prepare HTTP query for product_list component */ $related_list['product_id_list'] = $related; $query = http_build_query($related_list, '', ':'); /** * detect controller for product list */ switch ($this->GET['template']) { case 'scroll': $controller = 'product_list_scroll'; break; case '3col': $controller = 'product_list_3columns'; break; case '2col': $controller = 'product_list_2columns'; break; case '1col': default: $controller = 'product_list'; break; } /** * call controller */ $_Onxshop_Request = new Onxshop_Request("component/ecommerce/{$controller}~{$query}:image_width={$this->GET['image_width']}~"); $this->tpl->assign('ITEMS', $_Onxshop_Request->getContent()); $this->tpl->parse('content.product_related'); } return true; }
/** * main action */ public function mainAction() { set_time_limit(0); require_once 'models/common/common_file.php'; $File = new common_file(); $tool = $this->GET['tool']; switch ($tool) { case 'uri': require_once 'models/common/common_uri_mapping.php'; $CommonURIMapping = new common_uri_mapping(); $CommonURIMapping->generateAndSaveURITable(); msg("Nice URLs has been completely generated"); break; case 'flush_thumb': if ($File->rm(ONXSHOP_PROJECT_DIR . "var/thumbnails/*")) { msg("All image thumbnails have been deleted"); } else { "Flushing thumbnails failed"; } break; case 'flush_tmp': if ($File->rm(ONXSHOP_PROJECT_DIR . "var/tmp/*")) { msg("Temp directory has been cleaned"); } else { "Flushing temp dir failed"; } break; case 'flush_cache': if (onxshop_flush_cache()) { msg("Cache has been refreshed"); } else { msg("Flushing cache failed"); } break; case 'flush_api_cache': if (is_numeric($GLOBALS['onxshop_conf']['common_configuration']['api_data_version'])) { $current_api_data_version = $GLOBALS['onxshop_conf']['common_configuration']['api_data_version']; } else { $current_api_data_version = 1; } $api_data_version = $current_api_data_version + 1; $Configuration = new common_configuration(); if ($Configuration->saveConfig('common_configuration', 'api_data_version', $api_data_version)) { msg("Data version of API has increased to {$api_data_version}"); if (onxshop_flush_cache()) { msg("Cache has been refreshed"); } else { msg("Flushing cache failed"); } } break; case 'find_hard_links': require_once 'models/common/common_node.php'; $Node = new common_node(); $hard_links = $Node->findHardLinks(); foreach ($hard_links as $hard_link) { $this->tpl->assign('ITEM', $hard_link); $this->tpl->parse('content.hard_links.item'); } $this->tpl->parse('content.hard_links'); break; case 'delete_orphaned_baskets': require_once 'models/ecommerce/ecommerce_basket.php'; $Basket = new ecommerce_basket(); if ($Basket->deleteOrphanedAnonymouseBaskets()) { msg('Deleted orphaned baskets older than two weeks'); } break; case 'backup': $_Onxshop = new Onxshop_Request("bo/component/backup"); $this->tpl->assign('SUB_CONTENT', $_Onxshop->getContent()); break; default: $this->tpl->parse('content.menu'); break; } return true; }
/** * check for virtual product only */ public function isBasketVirtualProductOnly() { if ($gift_voucher_product_id = $this->getGiftVoucherProductId()) { if (is_numeric($basket_id = $_SESSION['basket']['id'])) { require_once 'models/ecommerce/ecommerce_basket.php'; $Basket = new ecommerce_basket(); $basket_content = $Basket->getFullDetail($basket_id); $voucher_basket_items = $this->getVoucherBasketItems($basket_content['items'], $gift_voucher_product_id); if (!$voucher_basket_items) { return false; } if (count($voucher_basket_items) == count($basket_content['items'])) { return true; } return false; } else { return false; } } else { return false; } }
/** * check if existing code can be used */ public function checkCodeBeforeApply($code, $customer_id, $basket, $customer_email = '') { if ($promotion_data = $this->checkCodeMatch($code)) { // make sure to avoid rounding errors $order_value = round($basket['sub_total']['price'], 2); /** * check if customer_id is needed (some codes can be used in guest checkout mode) */ if ($customer_id == 0 && ($promotion_data['uses_per_customer'] > 0 || $promotion_data['limit_cumulative_discount'] > 0 || $promotion_data['generated_by_customer_id'] > 0 || $promotion_data['limit_by_customer_id'] > 0)) { if (!Zend_Registry::isRegistered('ecommerce_promotion:login_needed')) { if ($_SESSION['client']['customer']['guest']) { msg("We're sorry, but this voucher code cannot be used in conjunction with “Guest Checkout”. Please go to" . " previous step and select “Save Details for Next Order” to create an account.", 'error'); } else { msg("You have to login or register to use your voucher code.", 'error'); } Zend_Registry::set('ecommerce_promotion:login_needed', true); } return false; } /** * first order */ if ($promotion_data['limit_to_first_order'] > 0) { if ($this->getNumCustomersOrders($customer_id, $customer_email) > 0) { if ($this->getNumCustomersPaidOrders($customer_id, $customer_email) == 0) { if (!Zend_Registry::isRegistered('ecommerce_promotion:first_order_unpaid')) { msg("Code \"{$code}\" can only be applied to your first order. If you cancelled " . "your previous order, please either return to it in “My Account” or contact " . "customer services if you wish to continue with your current order.", 'error'); Zend_Registry::set('ecommerce_promotion:first_order_unpaid', true); } } else { if (!Zend_Registry::isRegistered('ecommerce_promotion:first_order')) { msg("We are sorry, this voucher is only valid on your first order", 'error'); Zend_Registry::set('ecommerce_promotion:first_order', true); } } return false; } } /** * uses_per_coupon */ if ($promotion_data['uses_per_coupon'] > 0) { if ($this->getCountUsageOfSingleCode($code) + 1 > $promotion_data['uses_per_coupon']) { if (substr($promotion_data['code_pattern'], 0, 4) != "REF-") { // referral codes validity is extended automatically if (!Zend_Registry::isRegistered('ecommerce_promotion:total_usage_exceeded')) { msg("Code \"{$code}\" usage exceed number of allowed applications", 'error'); Zend_Registry::set('ecommerce_promotion:total_usage_exceeded', true); } return false; } } } /** * check uses_per_customer */ if ($promotion_data['uses_per_customer'] > 0) { if ($this->getCountUsageOfSingleCode($code, $customer_id) + 1 > $promotion_data['uses_per_customer']) { if (!Zend_Registry::isRegistered('ecommerce_promotion:per_user_usage_exceeded')) { msg("Code \"{$code}\" usage exceed number of allowed applications per one customer", 'error'); Zend_Registry::set('ecommerce_promotion:per_user_usage_exceeded', true); } return false; } } /** * check limit_cumulative_discount */ if ($promotion_data['limit_cumulative_discount'] > 0) { require_once 'models/ecommerce/ecommerce_basket.php'; $Basket = new ecommerce_basket(); $Basket->calculateBasketDiscount($basket, $code, false); $usage = $this->getUsage($promotion_data['id'], $customer_id); if ($usage && $usage['sum_discount'] + $basket['discount'] > $promotion_data['limit_cumulative_discount']) { $limit = money_format("%n", $promotion_data['limit_cumulative_discount']); $provided = money_format("%n", $usage['sum_discount']); if (!Zend_Registry::isRegistered('ecommerce_promotion:limit_cumulative_discount_exceeded')) { $msg = "Code \"{$code}\" is limited to maximum discount value of {$limit}. " . "You’ve already used of {$provided}"; if ($promotion_data['discount_percentage_value'] > 0) { $max_order = ($promotion_data['limit_cumulative_discount'] - $usage['sum_discount']) / ($promotion_data['discount_percentage_value'] / 100); if ($max_order > 0) { $max_order = money_format("%n", $max_order); $msg .= ", so your current order would exceed your allotted discount value. " . "Please try again with an order of no greater than {$max_order}"; } } $msg .= "."; msg($msg, 'error'); Zend_Registry::set('ecommerce_promotion:limit_cumulative_discount_exceeded', true); } return false; } } /** * not using self-generated code */ if ($promotion_data['generated_by_customer_id'] > 0 && $promotion_data['generated_by_customer_id'] == $customer_id) { if (!Zend_Registry::isRegistered('ecommerce_promotion:own_code')) { msg("You are not allowed to redeem your own code!"); Zend_Registry::set('ecommerce_promotion:own_code', true); } return false; } /** * code limited to customer_id */ if ($promotion_data['limit_by_customer_id'] > 0 && $promotion_data['limit_by_customer_id'] != $customer_id) { if (!Zend_Registry::isRegistered('ecommerce_promotion:limit_by_customer_id')) { msg("You are not allowed to redeem the code!"); Zend_Registry::set('ecommerce_promotion:limit_by_customer_id', true); } return false; } /** * minimum order amount */ if ($promotion_data['limit_to_order_amount'] > 0) { if ($order_value < $promotion_data['limit_to_order_amount']) { if (!Zend_Registry::isRegistered('ecommerce_promotion:order_amount')) { $amount = money_format("%n", $promotion_data['limit_to_order_amount']); $sub_total = money_format("%n", $order_value); msg("The voucher code \"{$code}\" is restricted to orders in amount of {$amount}. You have only {$sub_total} in you basket.", 'error'); Zend_Registry::set('ecommerce_promotion:order_amount', true); } return false; } } /** * do not allow to buy gift voucher */ if (substr($promotion_data['code_pattern'], 0, 4) == "REF-" || substr($promotion_data['code_pattern'], 0, 4) == "REW-") { $gift_voucher_product_id = (int) $this->getGiftVoucherProductId(); if ($gift_voucher_product_id > 0 && count($basket['items']) > 0) { foreach ($basket['items'] as $item) { if ($item['product']['id'] == $gift_voucher_product_id) { if (!Zend_Registry::isRegistered('ecommerce_promotion:gift_in_basket')) { msg("Sorry, voucher codes cannot be used to buy Gift Voucher Codes."); Zend_Registry::set('ecommerce_promotion:gift_in_basket', true); } return false; } } } } /** * check if limited products are in basket */ $limited_ids = explode(",", $promotion_data['limit_list_products']); if (strlen($promotion_data['limit_list_products']) > 0 && is_array($limited_ids)) { $prod = 0; if (count($basket['items']) > 0) { foreach ($basket['items'] as $item) { if (in_array($item['product']['id'], $limited_ids)) { $prod++; } } } if ($prod == 0) { if (!Zend_Registry::isRegistered('ecommerce_promotion:limit_to_products')) { msg("Sorry, the voucher code \"{$code}\" is limited to certain products, which you don't have in your basket."); Zend_Registry::set('ecommerce_promotion:limit_to_products', true); } return false; } } /** * check if free promo item can be addeded to order */ $promotion_data['free_promo_product'] = $this->checkForFreePromoItem($promotion_data, $order_value); require_once 'models/ecommerce/ecommerce_promotion_type.php'; $Type = new ecommerce_promotion_type(); $promotion_data['type'] = $Type->detail($promotion_data['type']); return $promotion_data; } else { return false; } }