Jump to content
Sign in to follow this  
newjey

[Заработало] Автогенирация sku в чём проблема?

Recommended Posts

Добрый день.

Под 1.5 opencart делал такую модификацию по автогенерации sku

admin/model/catalog/product.php

в самом начале вставить код:
$sku = rand ( 100 , 999 ) . "-" . $product_id;
$this->db->query("UPDATE " . DB_PREFIX . "product SET sku = '" . $sku . "' WHERE product_id = '" . (int)$product_id . "'");

в opencart 2.1 аналогично вставляю код:

 

<?php
class ModelCatalogProduct extends Model {
	public function addProduct($data) {
		$this->event->trigger('pre.admin.product.add', $data);

		$this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_added = NOW()");

		$product_id = $this->db->getLastId();
		
		$sku = rand ( 100 , 999 ) . "-" . $product_id;
$this->db->query("UPDATE " . DB_PREFIX . "product SET sku = '" . $sku . "' WHERE product_id = '" . (int)$product_id . "'");

		if (isset($data['image'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape($data['image']) . "' WHERE product_id = '" . (int)$product_id . "'");
		}

Но ничего не генерируется. Подскажите что не так?

Спасибо.

Edited by newjey

Share this post


Link to post
Share on other sites

Повторил операцию и всё заработало.

Прошу прощения).

Share this post


Link to post
Share on other sites

если что - есть такой модуль ;)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.