<?php $category_model = new shopCategoryModel(); foreach ($category_model->select('id, conditions')->where('type = 1')->fetchAll('id') as $item) { $conditions = preg_replace('/\\brate\\b/', 'rating', $item['conditions']); if ($conditions != $item['conditions']) { $category_model->updateById($item['id'], array('conditions' => $conditions)); } }
/** * Delete products from category * * @param int $category_id * @param array|bool $product_ids If true than delete all products from category * @return boolean */ public function deleteProducts($category_id, $product_ids = array()) { if (!$category_id) { return false; } $category_model = new shopCategoryModel(); if ($product_ids === true) { $product_ids = array_keys($this->select('product_id')->where('category_id = :c_id', array('c_id' => $category_id))->fetchAll('product_id', true)); if (!$this->deleteByField('category_id', $category_id)) { return false; } if (!$category_model->updateById($category_id, array('count' => 0))) { return false; } } else { if (!$this->deleteByField(array('category_id' => $category_id, 'product_id' => $product_ids))) { return false; } if (!$category_model->recount($category_id)) { return false; } } $product_model = new shopProductModel(); $product_model->correctMainCategory($product_ids); return true; }