Dmitry86 Опубликовано 23 августа, 2019 Жалоба Поделиться Опубликовано 23 августа, 2019 (изменено) Ребят, прошу помощи. В api/Products.php есть функции для добавления видео в карточке товара (сделаны по типу связанных товаров, только вместо товаров добавляются url на ютуб): function get_videos($filter = array()) { $product_id_filter = ''; if(!empty($filter['product_id'])) $product_id_filter = $this->db->placehold('AND v.product_id in(?@)', (array)$filter['product_id']); $query = $this->db->placehold("SELECT v.product_id, v.url, v.position FROM __videos AS v WHERE 1 $product_id_filter ORDER BY v.product_id, v.position"); $this->db->query($query); return $this->db->results(); } public function add_video($product_id, $url, $pos) { $query = $this->db->placehold("INSERT INTO __videos SET product_id=?, url=?, position=?", $product_id, $url, $pos); $this->db->query($query); } Надо, чтобы при копировании товара видео тоже копировались по типу как и связанные товары. Вот функция копирования: public function duplicate_product($id) { $product = $this->get_product($id); $product->id = null; $product->created = null; /* some fix */ unset($product->id,$product->created,$product->new_product,$product->main_category_id,$product->main_category_name,$product->product_code, $product->price); // Сдвигаем товары вперед и вставляем копию на соседнюю позицию $this->db->query('UPDATE __products SET position=position+1 WHERE position>?', $product->position); $product->name = $product->name.' копия'; $product->url = $product->url.'-copy'; $new_id = $this->products->add_product($product); $this->db->query('UPDATE __products SET position=? WHERE id=?', $product->position+1, $new_id); // Очищаем url // $this->db->query('UPDATE __products SET url="" WHERE id=?', $new_id); // Дублируем категории $categories = $this->categories->get_product_categories($id); foreach($categories as $c) $this->categories->add_product_category($new_id, $c->category_id); // Дублируем изображения $images = $this->get_images(array('product_id'=>$id)); foreach($images as $image) $this->add_image($new_id, $image->filename); // Дублируем варианты $variants = $this->variants->get_variants(array('product_id'=>$id)); foreach($variants as $variant) { $variant->product_id = $new_id; unset($variant->id); if($variant->infinity) $variant->stock = null; unset($variant->infinity); $variant->price = $variant->oprice; $variant->compare_price = $variant->compare_oprice; unset($variant->compare_oprice, $variant->oprice); $this->variants->add_variant($variant); } // Дублируем свойства $options = $this->features->get_options(array('product_id'=>$id)); foreach($options as $o) $this->features->update_option($new_id, $o->feature_id, $o->value); // Дублируем связанные товары $related = $this->get_related_products($id); foreach($related as $r) $this->add_related_product($new_id, $r->related_id); return $new_id; }Спасибо! Изменено 23 августа, 2019 пользователем Dmitry86 Цитата Ссылка на сообщение Поделиться на другие сайты
phukortsin Опубликовано 24 августа, 2019 Жалоба Поделиться Опубликовано 24 августа, 2019 Полная аналогия с images, примерно так // Дублируем video $images = $this->get_videos(array('product_id'=>$id)); foreach($images as $image) $this->add_video($new_id, $image->url, $image->position); Цитата Ссылка на сообщение Поделиться на другие сайты
Dmitry86 Опубликовано 26 августа, 2019 Автор Жалоба Поделиться Опубликовано 26 августа, 2019 Полная аналогия с images, примерно так // Дублируем video $images = $this->get_videos(array('product_id'=>$id)); foreach($images as $image) $this->add_video($new_id, $image->url, $image->position); Благодарю за ответ, всё работает. Спасибо! Цитата Ссылка на сообщение Поделиться на другие сайты
Рекомендуемые сообщения
Присоединяйтесь к обсуждению
Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.