Ejemplo n.º 1
0
 /**
  * @param int $currency_id
  * @param $data
  * @return bool
  */
 public function editCurrency($currency_id, $data)
 {
     // prevent disabling the only enabled currency in cart
     if (isset($data['status']) && !$data['status']) {
         $enabled = array();
         $all = $this->getCurrencies();
         foreach ($all as $c) {
             if ($c['status'] && $c['currency_id'] != $currency_id) {
                 $enabled[] = $c;
             }
         }
         if (!$enabled) {
             return false;
         }
     }
     $fields = array('title', 'code', 'symbol_left', 'symbol_right', 'decimal_place', 'value', 'status');
     $update = array('date_modified = "' . jdate::now() . '"');
     foreach ($fields as $f) {
         if (isset($data[$f])) {
             $update[] = $f . " = '" . $this->db->escape($data[$f]) . "'";
         }
     }
     if (!empty($update)) {
         $this->db->query("UPDATE " . $this->db->table("currencies") . " \n\t\t\t\t\t\t\t  SET " . implode(',', $update) . "\n\t\t\t\t\t\t\t  WHERE currency_id = '" . (int) $currency_id . "'");
         $this->cache->delete('currency');
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @param int $zone_to_location_id
  * @param array $data
  */
 public function editLocationZone($zone_to_location_id, $data)
 {
     $fields = array('country_id', 'zone_id');
     $update = array('date_modified = "' . jdate::now() . '"');
     foreach ($fields as $f) {
         if (isset($data[$f])) {
             $update[] = $f . " = '" . $this->db->escape($data[$f]) . "'";
         }
     }
     if (!empty($update)) {
         $this->db->query("UPDATE " . $this->db->table("zones_to_locations") . " SET " . implode(',', $update) . " WHERE zone_to_location_id = '" . (int) $zone_to_location_id . "'");
         $this->cache->delete('location');
     }
 }
Ejemplo n.º 3
0
 /**
  * @param int $category_id
  * @param array $data
  */
 public function editCategory($category_id, $data)
 {
     $fields = array('parent_id', 'sort_order', 'status');
     $update = array('date_modified = "' . jdate::now() . '"');
     foreach ($fields as $f) {
         if (isset($data[$f])) {
             $update[] = $f . " = '" . $this->db->escape($data[$f]) . "'";
         }
     }
     if (!empty($update)) {
         $this->db->query("UPDATE " . $this->db->table("categories") . " SET " . implode(',', $update) . " WHERE category_id = '" . (int) $category_id . "'");
     }
     if (!empty($data['category_description'])) {
         foreach ($data['category_description'] as $language_id => $value) {
             $update = array();
             if (isset($value['name'])) {
                 $update["name"] = $value['name'];
             }
             if (isset($value['description'])) {
                 $update["description"] = $value['description'];
             }
             if (isset($value['meta_keywords'])) {
                 $update["meta_keywords"] = $value['meta_keywords'];
             }
             if (isset($value['meta_description'])) {
                 $update["meta_description"] = $value['meta_description'];
             }
             if (!empty($update)) {
                 // insert or update
                 $this->language->replaceDescriptions('category_descriptions', array('category_id' => (int) $category_id), array($language_id => $update));
             }
         }
     }
     if (isset($data['category_store'])) {
         $this->db->query("DELETE FROM " . $this->db->table("categories_to_stores") . " WHERE category_id = '" . (int) $category_id . "'");
         foreach ($data['category_store'] as $store_id) {
             $this->db->query("INSERT INTO " . $this->db->table("categories_to_stores") . " SET category_id = '" . (int) $category_id . "', store_id = '" . (int) $store_id . "'");
         }
     }
     if (isset($data['keyword'])) {
         $data['keyword'] = SEOEncode($data['keyword']);
         if ($data['keyword']) {
             $this->language->replaceDescriptions('url_aliases', array('query' => "category_id=" . (int) $category_id), array((int) $this->language->getContentLanguageID() => array('keyword' => $data['keyword'])));
         } else {
             $this->db->query("DELETE\n\t\t\t\t\t\t\t\tFROM " . $this->db->table("url_aliases") . " \n\t\t\t\t\t\t\t\tWHERE query = 'category_id=" . (int) $category_id . "'\n\t\t\t\t\t\t\t\t\tAND language_id = '" . (int) $this->language->getContentLanguageID() . "'");
         }
     }
     $this->cache->delete('category');
 }
Ejemplo n.º 4
0
 /**
  * @param int $review_id
  * @param array $data
  */
 public function editReview($review_id, $data)
 {
     $allowFields = array('product_id', 'customer_id', 'author', 'text', 'rating', 'status', 'date_added');
     $update_data = array(' date_modified = "' . jdate::now() . '" ');
     foreach ($data as $key => $val) {
         if (in_array($key, $allowFields)) {
             $update_data[] = "`{$key}` = '" . $this->db->escape($val) . "' ";
         }
     }
     $review = $this->getReview($review_id);
     $this->db->query("UPDATE " . $this->db->table("reviews") . " \n\t\t\t\t\t\t  SET " . implode(',', $update_data) . "\n\t\t\t\t\t\t  WHERE review_id = '" . (int) $review_id . "'");
     $this->cache->delete('product.rating.' . (int) $review['product_id']);
     $this->cache->delete('product.reviews.totals');
     $this->cache->delete('product.all_info');
 }
Ejemplo n.º 5
0
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('common/home');
     $data = array();
     $data['order'] = array();
     $data['customer'] = array();
     $data['xaxis'] = array();
     $data['order']['label'] = $this->language->get('text_order');
     $data['customer']['label'] = $this->language->get('text_customer');
     if (isset($this->request->get['range'])) {
         $range = $this->request->get['range'];
     } else {
         $range = 'month';
     }
     switch ($range) {
         case 'day':
             for ($i = 0; $i < 24; $i++) {
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . $this->db->table("orders") . "` WHERE order_status_id > '0' AND (DATE(date_added) = DATE('" . Jdate::now() . "') AND HOUR(date_added) = '" . (int) $i . "') GROUP BY HOUR(date_added) ORDER BY date_added ASC");
                 if ($query->num_rows) {
                     $data['order']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['order']['data'][] = array($i, 0);
                 }
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->table("customers") . " WHERE DATE(date_added) = DATE(NOW()) AND HOUR(date_added) = '" . (int) $i . "' GROUP BY HOUR(date_added) ORDER BY date_added ASC");
                 if ($query->num_rows) {
                     $data['customer']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['customer']['data'][] = array($i, 0);
                 }
                 $data['xaxis'][] = array($i, date('H', mktime($i, 0, 0, date('n'), date('j'), date('Y'))));
             }
             break;
         case 'week':
             $date_start = strtotime('-' . date('w') . ' days');
             for ($i = 0; $i < 7; $i++) {
                 $date = date('Y-m-d', $date_start + $i * 86400);
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . $this->db->table("orders") . "` WHERE order_status_id > '0' AND DATE(date_added) = '" . Jdate::Jalali($date) . "' GROUP BY DATE(date_added)");
                 if ($query->num_rows) {
                     $data['order']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['order']['data'][] = array($i, 0);
                 }
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . $this->db->table("customers") . "` WHERE DATE(date_added) = '" . Jdate::Jalali($date) . "' GROUP BY DATE(date_added)");
                 if ($query->num_rows) {
                     $data['customer']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['customer']['data'][] = array($i, 0);
                 }
                 $data['xaxis'][] = array($i, date('D', strtotime($date)));
             }
             break;
         default:
         case 'month':
             for ($i = 1; $i <= jdate::day(); $i++) {
                 $date = Jdate::year() . '-' . Jdate::month() . '-' . $i;
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . $this->db->table("orders") . "` WHERE order_status_id > '0' AND (DATE(date_added) = '" . $this->db->escape($date) . "') GROUP BY DAY(date_added)");
                 if ($query->num_rows) {
                     $data['order']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['order']['data'][] = array($i, 0);
                 }
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->table("customers") . " WHERE DATE(date_added) = '" . $this->db->escape($date) . "' GROUP BY DAY(date_added)");
                 if ($query->num_rows) {
                     $data['customer']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['customer']['data'][] = array($i, 0);
                 }
                 $data['xaxis'][] = array($i, date('j', strtotime($date)));
             }
             break;
         case 'year':
             for ($i = 1; $i <= 12; $i++) {
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . $this->db->table("orders") . "` WHERE order_status_id > '0' AND YEAR(date_added) = '" . Jdate::year() . "' AND MONTH(date_added) = '" . $i . "' GROUP BY MONTH(date_added)");
                 if ($query->num_rows) {
                     $data['order']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['order']['data'][] = array($i, 0);
                 }
                 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . $this->db->table("customers") . " WHERE YEAR(date_added) = '" . date('Y') . "' AND MONTH(date_added) = '" . $i . "' GROUP BY MONTH(date_added)");
                 if ($query->num_rows) {
                     $data['customer']['data'][] = array($i, (int) $query->row['total']);
                 } else {
                     $data['customer']['data'][] = array($i, 0);
                 }
                 $data['xaxis'][] = array($i, date('M', mktime(0, 0, 0, $i, 1, date('Y'))));
             }
             break;
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->setOutput(AJson::encode($data));
 }
Ejemplo n.º 6
0
 /**
  * @param int $order_id
  * @param array $data
  */
 public function editOrder($order_id, $data)
 {
     $fields = array('telephone', 'email', 'fax', 'shipping_firstname', 'shipping_lastname', 'shipping_company', 'shipping_address_1', 'shipping_address_2', 'shipping_city', 'shipping_postcode', 'shipping_zone', 'shipping_zone_id', 'shipping_country', 'shipping_country_id', 'payment_firstname', 'payment_lastname', 'payment_company', 'payment_address_1', 'payment_address_2', 'payment_city', 'payment_postcode', 'payment_zone', 'payment_zone_id', 'payment_country', 'payment_country_id', 'shipping_method', 'payment_method', 'order_status_id', 'key_id');
     $update = array('date_modified = "' . jdate::now() . '"');
     if ($this->dcrypt->active) {
         //encrypt order data
         //check key_id to use from existing record
         $query_key = $this->db->query("select key_id from " . $this->db->table("orders") . "\n\t\t\t\t\t\t\t  WHERE order_id = '" . (int) $order_id . "'");
         $data['key_id'] = $query_key->rows[0]['key_id'];
         $data = $this->dcrypt->encrypt_data($data, 'orders');
         $fields[] = 'key_id';
     }
     foreach ($fields as $f) {
         if (isset($data[$f])) {
             $update[] = $f . " = '" . $this->db->escape($data[$f]) . "'";
         }
     }
     $this->db->query("UPDATE `" . $this->db->table("orders") . "`\n\t\t\t\t\t\t  SET " . implode(',', $update) . "\n\t\t\t\t\t\t  WHERE order_id = '" . (int) $order_id . "'");
     $order = $this->getOrder($order_id);
     if (isset($data['product'])) {
         // first of all delete removed products
         foreach ($data['product'] as $item) {
             if ($item['order_product_id']) {
                 $order_product_ids[] = $item['order_product_id'];
             }
         }
         $this->db->query("DELETE FROM " . $this->db->table("order_products") . "\n\t\t\t\t\t\t\t  WHERE order_id = '" . (int) $order_id . "' AND order_product_id NOT IN ('" . implode("','", $order_product_ids) . "')");
         foreach ($data['product'] as $product) {
             if ($product['product_id']) {
                 $exists = $this->db->query("SELECT product_id\n\t\t\t\t\t\t\t\t\t\t\t\t FROM " . $this->db->table("order_products") . "\n\t\t\t\t\t\t\t\t\t\t\t\t WHERE order_id = '" . (int) $order_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t    AND product_id='" . (int) $product['product_id'] . "'\n\t\t\t\t\t\t\t\t\t\t\t\t    AND order_product_id = '" . (int) $product['order_product_id'] . "'");
                 $exists = $exists->num_rows;
                 if ($exists) {
                     $this->db->query("UPDATE " . $this->db->table("order_products") . "\n\t\t\t\t\t\t\t\t\t\t  SET price = '" . $this->db->escape(preformatFloat($product['price'], $this->language->get('decimal_point')) / $order['value']) . "',\n\t\t\t\t\t\t\t\t\t\t  \t  total = '" . $this->db->escape(preformatFloat($product['total'], $this->language->get('decimal_point')) / $order['value']) . "',\n\t\t\t\t\t\t\t\t\t\t\t  quantity = '" . $this->db->escape($product['quantity']) . "'\n\t\t\t\t\t\t\t\t\t\t  WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . (int) $product['order_product_id'] . "'");
                 } else {
                     // new products
                     $product_query = $this->db->query("SELECT *, p.product_id\n\t\t\t\t\t\t\t FROM " . $this->db->table("products") . " p\n\t\t\t\t\t\t\t LEFT JOIN " . $this->db->table("product_descriptions") . " pd ON (p.product_id = pd.product_id)\n\t\t\t\t\t\t\t WHERE p.product_id='" . (int) $product['product_id'] . "'");
                     $this->db->query("INSERT INTO " . $this->db->table("order_products") . "\n\t\t\t\t\t\t\tSET order_id = '" . (int) $order_id . "',\n\t\t\t\t\t\t\t\tproduct_id = '" . (int) $product['product_id'] . "',\n\t\t\t\t\t\t\t\tname = '" . $this->db->escape($product_query->row['name']) . "',\n\t\t\t\t\t\t\t\tmodel = '" . $this->db->escape($product_query->row['model']) . "',\n\t\t\t\t\t\t\t\tprice = '" . $this->db->escape(preformatFloat($product['price'], $this->language->get('decimal_point')) / $order['value']) . "',\n\t\t\t\t\t\t\t\ttotal = '" . $this->db->escape(preformatFloat($product['total'], $this->language->get('decimal_point')) / $order['value']) . "',\n\t\t\t\t\t\t\t\tquantity = '" . $this->db->escape($product['quantity']) . "'");
                 }
             }
         }
     }
     if (isset($data['totals'])) {
         //TODO: Improve, not to rely on text value. Add 2 parameters for total, text_val and number.
         foreach ($data['totals'] as $total_id => $text_value) {
             //get number portion together with the sign
             $number = preformatFloat($text_value, $this->language->get('decimal_point'));
             $this->db->query("UPDATE " . $this->db->table("order_totals") . "\n\t\t\t\t\t\t\t\t  SET `text` = '" . $this->db->escape($text_value) . "',\n\t\t\t\t\t\t\t\t      `value` = '" . $number . "'\n\t\t\t\t\t\t\t\t  WHERE order_total_id = '" . (int) $total_id . "'");
         }
         // update total in order main table reading back from all totals and select key 'total'
         $totals = $this->getOrderTotals($order_id);
         if ($totals) {
             foreach ($totals as $total_id => $t_data) {
                 if ($t_data['key'] == 'total') {
                     $this->db->query("UPDATE " . $this->db->table("orders") . "\n\t\t\t\t\t\t\t\t  SET `total` = '" . $t_data['value'] . "'\n\t\t\t\t\t\t\t\t  WHERE order_id = '" . (int) $order_id . "'");
                     break;
                 }
             }
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * @param int $product_id
  * @param array $data
  */
 public function updateProduct($product_id, $data)
 {
     $fields = array("model", "sku", "location", "quantity", "minimum", "maximum", "subtract", "stock_status_id", "date_available", "manufacturer_id", "shipping", "ship_individually", "free_shipping", "shipping_price", "call_to_order", "price", "cost", "weight", "weight_class_id", "length", "width", "height", "length_class_id", "status", "tax_class_id", "sort_order");
     $preformat_fields = array("shipping_price", "price", "cost", "weight", "length", "width", "height");
     $update = array('date_modified = "' . jdate::now() . '"');
     foreach ($fields as $f) {
         if (isset($data[$f])) {
             if (in_array($f, $preformat_fields)) {
                 $data[$f] = preformatFloat($data[$f], $this->language->get('decimal_point'));
             }
             $update[] = $f . " = '" . $this->db->escape($data[$f]) . "'";
         }
     }
     if (!empty($update)) {
         $this->db->query("UPDATE `" . $this->db->table("products`") . " SET " . implode(',', $update) . " WHERE product_id = '" . (int) $product_id . "'");
     }
     if (!empty($data['product_description'])) {
         foreach ($data['product_description'] as $field => $value) {
             $fields = array('name', 'description', 'meta_keywords', 'meta_description', 'blurb');
             $update = array();
             foreach ($fields as $f) {
                 if ($f == $field) {
                     $update[$f] = $value;
                 }
             }
             if (!empty($update)) {
                 $this->language->replaceDescriptions('product_descriptions', array('product_id' => (int) $product_id), array((int) $this->language->getContentLanguageID() => $update));
             }
         }
     }
     if (isset($data['featured'])) {
         $this->setFeatured($product_id, $data['featured'] ? true : false);
     }
     if (isset($data['keyword'])) {
         $data['keyword'] = SEOEncode($data['keyword'], 'product_id', $product_id);
         if ($data['keyword']) {
             $this->language->replaceDescriptions('url_aliases', array('query' => "product_id=" . (int) $product_id), array((int) $this->language->getContentLanguageID() => array('keyword' => $data['keyword'])));
         } else {
             $this->db->query("DELETE\n\t\t\t\t\t\t\t\tFROM " . $this->db->table("url_aliases") . " \n\t\t\t\t\t\t\t\tWHERE query = 'product_id=" . (int) $product_id . "'\n\t\t\t\t\t\t\t\t\tAND language_id = '" . (int) $this->language->getContentLanguageID() . "'");
         }
     }
     if (isset($data['product_tags'])) {
         $language_id = $this->language->getContentLanguageID();
         $tags = explode(',', $data['product_tags']);
         foreach ($tags as &$tag) {
             $tag = $this->db->escape(trim($tag));
         }
         $this->language->replaceMultipleDescriptions('product_tags', array('product_id' => (int) $product_id), array((int) $language_id => array('tag' => array_unique($tags))));
     }
     $this->cache->delete('product');
 }