Пример #1
0
    /**
     * Remove a shop only if it has no dependencies, and remove its associations
     *
     * @return bool
     */
    public function delete()
    {
        if (Shop::hasDependency($this->id) || !($res = parent::delete())) {
            return false;
        }
        foreach (Shop::getAssoTables() as $table_name => $row) {
            $id = 'id_' . $row['type'];
            if ($row['type'] == 'fk_shop') {
                $id = 'id_shop';
            } else {
                $table_name .= '_' . $row['type'];
            }
            $res &= Db::getInstance()->execute('
				DELETE FROM `' . bqSQL(_DB_PREFIX_ . $table_name) . '`
				WHERE `' . bqSQL($id) . '`=' . (int) $this->id);
        }
        // removes stock available
        $res &= Db::getInstance()->delete('stock_available', 'id_shop = ' . (int) $this->id);
        // Remove urls
        $res &= Db::getInstance()->delete('shop_url', 'id_shop = ' . (int) $this->id);
        Shop::cacheShops(true);
        return $res;
    }
Пример #2
0
 public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
 {
     if (Shop::getContext() == Shop::CONTEXT_GROUP) {
         $this->_where .= ' AND a.id_shop_group = ' . (int) Shop::getContextShopGroupID();
     }
     parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
     $shop_delete_list = array();
     // don't allow to remove shop which have dependencies (customers / orders / ... )
     foreach ($this->_list as &$shop) {
         if (Shop::hasDependency($shop['id_shop'])) {
             $shop_delete_list[] = $shop['id_shop'];
         }
     }
     $this->context->smarty->assign('shops_having_dependencies', $shop_delete_list);
 }