Merge remote-tracking branch 'origin/ticket-14739-PackLogistic'
This commit is contained in:
commit
1d5578d66b
@ -79,7 +79,16 @@ class AdminImport extends AdminTab
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->entities = array_flip(array($this->l('Categories'), $this->l('Products'), $this->l('Combinations'), $this->l('Customers'), $this->l('Addresses'), $this->l('Manufacturers'), $this->l('Suppliers')));
|
$this->entities = array_flip(array(
|
||||||
|
$this->l('Categories'),
|
||||||
|
$this->l('Products'),
|
||||||
|
$this->l('Combinations'),
|
||||||
|
$this->l('Customers'),
|
||||||
|
$this->l('Addresses'),
|
||||||
|
$this->l('Manufacturers'),
|
||||||
|
$this->l('Suppliers'),
|
||||||
|
$this->l('Pack'),
|
||||||
|
));
|
||||||
|
|
||||||
switch ((int)(Tools::getValue('entity')))
|
switch ((int)(Tools::getValue('entity')))
|
||||||
{
|
{
|
||||||
@ -280,7 +289,19 @@ class AdminImport extends AdminTab
|
|||||||
'meta_keywords' => array('label' => $this->l('Meta-keywords')),
|
'meta_keywords' => array('label' => $this->l('Meta-keywords')),
|
||||||
'meta_description' => array('label' => $this->l('Meta-description')));
|
'meta_description' => array('label' => $this->l('Meta-description')));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case $this->entities[$this->l('Pack')]:
|
||||||
|
|
||||||
|
self::$required_fields = array('id_product_item', 'qty', 'id');
|
||||||
|
|
||||||
|
$this->available_fields = array(
|
||||||
|
'id_product_item' => array('label' => $this->l('ID Item')),
|
||||||
|
'qty' => array('label' => $this->l('Quantity Item')),
|
||||||
|
'id' => array('label' => $this->l('ID Pack')),
|
||||||
|
);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1292,6 +1313,51 @@ class AdminImport extends AdminTab
|
|||||||
}
|
}
|
||||||
$this->closeCsvFile($handle);
|
$this->closeCsvFile($handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function packImport()
|
||||||
|
{
|
||||||
|
$this->receiveTab();
|
||||||
|
$handle = $this->openCsvFile();
|
||||||
|
self::setLocale();
|
||||||
|
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++)
|
||||||
|
{
|
||||||
|
if (Tools::getValue('convert')) {
|
||||||
|
$line = $this->utf8_encode_array($line);
|
||||||
|
}
|
||||||
|
$info = self::getMaskedRow($line);
|
||||||
|
|
||||||
|
self::setDefaultValues($info);
|
||||||
|
|
||||||
|
// Is product a pack
|
||||||
|
if (array_key_exists('id', $info) && (int)($info['id']) && Pack::isPack((int)($info['id']))) {
|
||||||
|
$pack = new Pack((int)($info['id']));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$pack = new Pack();
|
||||||
|
}
|
||||||
|
|
||||||
|
self::array_walk($info, array('AdminImport', 'fillInfo'), $pack);
|
||||||
|
if (($fieldError = $pack->validateFields(UNFRIENDLY_ERROR, true)) === true && is_numeric($info['qty']))
|
||||||
|
{
|
||||||
|
$res = false;
|
||||||
|
// Is product item in pack
|
||||||
|
if ($pack->isPacked($info['id_product_item'])) {
|
||||||
|
$res = $pack->updateItem($info['id'], $info['id_product_item'], $info['qty']);
|
||||||
|
}
|
||||||
|
// Insert
|
||||||
|
if (!$res) {
|
||||||
|
$res = $pack->addItem($info['id'], $info['id_product_item'], $info['qty']);
|
||||||
|
}
|
||||||
|
if (!$res) {
|
||||||
|
$this->_errors[] = mysql_error().' '.$info['id_product_item'].(isset($info['id']) ? ' (ID '.$info['id'].')' : '').' '.Tools::displayError('Cannot be saved');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->_errors[] = ($fieldError !== true ? $fieldError : '').($langFieldError !== true ? $langFieldError : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->closeCsvFile($handle);
|
||||||
|
}
|
||||||
|
|
||||||
public function display()
|
public function display()
|
||||||
{
|
{
|
||||||
@ -1824,6 +1890,9 @@ class AdminImport extends AdminTab
|
|||||||
case $this->entities[$this->l('Suppliers')]:
|
case $this->entities[$this->l('Suppliers')]:
|
||||||
$this->supplierImport();
|
$this->supplierImport();
|
||||||
break;
|
break;
|
||||||
|
case $this->entities[$this->l('Pack')]:
|
||||||
|
$this->packImport();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$this->_errors[] = $this->l('no entity selected');
|
$this->_errors[] = $this->l('no entity selected');
|
||||||
}
|
}
|
||||||
|
@ -174,18 +174,30 @@ class PackCore extends Product
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an item to the pack
|
* Add an item to the pack
|
||||||
*
|
* @param integer $id_product
|
||||||
* @param integer $id_product
|
* @param integer $id_item
|
||||||
* @param integer $id_item
|
* @param integer $qty
|
||||||
* @param integer $qty
|
* @return boolean true if everything was fine
|
||||||
* @return boolean true if everything was fine
|
*/
|
||||||
*/
|
|
||||||
public static function addItem($id_product, $id_item, $qty)
|
public static function addItem($id_product, $id_item, $qty)
|
||||||
{
|
{
|
||||||
Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'product SET cache_is_pack = 1 WHERE id_product = '.(int)($id_product).' LIMIT 1');
|
Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'product SET cache_is_pack = 1 WHERE id_product = '.(int)($id_product).' LIMIT 1');
|
||||||
return Db::getInstance()->AutoExecute(_DB_PREFIX_.'pack', array('id_product_pack' => (int)($id_product), 'id_product_item' => (int)($id_item), 'quantity' => (int)($qty)), 'INSERT');
|
return Db::getInstance()->AutoExecute(_DB_PREFIX_.'pack', array('id_product_pack' => (int)($id_product), 'id_product_item' => (int)($id_item), 'quantity' => (int)($qty)), 'INSERT');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update item and his pack association
|
||||||
|
* @param integer $id_product
|
||||||
|
* @param integer $id_item
|
||||||
|
* @param integer $qty
|
||||||
|
* @return boolean true if everything was fine
|
||||||
|
*/
|
||||||
|
public static function updateItem($id_product, $id_item, $qty)
|
||||||
|
{
|
||||||
|
return Db::getInstance()->AutoExecute(_DB_PREFIX_.'pack', array('quantity' => (int)($qty)),
|
||||||
|
'UPDATE', 'id_product_pack='.(int)($id_product).' AND id_product_item='.(int)($id_item));
|
||||||
|
}
|
||||||
|
|
||||||
public static function duplicate($id_product_old, $id_product_new)
|
public static function duplicate($id_product_old, $id_product_new)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user