Beispiel #1
0
 public function getNextProduct()
 {
     if (!$this->productSql) {
         foreach ($this->languages as $code => $id) {
             list($join[], $langs[]) = $this->joinProductFields($id, $code);
         }
         foreach ($this->attributes as $attr) {
             $join[] = 'LEFT JOIN ' . $this->getTablePrefix() . 'extra_field_values  AS extra_' . $attr['fieldid'] . ' ON (extra_' . $attr['fieldid'] . '.productid=' . $this->getTablePrefix() . 'products.productid AND extra_' . $attr['fieldid'] . '.fieldid=' . $attr['fieldid'] . ')';
             $langs[] = 'extra_' . $attr['fieldid'] . '.value AS extrafield_' . $attr['fieldid'];
         }
         $this->productSql = 'SELECT ' . $this->getTablePrefix() . 'products.*, ' . $this->getTablePrefix() . 'products_categories.categoryid ' . ($langs ? ',' : '') . implode(', ', $langs) . ', (SELECT price FROM ' . $this->getTablePrefix() . 'pricing WHERE ' . $this->getTablePrefix() . 'pricing.productid=' . $this->getTablePrefix() . 'products.productid ORDER BY quantity ASC LIMIT 1) AS price FROM ' . $this->getTablePrefix() . 'products ' . implode(' ', $join) . ' LEFT JOIN ' . $this->getTablePrefix() . 'products_categories ON (' . $this->getTablePrefix() . 'products.productid=' . $this->getTablePrefix() . 'products_categories.productid AND ' . $this->getTablePrefix() . 'products_categories.main="Y")';
     }
     if (!($data = $this->loadRecord($this->productSql))) {
         return null;
     }
     $rec = Product::getNewInstance(Category::getInstanceById($this->getRealId('Category', $data['categoryid'])));
     $rec->setID($data['productid']);
     $rec->keywords->set($data['keywords']);
     $rec->setValueByLang('name', $this->defLang, $data['product']);
     $rec->setValueByLang('longDescription', $this->defLang, $data['fulldescr']);
     $rec->setValueByLang('shortDescription', $this->defLang, $data['descr']);
     foreach ($this->languages as $code => $id) {
         $rec->setValueByLang('name', $code, $data['name_' . $code]);
         $rec->setValueByLang('longDescription', $code, $data['fulldescr_' . $code]);
         $rec->setValueByLang('shortDescription', $code, $data['descr_' . $code]);
     }
     foreach ($this->attributes as $attr) {
         if (!empty($data['extrafield_' . $attr['fieldid']])) {
             $rec->setAttributeValueByLang(SpecField::getInstanceByID($this->getRealId('SpecField', $attr['fieldid']), SpecField::LOAD_DATA), $this->defLang, $data['extrafield_' . $attr['fieldid']]);
         }
     }
     if ($data['manufacturerid']) {
         $rec->manufacturer->set(Manufacturer::getInstanceById($this->getRealId('Manufacturer', $data['manufacturerid'])));
     }
     foreach (array('sku' => 'productcode', 'shippingWeight' => 'weight', 'stockCount' => 'avail', 'shippingSurchargeAmount' => 'shipping_freight', 'minimumQuantity' => 'min_amount', 'dateCreated' => 'add_date') as $lc => $xc) {
         $rec->{$lc}->set($data[$xc]);
     }
     $rec->isEnabled->set('Y' == $data['forsale']);
     $rec->setPrice($this->getDefaultCurrency(), $data['price']);
     //images
     $images = array_merge($this->getDataBySQL('SELECT * FROM ' . $this->getTablePrefix() . 'images_t WHERE id=' . $data['productid'] . ' ORDER BY orderby ASC'), $this->getDataBySQL('SELECT * FROM ' . $this->getTablePrefix() . 'images_d WHERE id=' . $data['productid'] . ' ORDER BY orderby ASC'));
     foreach ($images as $image) {
         $this->importProductImage($rec, $this->path . '/' . $image['image_path']);
     }
     $rec->rawData = $data;
     return $rec;
 }
Beispiel #2
0
 public function getNextProduct()
 {
     if (!$this->productSql) {
         foreach ($this->languages as $id => $code) {
             list($join[], $langs[]) = $this->joinProductFields($id, $code);
         }
         $this->productSql = 'SELECT *,' . implode(', ', $langs) . ' FROM ' . $this->getTablePrefix() . 'products ' . implode(' ', $join) . ' LEFT JOIN ' . $this->getTablePrefix() . 'products_to_categories ON ' . $this->getTablePrefix() . 'products.products_id=' . $this->getTablePrefix() . 'products_to_categories.products_id LEFT JOIN ' . $this->getTablePrefix() . 'categories ON ' . $this->getTablePrefix() . 'products_to_categories.categories_id=' . $this->getTablePrefix() . 'categories.categories_id  WHERE ' . $this->getTablePrefix() . 'categories.categories_id IS NOT NULL GROUP BY ' . $this->getTablePrefix() . 'products.products_id';
     }
     if (!($data = $this->loadRecord($this->productSql))) {
         return null;
     }
     $rec = Product::getNewInstance(Category::getInstanceById($this->getRealId('Category', $data['categories_id'])));
     $rec->setID($data['products_id']);
     foreach ($this->languages as $code) {
         $rec->setValueByLang('name', $code, $data['name_' . $code]);
         $rec->setValueByLang('longDescription', $code, $data['descr_' . $code]);
         // use the first line or paragraph of the long description as the short description
         $short = array_shift(preg_split("/\n|\\<br/", $data['descr_' . $code]));
         $rec->setValueByLang('shortDescription', $code, $short);
     }
     if ($data['manufacturers_id']) {
         try {
             $man = Manufacturer::getInstanceById($this->getRealId('Manufacturer', $data['manufacturers_id']), true);
             $man->load();
             $rec->manufacturer->set($man);
         } catch (Exception $e) {
             // orphan data
         }
     }
     $rec->sku->set($data['products_model']);
     $rec->URL->set($data['products_url']);
     $rec->isEnabled->set((int) (1 == $data['products_status']));
     $rec->shippingWeight->set($data['products_weight']);
     $rec->stockCount->set($data['products_quantity']);
     $rec->dateCreated->set($data['products_date_added']);
     $rec->setPrice($this->getConfigValue('DEFAULT_CURRENCY'), $data['products_price']);
     //product image
     if ($data['products_image']) {
         $this->importProductImage($rec, $this->path . '/images/' . $data['products_image']);
     }
     $rec->rawData = $data;
     return $rec;
 }