protected function generateProductsData() { $delimiter = ';'; $titles = array(); $id_lang = $this->use_lang; $new_path = new Sampledatainstall(); $f = fopen($new_path->sendPath() . 'output/products.vsc', 'w'); foreach ($this->product_fields as $field => $array) { $titles[] = $array['label']; } fputcsv($f, $titles, $delimiter, '"'); $products = Product::getProducts($id_lang, 0, 0, 'id_product', 'ASC', false, true); foreach ($products as $product) { $line = array(); $p = new Product($product['id_product'], true, $id_lang, 1); foreach ($this->product_fields as $field => $array) { $line[$field] = property_exists('Product', $field) && !is_array($p->{$field}) && !Tools::isEmpty($p->{$field}) ? $p->{$field} : ''; } $cats = $p->getProductCategoriesFull($p->id, 1); $cat_array = array(); foreach ($cats as $cat) { $cat_array[] = $cat['id_category']; } $line['categories'] = implode(',', $cat_array); $line['price_tex'] = $p->getPrice(false); $line['price_tin'] = $p->getPrice(true); $line['upc'] = $p->upc ? $p->upc : ''; $line['features'] = ''; $features = $p->getFrontFeatures($id_lang); $position = 1; $devider = ''; foreach ($features as $feature) { $sql = 'SELECT `id_feature` FROM ' . _DB_PREFIX_ . 'feature_lang WHERE `name` = "' . pSql($feature['name']) . '"'; $sql1 = 'SELECT `id_feature_value` FROM ' . _DB_PREFIX_ . 'feature_value_lang WHERE `value` = "' . pSql($feature['value']) . '"'; $id_feature = Db::getInstance()->getValue($sql); $id_feature_value = Db::getInstance()->getValue($sql1); $line['features'] .= $devider . $id_feature . ':' . $id_feature_value . ':' . $position; $devider = ','; $position++; } $specificPrice = SpecificPrice::getSpecificPrice($p->id, 1, 0, 0, 0, 0); $line['reduction_price'] = ''; $line['reduction_percent'] = ''; $line['reduction_from'] = ''; $line['reduction_to'] = ''; if ($specificPrice) { if ($specificPrice['reduction_type'] == 'amount') { $line['reduction_price'] = $specificPrice['reduction']; } elseif ($specificPrice['reduction_type'] == 'percent') { $line['reduction_percent'] = $specificPrice['reduction']; } if ($line['reduction_price'] !== '' || $line['reduction_percent'] !== '') { $line['reduction_from'] = $specificPrice['from']; $line['reduction_to'] = $specificPrice['to']; } } $tags = $p->getTags($id_lang); $line['tags'] = $tags; $link = new Link(); $imagelinks = array(); $images = $p->getImages($id_lang); foreach ($images as $image) { $imagelink = Tools::getShopProtocol() . $link->getImageLink($p->link_rewrite, $p->id . '-' . $image['id_image']); $this->copyConverFileName($imagelink); $imagelinks[] = $imagelink; } $line['image'] = implode(',', $imagelinks); $line['delete_existing_images'] = 0; $line['shop'] = 1; $warehouses = Warehouse::getWarehousesByProductId($p->id); $line['warehouse'] = ''; if (!empty($warehouses)) { $line['warehouse'] = implode(',', array_map("{$this->getWarehouses}", $warehouses)); } $values = array(); $accesories = $p->getAccessories($id_lang); if (isset($accesories) && $accesories && count($accesories)) { foreach ($accesories as $accesorie) { $values[] = $accesorie['id_product']; } } $line['accessories'] = $values ? implode(',', $values) : ''; $values = array(); $carriers = $p->getCarriers(); if (isset($carriers) && $carriers && count($carriers)) { foreach ($carriers as $carrier) { $values[] = $carrier['id_carrier']; } } $line['carriers'] = $values ? implode(',', $values) : ''; $values = array(); $customization_fields_ids = $p->getCustomizationFieldIds(); if (class_exists('CustomizationField') && isset($customization_fields_ids) && $customization_fields_ids && count($customization_fields_ids)) { foreach ($customization_fields_ids as $customization_field_id) { $cf = new CustomizationField($customization_field_id['id_customization_field'], $this->use_lang); $values[] = $cf->id . ':' . $cf->type . ':' . $cf->required . ':' . $cf->name; } } $line['customization_fields_ids'] = $values ? implode(',', $values) : ''; $values = array(); $attachments = $p->getAttachments($this->use_lang); if (isset($attachments) && $attachments && count($attachments)) { foreach ($attachments as $attachment) { $values[] = $attachment['id_attachment']; } } $line['attachments'] = $values ? implode(',', $values) : ''; if (!property_exists('Product', 'base_price')) { // for versions < 1.6.0.13 $line['base_price'] = !is_array($p->base_price) && !Tools::isEmpty($p->base_price) ? $p->base_price : ''; } if (!$line[$field]) { $line[$field] = ''; } fputcsv($f, $line, $delimiter, '"'); } fclose($f); }