public function __construct($id = null, $id_lang = null, $id_shop = null)
 {
     Cache::Clean('objectmodel_def_WarehouseProductLocation');
     self::$definition['fields']['location'] = array('type' => self::TYPE_INT, 'validate' => 'isReference');
     //self::$definition['fields']['zone'] = array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 50);
     //self::$definition['fields']['sous_zone'] = array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 50);
     parent::__construct($id, $id_lang, $id_shop);
 }
Ejemplo n.º 2
0
 /**
  * For a given product and warehouse, gets the product warehouse data
  *
  * @param int $id_product
  * @param int $id_product_attribute
  * @param int $id_warehouse
  * @return array
  */
 public function getWarehouseProductLocationData($id_product, $id_product_attribute, $id_warehouse)
 {
     $location = \WarehouseProductLocationCore::getProductLocation($id_product, $id_product_attribute, $id_warehouse);
     // for 'activated', we test if $location is ===false or ==="", that's the only difference to know it...
     return ['location' => $location, 'activated' => $location !== false, 'product_id' => $id_product];
 }
 public function postProcess()
 {
     if (Tools::isSubmit('submitFilterconfiguration')) {
         // get an array with first paramettre id_product, second paramettre id_product attribute, third area
         // fourth id_wharehouse_product_location, fifth id_erpip_warhouse_product_location
         $areas = Tools::getValue('data_location');
         if (!empty($areas) && is_array($areas)) {
             foreach ($areas as $id_product => $product) {
                 foreach ($product as $id_attribute => $attribute) {
                     // data already exists in warehouse product location table
                     if (!empty($attribute['id_warehouse_product_location']) && $attribute['id_warehouse_product_location'] != '0') {
                         $warehouse = new WarehouseProductLocationCore((int) $attribute['id_warehouse_product_location']);
                     } else {
                         $warehouse = new WarehouseProductLocationCore();
                         $warehouse->id_product = (int) $id_product;
                         $warehouse->id_product_attribute = (int) $id_attribute;
                         $warehouse->id_warehouse = (int) Tools::getValue('id_warehouse');
                     }
                     //save location
                     $warehouse->location = empty($attribute['location']) ? null : $attribute['location'];
                     $warehouse->save();
                     // data not exists in ERP warehouse product location table
                     if ($attribute['id_erpip_warehouse_product_location'] == '0') {
                         $erp_warehouse = new ErpWarehouseProductLocation();
                     } else {
                         $erp_warehouse = new ErpWarehouseProductLocation((int) $attribute['id_erpip_warehouse_product_location']);
                     }
                     // save area and sub area
                     $erp_warehouse->id_warehouse_product_location = (int) $warehouse->id;
                     $erp_warehouse->id_zone_parent = empty($attribute['area']) ? null : (int) $attribute['area'];
                     //id_zone_parent  = area
                     $erp_warehouse->id_zone = empty($attribute['sub_area']) ? null : (int) $attribute['sub_area'];
                     //id_zone = sub_area
                     $erp_warehouse->save();
                 }
             }
             $this->confirmations[] = $this->l('Locations updated successfully');
         }
     }
     if (Tools::isSubmit('createImageStock')) {
         // list of stock images
         $images = Tools::getValue('images');
         if (!empty($images) && is_array($images)) {
             foreach ($images as $image) {
                 //if isset id_image then this is the selected images stock
                 if (isset($image['id_stock_image'])) {
                     $stock_image = new StockImage();
                     $stock_image->createImage((int) $image['id_stock_image'], $image['name_stock_image']);
                     break;
                 }
             }
         }
     }
     //Display Information or confirmation message / error of end of inventory
     switch (Tools::getValue('submitFilterstock')) {
         case 0:
             $this->displayInformation($this->l('You may create a new stock image or select an older one'));
             break;
         case 1:
             $this->confirmations[] = $this->l('New image saved');
             break;
         case 2:
             $this->errors[] = Tools::displayError('Error while handling products');
             break;
         default:
             $this->displayInformation($this->l('You may create a new stock image or select an older one'));
             break;
     }
     // Stock image selection
     $this->context->smarty->assign(array('images' => StockImage::getStockImages(), 'pack' => ERP_SLOT_IPTIMEMACHINE, 'id_warehouse' => Tools::getValue('id_warehouse')));
     $this->getCurrentValue('id_image');
     // Get context link and display toolbar
     $this->context_link = $this->context->link;
     $this->initToolbar();
     $this->initPageHeaderToolbar();
     require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php';
     $this->context->smarty->assign(array('erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path));
     return parent::postProcess();
 }