예제 #1
0
 function toC_Coupon($coupon_code)
 {
     global $osC_Database, $osC_Language, $osC_CategoryTree;
     if (!empty($coupon_code)) {
         $Qcoupon = $osC_Database->query('select * from :table_coupons c, :table_coupons_description cd where c.coupons_id = cd.coupons_id and c.coupons_code = :coupons_code and cd.language_id = :language_id');
         $Qcoupon->bindTable(':table_coupons', TABLE_COUPONS);
         $Qcoupon->bindTable(':table_coupons_description', TABLE_COUPONS_DESCRIPTION);
         $Qcoupon->bindValue(':coupons_code', $coupon_code);
         $Qcoupon->bindInt(':language_id', $osC_Language->getID());
         $Qcoupon->execute();
         if ($Qcoupon->numberOfRows() === 1) {
             $this->_data = $Qcoupon->toArray();
             //categories
             $QcouponCategories = $osC_Database->query('select categories_id from :table_coupons_to_categories where coupons_id = :coupons_id');
             $QcouponCategories->bindTable(':table_coupons_to_categories', TABLE_COUPONS_TO_CATEGORIES);
             $QcouponCategories->bindInt(':coupons_id', $this->_data['coupons_id']);
             $QcouponCategories->execute();
             while ($QcouponCategories->next()) {
                 $this->_categories[] = $QcouponCategories->valueInt('categories_id');
             }
             $QcouponCategories->freeResult();
             //get all sub categories
             if (!empty($this->_categories)) {
                 //add by tomatoshop
                 require_once 'category_tree.php';
                 $osC_CategoryTree = new osC_CategoryTree($categories_id);
                 //add by tomatoshop
                 $children = array();
                 foreach ($this->_categories as $categories_id) {
                     $osC_CategoryTree->getChildren($categories_id, $children);
                 }
                 $this->_categories = array_merge($this->_categories, $children);
                 //products
                 $QcouponProducts = $osC_Database->query('select products_id from :table_products_to_categories where categories_id in (' . implode(',', $this->_categories) . ')');
                 $QcouponProducts->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
                 $QcouponProducts->execute();
                 while ($QcouponProducts->next()) {
                     $this->_products[] = $QcouponProducts->valueInt('products_id');
                 }
                 $QcouponProducts->freeResult();
             } else {
                 //products
                 $QcouponProducts = $osC_Database->query('select products_id from :coupons_to_products where coupons_id = :coupons_id');
                 $QcouponProducts->bindTable(':coupons_to_products', TABLE_COUPONS_TO_PRODUCTS);
                 $QcouponProducts->bindInt(':coupons_id', $this->_data['coupons_id']);
                 $QcouponProducts->execute();
                 while ($QcouponProducts->next()) {
                     $this->_products[] = $QcouponProducts->valueInt('products_id');
                 }
                 $QcouponProducts->freeResult();
             }
         }
         $Qcoupon->freeResult();
     }
 }
예제 #2
0
 function saveCategory()
 {
     global $toC_Json, $osC_Database, $osC_Language;
     $parent_id = isset($_REQUEST['parent_category_id']) ? end(explode('_', $_REQUEST['parent_category_id'])) : null;
     //search engine friendly urls
     $formatted_urls = array();
     $urls = $_REQUEST['categories_url'];
     if (is_array($urls) && !empty($urls)) {
         foreach ($urls as $languages_id => $url) {
             $url = toc_format_friendly_url($url);
             if (empty($url)) {
                 $url = toc_format_friendly_url($_REQUEST['categories_name'][$languages_id]);
             }
             $formatted_urls[$languages_id] = $url;
         }
     }
     $data = array('parent_id' => $parent_id, 'sort_order' => $_REQUEST['sort_order'], 'image' => $_FILES['image'], 'categories_status' => $_REQUEST['categories_status'], 'name' => $_REQUEST['categories_name'], 'url' => $formatted_urls, 'page_title' => $_REQUEST['page_title'], 'meta_keywords' => $_REQUEST['meta_keywords'], 'meta_description' => $_REQUEST['meta_description'], 'flag' => isset($_REQUEST['product_flag']) ? $_REQUEST['product_flag'] : 0, 'ratings' => $_REQUEST['ratings']);
     //editing the parent category
     if (isset($_REQUEST['categories_id']) && is_numeric($_REQUEST['categories_id'])) {
         $subcategories = array();
         $osC_CategoryTree = new osC_CategoryTree();
         $subcategories = $osC_CategoryTree->getChildren($_REQUEST['categories_id'], $subcategories);
         if (!osc_empty($subcategories)) {
             $data['subcategories'] = $subcategories;
         }
     }
     $category_id = osC_Categories_Admin::save(isset($_REQUEST['categories_id']) && is_numeric($_REQUEST['categories_id']) ? $_REQUEST['categories_id'] : null, $data);
     if ($category_id > 0) {
         $response = array('success' => true, 'feedback' => $osC_Language->get('ms_success_action_performed'), 'categories_id' => $category_id, 'text' => $_REQUEST['categories_name'][$osC_Language->getID()]);
     } else {
         $response = array('success' => false, 'feedback' => $osC_Language->get('ms_error_action_not_performed'));
     }
     header('Content-Type: text/html');
     echo $toC_Json->encode($response);
 }
예제 #3
0
 function setStatus($id, $flag, $product_flag)
 {
     global $osC_Database;
     include_once '../includes/classes/category_tree.php';
     $osC_CategoryTree = new osC_CategoryTree(true, true, false);
     $error = false;
     $subcategories_array = array($id);
     $subcategories_array = $osC_CategoryTree->getChildren($id, $subcategories_array);
     $categories_id = implode(',', $subcategories_array);
     $Qstatus = $osC_Database->query('update :table_categories set categories_status = :categories_status where categories_id in (:categories_id)');
     $Qstatus->bindTable(':table_categories', TABLE_CATEGORIES);
     $Qstatus->bindRaw(":categories_id", $categories_id);
     $Qstatus->bindValue(":categories_status", $flag);
     $Qstatus->execute();
     if (!$osC_Database->isError()) {
         if ($flag == 0 && $product_flag == 1) {
             $Qupdate = $osC_Database->query('update :table_products set products_status = 0 where products_id in (select products_id from :table_products_to_categories where categories_id in (:categories_id))');
             $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
             $Qupdate->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES);
             $Qupdate->bindRaw(":categories_id", $categories_id);
             $Qupdate->execute();
         }
     }
     if (!$osC_Database->isError()) {
         osC_Cache::clear('categories');
         osC_Cache::clear('category_tree');
         osC_Cache::clear('also_purchased');
         osC_Cache::clear('sefu-products');
         osC_Cache::clear('new_products');
         return true;
     }
     return false;
 }