Esempio n. 1
0
 /**
  * Insert data (Step 2)
  *
  * @param Pimgento_Core_Model_Task $task
  *
  * @return bool
  * @throws Exception
  */
 public function insertData($task)
 {
     $file = $task->getFile();
     $lines = $this->getRequest()->insertDataFromFile($this->getCode(), $file);
     if (!$lines) {
         $task->error(Mage::helper('pimgento_asset')->__('No data to insert, verify the file is not empty or CSV configuration is correct'));
     }
     $task->setMessage(Mage::helper('pimgento_asset')->__('%s lines found', $lines));
     return true;
 }
Esempio n. 2
0
 /**
  * Set values to attributes (Step 9)
  *
  * @param Pimgento_Core_Model_Task $task
  *
  * @return bool
  */
 public function setValues($task)
 {
     $adapter = $this->getAdapter();
     $file = $task->getFile();
     $values = array('options_container' => '_options_container', 'tax_class_id' => '_tax_class_id', 'enable_googlecheckout' => $this->_zde(0), 'is_recurring' => $this->_zde(0), 'visibility' => $this->_zde(4));
     if ($this->getConfig('configurable_enabled')) {
         $values['visibility'] = $this->_zde('IF(`_type_id` = "simple" AND `groups` <> "", 1, 4)');
     }
     $this->getRequest()->setValues($this->getCode(), 'catalog/product', $values, 4, 0);
     /* @var $helper Pimgento_Core_Helper_Data */
     $helper = Mage::helper('pimgento_core');
     $codes = array_merge($helper->getStoresLang(), $helper->getStoresWebsites());
     $columns = $this->getRequest()->getFirstLine($file);
     $transformer = Mage::helper('pimgento_product')->transformer();
     foreach ($columns as $column) {
         if (!$adapter->tableColumnExists($this->getTable(), $column)) {
             continue;
         }
         $translation = false;
         foreach ($codes as $code => $ids) {
             if (preg_match('/^(.*)-(.*)$/', $column)) {
                 $translation = true;
                 if (preg_match('/^(?P<attribute>[^-]*)-' . $code . '$/', $column, $matches)) {
                     foreach ($ids as $key => $storeId) {
                         $values = array($matches['attribute'] => $column);
                         if (isset($transformer[$matches['attribute']])) {
                             $match = $transformer[$matches['attribute']];
                             foreach ($match as $attribute) {
                                 $values[$attribute] = $column;
                             }
                         }
                         foreach ($values as $attribute => $column) {
                             if ($attribute == 'url_key') {
                                 $adapter->addColumn($this->getTable(), $column . '_' . $key, 'VARCHAR(255) NOT NULL default ""');
                                 $values = array($column . '_' . $key => $this->_zde('CONCAT(`' . $column . '`,"-' . $key . '")'));
                                 $adapter->update($this->getTable(), $values);
                                 $values[$attribute] = $column . '_' . $key;
                             }
                         }
                         $this->getRequest()->setValues($this->getCode(), 'catalog/product', $values, 4, $storeId);
                     }
                 }
             }
         }
         if (!$translation) {
             $values = array($column => $column);
             if (isset($transformer[$column])) {
                 $match = $transformer[$column];
                 foreach ($match as $attribute) {
                     $values[$attribute] = $column;
                 }
             }
             $this->getRequest()->setValues($this->getCode(), 'catalog/product', $values, 4, 0);
         }
     }
     return true;
 }