Skip to content

Commit

Permalink
OkayCMS 2.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
OkayCMS committed Mar 4, 2019
1 parent 8c793ea commit 1a1db59
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 101 deletions.
11 changes: 4 additions & 7 deletions api/Brands.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function get_brands($filter = array(), $count = false) {
$lang_sql->fields";
$visible = '';

$joins .= $this->db->placehold(" LEFT JOIN __products p ON p.brand_id=b.id");

if ($count === true) {
$select = "COUNT(DISTINCT b.id) as count";
}
Expand All @@ -46,7 +48,6 @@ public function get_brands($filter = array(), $count = false) {

if(isset($filter['product_id'])) {
$where .= $this->db->placehold(' AND p.id in (?@)', (array)$filter['product_id']);
$joins = $this->db->placehold(" LEFT JOIN __products p ON p.brand_id=b.id");
}

$first_currency = $this->money->get_currencies(array('enabled'=>1));
Expand All @@ -65,13 +66,11 @@ public function get_brands($filter = array(), $count = false) {
if(isset($filter['price']['max'])) {
$where .= $this->db->placehold(" AND floor(IF(pv.currency_id=0 OR c.id is null,pv.price, pv.price*c.rate_to/c.rate_from)*$coef)<= ? ", $this->db->escape(trim($filter['price']['max'])));
}
$joins .= $this->db->placehold(" LEFT JOIN __products p ON p.brand_id=b.id");
$joins .= ' LEFT JOIN __variants pv ON pv.product_id = p.id';
$joins .= ' LEFT JOIN __currencies c ON c.id=pv.currency_id';
$joins .= $this->db->placehold(" LEFT JOIN __variants pv ON pv.product_id = p.id");
$joins .= $this->db->placehold(" LEFT JOIN __currencies c ON c.id=pv.currency_id");
}

if(!empty($filter['category_id'])) {
$joins .= $this->db->placehold(" LEFT JOIN __products p ON p.brand_id=b.id");
$joins .= $this->db->placehold(" LEFT JOIN __products_categories pc ON p.id = pc.product_id");
$where .= $this->db->placehold(" AND pc.category_id in(?@) $visible", (array)$filter['category_id']);
}
Expand Down Expand Up @@ -125,8 +124,6 @@ public function get_brands($filter = array(), $count = false) {
$other_filter .= "(SELECT 1 FROM __variants pv WHERE pv.product_id=p.id AND pv.compare_price>0 LIMIT 1) = 1 OR ";
}
$where .= substr($other_filter, 0, -4).")";

$joins .= $this->db->placehold(" LEFT JOIN __products p ON (p.brand_id=b.id)");
}

if(!empty($filter['selected_brands'])) {
Expand Down
23 changes: 20 additions & 3 deletions api/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ public function update_category($id, $category) {
$this->update_level_depth($id, $category->level_depth);
}

$category = (array)$category;
unset($category['path']);
unset($category['level']);
unset($category['subcategories']);
unset($category['children']);
$category = (object)$category;
$result = $this->languages->get_description($category, 'category');

Expand Down Expand Up @@ -283,9 +288,21 @@ public function update_main_product_category($product_ids) {
}

/*Удаление категории из товара*/
public function delete_product_category($product_id, $category_id) {
$this->db->query("update __categories set last_modify=now() where id=?", intval($category_id));
$query = $this->db->placehold("DELETE FROM __products_categories WHERE product_id=? AND category_id=? LIMIT 1", intval($product_id), intval($category_id));
public function delete_product_category($products_ids, $categories_ids = array()) {

$products_ids = (array)$products_ids;
$categories_ids = (array)$categories_ids;
$category_id_filter = '';
if (empty($category_id)) {
foreach ($this->get_categories(array('product_id'=>$products_ids)) as $c) {
$categories_ids[] = $c->id;
}
}
if (!empty($categories_ids)) {
$this->db->query("UPDATE __categories SET last_modify=NOW() WHERE id IN (?@)", $categories_ids);
$category_id_filter = $this->db->placehold("AND category_id IN (?@)", $categories_ids);
}
$query = $this->db->placehold("DELETE FROM __products_categories WHERE product_id IN (?@) $category_id_filter", $products_ids);
$this->db->query($query);
}

Expand Down
2 changes: 1 addition & 1 deletion api/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Config {

/*Версия системы*/
public $version = '2.3.1';
public $version = '2.3.2';
/*Тип системы*/
public $version_type = 'pro';

Expand Down
48 changes: 23 additions & 25 deletions api/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,61 +376,59 @@ public function add_product($product) {
}

/*Удаление товара*/
public function delete_product($id) {
if(!empty($id)) {
public function delete_product($ids) {
if (!empty($ids)) {
$ids = (array)$ids;
// Удаляем варианты
$variants = $this->variants->get_variants(array('product_id'=>$id));
foreach($variants as $v) {
$this->variants->delete_variant($v->id);
foreach ($this->variants->get_variants(array('product_id'=>$ids)) as $v) {
$variants_ids[] = $v->id;
}
if (!empty($variants_ids)) {
$this->variants->delete_variant($variants_ids);
}

// Удаляем изображения
$images = $this->get_images(array('product_id'=>$id));
$images = $this->get_images(array('product_id'=>$ids));
foreach($images as $i) {
$this->delete_image($i->id);
}

// Удаляем категории
$categories = $this->categories->get_categories(array('product_id'=>$id));
foreach($categories as $c) {
$this->categories->delete_product_category($id, $c->id);
}
$this->categories->delete_product_category($ids);

// Удаляем свойства
$this->features_values->delete_product_value($id);
$this->features_values->delete_product_value($ids);

// Удаляем связанные товары
$related = $this->get_related_products($id);
foreach($related as $r) {
$this->delete_related_product($id, $r->related_id);
}
$query = $this->db->placehold("DELETE FROM __related_products WHERE product_id IN (?@)", $ids);
$this->db->query($query);

// Удаляем товар из связанных с другими
$query = $this->db->placehold("DELETE FROM __related_products WHERE related_id=?", intval($id));
$query = $this->db->placehold("DELETE FROM __related_products WHERE related_id IN (?@)", $ids);
$this->db->query($query);

// Удаляем отзывы
$comments = $this->comments->get_comments(array('object_id'=>$id, 'type'=>'product'));
$comments = $this->comments->get_comments(array('object_id'=>$ids, 'type'=>'product'));
foreach($comments as $c) {
$this->comments->delete_comment($c->id);
}

// Удаляем из покупок
$this->db->query('UPDATE __purchases SET product_id=NULL WHERE product_id=?', intval($id));
$this->db->query('UPDATE __purchases SET product_id=NULL WHERE product_id IN (?@)', $ids);

//lastModify
$this->db->query('select brand_id from __products where id=?', intval($id));
$bid = (int)$this->db->result('brand_id');
if ($bid) {
$this->db->query('update __brands set last_modify=now() where id=?', $bid);
$this->db->query('SELECT brand_id FROM __products WHERE id IN (?@)', $ids);
$bid = $this->db->results('brand_id');
if (!empty($bid)) {
$this->db->query('UPDATE __brands SET last_modify=NOW() WHERE id IN (?@)', $bid);
}

// Удаляем языки
$query = $this->db->placehold("DELETE FROM __lang_products WHERE product_id=?", intval($id));
$query = $this->db->placehold("DELETE FROM __lang_products WHERE product_id IN (?@)", $ids);
$this->db->query($query);

// Удаляем товар
$query = $this->db->placehold("DELETE FROM __products WHERE id=? LIMIT 1", intval($id));
$query = $this->db->placehold("DELETE FROM __products WHERE id IN (?@)", $ids);
if($this->db->query($query)) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion api/Subscribes.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function get_subscribes($filter = array(), $count = false) {
}

$query = $this->db->placehold("SELECT $select
FROM __subescribe_mailing s
FROM __subscribe_mailing s
$joins
WHERE
$where
Expand Down
35 changes: 20 additions & 15 deletions api/Variants.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,27 +179,32 @@ public function add_variant($variant) {
return $variant_id;
}

public function delete_variant($id) {
if(!empty($id)) {
$this->delete_attachment($id);
$query = $this->db->placehold("DELETE FROM __variants WHERE id = ? LIMIT 1", intval($id));
public function delete_variant($ids) {
$ids = (array)$ids;
if (!empty($ids)) {
$this->delete_attachment($ids);
$query = $this->db->placehold("DELETE FROM __variants WHERE id IN (?@)", $ids);
$this->db->query($query);
$this->db->query('UPDATE __purchases SET variant_id=NULL WHERE variant_id=?', intval($id));
$this->db->query("DELETE FROM __lang_variants WHERE variant_id = ?", intval($id));
$this->db->query('UPDATE __purchases SET variant_id=NULL WHERE variant_id IN (?@)', $ids);
$this->db->query("DELETE FROM __lang_variants WHERE variant_id IN (?@)", $ids);
}
}

public function delete_attachment($id) {
$query = $this->db->placehold("SELECT attachment FROM __variants WHERE id=?", $id);
public function delete_attachment($ids) {
$ids = (array)$ids;
$query = $this->db->placehold("SELECT id, attachment FROM __variants WHERE id IN (?@) AND attachment !=''", $ids);
$this->db->query($query);
$filename = $this->db->result('attachment');
$query = $this->db->placehold("SELECT 1 FROM __variants WHERE attachment=? AND id!=?", $filename, $id);
$this->db->query($query);
$exists = $this->db->num_rows();
if(!empty($filename) && $exists == 0) {
@unlink($this->config->root_dir.'/'.$this->config->downloads_dir.$filename);
$results = (array)$this->db->results();

foreach ($results as $result) {
$query = $this->db->placehold("SELECT 1 FROM __variants WHERE attachment=? AND id!=?", $result->filename, $result->id);
$this->db->query($query);
$exists = $this->db->num_rows();
if (!empty($result->filename) && $exists == 0) {
@unlink($this->config->root_dir . '/' . $this->config->downloads_dir . $result->filename);
}
$this->update_variant($result->id, array('attachment' => null));
}
$this->update_variant($id, array('attachment'=>null));
}

}
33 changes: 30 additions & 3 deletions backend/ajax/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,28 @@ private function import_item($item) {

// Если задан артикул варианта, найдем этот вариант и соответствующий товар
if (!empty($variant['sku'])) {
$this->db->query('SELECT v.id as variant_id, v.product_id, p.url FROM __variants v, __products p WHERE v.sku=? AND v.product_id = p.id LIMIT 1', $variant['sku']);

// Если у варианта есть еще и название, тогда ищем по артикулу + название, это как бы первичный ключ будет,
// чтобы можно было импортировать варианты с одинаковым артикулом
$variant_filter = '';
if (!empty($variant['name'])) {
$variant_filter = $this->db->placehold(" AND v.name=?", $variant['name']);
}

$this->db->query("SELECT v.id as variant_id, v.product_id
FROM __variants v
WHERE
v.sku=?
$variant_filter
LIMIT 1", $variant['sku']);
$result = $this->db->result();
if ($result) {
$product_id = $result->product_id;
$variant_id = $result->variant_id;
$imported_item->status = 'updated';
} elseif (!empty($product['name'])) {
// если по артикулу не нашли попробуем по названию(если он задано)
$this->db->query('SELECT p.id as product_id, p.url FROM __products p WHERE p.name=? LIMIT 1', $product['name']);
$this->db->query('SELECT p.id as product_id FROM __products p WHERE p.name=? LIMIT 1', $product['name']);
$result = $this->db->result();
if ($result) {
$product_id = $result->product_id;
Expand All @@ -222,7 +235,7 @@ private function import_item($item) {
}
} else {
// если нет артикула попробуем по названию товара
$this->db->query('SELECT v.id as variant_id, p.id as product_id, p.url
$this->db->query('SELECT v.id as variant_id, p.id as product_id
FROM __products p
LEFT JOIN __variants v ON v.product_id=p.id AND v.name=?
WHERE p.name=?
Expand All @@ -248,6 +261,20 @@ private function import_item($item) {
$product['url'] = $this->translit($product['name']);
}
if (empty($product_id)) {

// Если для нового товара не заданы метаданные, запишем туда название товара
if (!isset($product['meta_title']) || empty($product['meta_title'])) {
$product['meta_title'] = $product['name'];
}

if (!isset($product['meta_keywords']) || empty($product['meta_keywords'])) {
$product['meta_keywords'] = $product['name'];
}

if (!isset($product['meta_description']) || empty($product['meta_description'])) {
$product['meta_description'] = $product['name'];
}

$product_id = $this->products->add_product($product);
} else {
$this->products->update_product($product_id, $product);
Expand Down
4 changes: 1 addition & 3 deletions backend/core/ProductsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ public function fetch() {
}
case 'delete': {
/*Удалить товар*/
foreach($ids as $id) {
$this->products->delete_product($id);
}
$this->products->delete_product($ids);
break;
}
case 'duplicate': {
Expand Down
2 changes: 1 addition & 1 deletion backend/design/html/brands.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
{/if}
</select>
</div>
<div class="col-lg-8 col-md-6 col-sm-12 fn_additional_params">
<div class="fn_additional_params">
<div class="fn_move_to_page col-lg-12 col-md-12 col-sm-12 hidden fn_hide_block">
<select name="target_page" class="selectpicker">
{section target_page $pages_count}
Expand Down
2 changes: 1 addition & 1 deletion backend/design/html/features.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
{/if}
</select>
</div>
<div class="col-lg-8 col-md-6 col-sm-12 fn_additional_params">
<div class="fn_additional_params">
<div class="fn_move_to_page col-lg-12 col-md-12 col-sm-12 hidden fn_hide_block">
<select name="target_page" class="selectpicker">
{section target_page $pages_count}
Expand Down
Loading

0 comments on commit 1a1db59

Please sign in to comment.