public function hookDisplayFooterProduct() { global $smarty; global $cookie; global $db; $this_product = new Product($_GET['id_product']); $combinations = $this_product->getAttributeCombinations($cookie->id_lang); $enable = 0; for ($i = 0; $i < count($combinations); $i++) { if (strpos($combinations[$i]["group_name"], "Color") !== False) { $enable = 1; } $attributeId = new Attribute($combinations[$i]['id_attribute']); $combinations[$i]["color_value"] = $attributeId->color == '0' ? 'img/co/' . $combinations[$i]['id_attribute'] . '.jpg' : $attributeId->color; } $smarty->assign('enable', $enable); $smarty->assign('product', $this_product); $smarty->assign('combinations', $combinations); return $this->display(__FILE__, 'c1b291cb852.tpl'); }
protected function attributeImportOne($info, $default_language, &$groups, &$attributes, $regenerate, $shop_is_feature_active, $validateOnly = false) { AdminImportController::setDefaultValues($info); if (!$shop_is_feature_active) { $info['shop'] = 1; } elseif (!isset($info['shop']) || empty($info['shop'])) { $info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID()); } // Get shops for each attributes $info['shop'] = explode($this->multiple_value_separator, $info['shop']); $id_shop_list = array(); if (is_array($info['shop']) && count($info['shop'])) { foreach ($info['shop'] as $shop) { if (!empty($shop) && !is_numeric($shop)) { $id_shop_list[] = Shop::getIdByName($shop); } elseif (!empty($shop)) { $id_shop_list[] = $shop; } } } if (isset($info['id_product']) && $info['id_product']) { $product = new Product((int) $info['id_product'], false, $default_language); } elseif (Tools::getValue('match_ref') && isset($info['product_reference']) && $info['product_reference']) { $datas = Db::getInstance()->getRow(' SELECT p.`id_product` FROM `' . _DB_PREFIX_ . 'product` p ' . Shop::addSqlAssociation('product', 'p') . ' WHERE p.`reference` = "' . pSQL($info['product_reference']) . '" ', false); if (isset($datas['id_product']) && $datas['id_product']) { $product = new Product((int) $datas['id_product'], false, $default_language); } } else { return; } $id_image = array(); if (isset($info['image_url']) && $info['image_url']) { $info['image_url'] = explode($this->multiple_value_separator, $info['image_url']); if (is_array($info['image_url']) && count($info['image_url'])) { foreach ($info['image_url'] as $key => $url) { $url = trim($url); $product_has_images = (bool) Image::getImages($this->context->language->id, $product->id); $image = new Image(); $image->id_product = (int) $product->id; $image->position = Image::getHighestPosition($product->id) + 1; $image->cover = !$product_has_images ? true : false; if (isset($info['image_alt'])) { $alt = self::split($info['image_alt']); if (isset($alt[$key]) && strlen($alt[$key]) > 0) { $alt = self::createMultiLangField($alt[$key]); $image->legend = $alt; } } $field_error = $image->validateFields(UNFRIENDLY_ERROR, true); $lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true); if ($field_error === true && $lang_field_error === true && !$validateOnly && $image->add()) { $image->associateTo($id_shop_list); // FIXME: 2s/image ! if (!AdminImportController::copyImg($product->id, $image->id, $url, 'products', !$regenerate)) { $this->warnings[] = sprintf($this->trans('Error copying image: %s', array(), 'Admin.Parameters.Notification'), $url); $image->delete(); } else { $id_image[] = (int) $image->id; } // until here } else { if (!$validateOnly) { $this->warnings[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), isset($image->id_product) ? ' (' . $image->id_product . ')' : ''); } if ($field_error !== true || $lang_field_error !== true) { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . mysql_error(); } } } } } elseif (isset($info['image_position']) && $info['image_position']) { $info['image_position'] = explode($this->multiple_value_separator, $info['image_position']); if (is_array($info['image_position']) && count($info['image_position'])) { foreach ($info['image_position'] as $position) { // choose images from product by position $images = $product->getImages($default_language); if ($images) { foreach ($images as $row) { if ($row['position'] == (int) $position) { $id_image[] = (int) $row['id_image']; break; } } } if (empty($id_image)) { $this->warnings[] = sprintf($this->trans('No image was found for combination with id_product = %s and image position = %s.', array(), 'Admin.Parameters.Notification'), $product->id, (int) $position); } } } } $id_attribute_group = 0; // groups $groups_attributes = array(); if (isset($info['group'])) { foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) { if (empty($group)) { continue; } $tab_group = explode(':', $group); $group = trim($tab_group[0]); if (!isset($tab_group[1])) { $type = 'select'; } else { $type = trim($tab_group[1]); } // sets group $groups_attributes[$key]['group'] = $group; // if position is filled if (isset($tab_group[2])) { $position = trim($tab_group[2]); } else { $position = false; } if (!isset($groups[$group])) { $obj = new AttributeGroup(); $obj->is_color_group = false; $obj->group_type = pSQL($type); $obj->name[$default_language] = $group; $obj->public_name[$default_language] = $group; $obj->position = !$position ? AttributeGroup::getHigherPosition() + 1 : $position; if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { // here, cannot avoid attributeGroup insertion to avoid an error during validation step. //if (!$validateOnly) { $obj->add(); $obj->associateTo($id_shop_list); $groups[$group] = $obj->id; //} } else { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : ''); } // fills groups attributes $id_attribute_group = $obj->id; $groups_attributes[$key]['id'] = $id_attribute_group; } else { // already exists $id_attribute_group = $groups[$group]; $groups_attributes[$key]['id'] = $id_attribute_group; } } } // inits attribute $id_product_attribute = 0; $id_product_attribute_update = false; $attributes_to_add = array(); // for each attribute if (isset($info['attribute'])) { foreach (explode($this->multiple_value_separator, $info['attribute']) as $key => $attribute) { if (empty($attribute)) { continue; } $tab_attribute = explode(':', $attribute); $attribute = trim($tab_attribute[0]); // if position is filled if (isset($tab_attribute[1])) { $position = trim($tab_attribute[1]); } else { $position = false; } if (isset($groups_attributes[$key])) { $group = $groups_attributes[$key]['group']; if (!isset($attributes[$group . '_' . $attribute]) && count($groups_attributes[$key]) == 2) { $id_attribute_group = $groups_attributes[$key]['id']; $obj = new Attribute(); // sets the proper id (corresponding to the right key) $obj->id_attribute_group = $groups_attributes[$key]['id']; $obj->name[$default_language] = str_replace('\\n', '', str_replace('\\r', '', $attribute)); $obj->position = !$position && isset($groups[$group]) ? Attribute::getHigherPosition($groups[$group]) + 1 : $position; if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { if (!$validateOnly) { $obj->add(); $obj->associateTo($id_shop_list); $attributes[$group . '_' . $attribute] = $obj->id; } } else { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : ''); } } $info['minimal_quantity'] = isset($info['minimal_quantity']) && $info['minimal_quantity'] ? (int) $info['minimal_quantity'] : 1; $info['wholesale_price'] = str_replace(',', '.', $info['wholesale_price']); $info['price'] = str_replace(',', '.', $info['price']); $info['ecotax'] = str_replace(',', '.', $info['ecotax']); $info['weight'] = str_replace(',', '.', $info['weight']); $info['available_date'] = Validate::isDate($info['available_date']) ? $info['available_date'] : null; if (!Validate::isEan13($info['ean13'])) { $this->warnings[] = sprintf($this->trans('EAN13 "%1s" has incorrect value for product with id %2d.', array(), 'Admin.Parameters.Notification'), $info['ean13'], $product->id); $info['ean13'] = ''; } if ($info['default_on'] && !$validateOnly) { $product->deleteDefaultAttributes(); } // if a reference is specified for this product, get the associate id_product_attribute to UPDATE if (isset($info['reference']) && !empty($info['reference'])) { $id_product_attribute = Combination::getIdByReference($product->id, strval($info['reference'])); // updates the attribute if ($id_product_attribute && !$validateOnly) { // gets all the combinations of this product $attribute_combinations = $product->getAttributeCombinations($default_language); foreach ($attribute_combinations as $attribute_combination) { if ($id_product_attribute && in_array($id_product_attribute, $attribute_combination)) { // FIXME: ~3s/declinaison $product->updateAttribute($id_product_attribute, (double) $info['wholesale_price'], (double) $info['price'], (double) $info['weight'], 0, Configuration::get('PS_USE_ECOTAX') ? (double) $info['ecotax'] : 0, $id_image, strval($info['reference']), strval($info['ean13']), (int) $info['default_on'], 0, strval($info['upc']), (int) $info['minimal_quantity'], $info['available_date'], null, $id_shop_list); $id_product_attribute_update = true; if (isset($info['supplier_reference']) && !empty($info['supplier_reference'])) { $product->addSupplierReference($product->id_supplier, $id_product_attribute, $info['supplier_reference']); } // until here } } } } // if no attribute reference is specified, creates a new one if (!$id_product_attribute && !$validateOnly) { $id_product_attribute = $product->addCombinationEntity((double) $info['wholesale_price'], (double) $info['price'], (double) $info['weight'], 0, Configuration::get('PS_USE_ECOTAX') ? (double) $info['ecotax'] : 0, (int) $info['quantity'], $id_image, strval($info['reference']), 0, strval($info['ean13']), (int) $info['default_on'], 0, strval($info['upc']), (int) $info['minimal_quantity'], $id_shop_list, $info['available_date']); if (isset($info['supplier_reference']) && !empty($info['supplier_reference'])) { $product->addSupplierReference($product->id_supplier, $id_product_attribute, $info['supplier_reference']); } } // fills our attributes array, in order to add the attributes to the product_attribute afterwards if (isset($attributes[$group . '_' . $attribute])) { $attributes_to_add[] = (int) $attributes[$group . '_' . $attribute]; } // after insertion, we clean attribute position and group attribute position if (!$validateOnly) { $obj = new Attribute(); $obj->cleanPositions((int) $id_attribute_group, false); AttributeGroup::cleanPositions(); } } } } $product->checkDefaultAttributes(); if (!$product->cache_default_attribute && !$validateOnly) { Product::updateDefaultAttribute($product->id); } if ($id_product_attribute) { if (!$validateOnly) { // now adds the attributes in the attribute_combination table if ($id_product_attribute_update) { Db::getInstance()->execute(' DELETE FROM ' . _DB_PREFIX_ . 'product_attribute_combination WHERE id_product_attribute = ' . (int) $id_product_attribute); } foreach ($attributes_to_add as $attribute_to_add) { Db::getInstance()->execute(' INSERT IGNORE INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute) VALUES (' . (int) $attribute_to_add . ',' . (int) $id_product_attribute . ')', false); } } // set advanced stock managment if (isset($info['advanced_stock_management'])) { if ($info['advanced_stock_management'] != 1 && $info['advanced_stock_management'] != 0) { $this->warnings[] = sprintf($this->trans('Advanced stock management has incorrect value. Not set for product with id %d.', array(), 'Admin.Parameters.Notification'), $product->id); } elseif (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $info['advanced_stock_management'] == 1) { $this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, cannot enable on product with id %d.', array(), 'Admin.Parameters.Notification'), $product->id); } elseif (!$validateOnly) { $product->setAdvancedStockManagement($info['advanced_stock_management']); } // automaticly disable depends on stock, if a_s_m set to disabled if (!$validateOnly && StockAvailable::dependsOnStock($product->id) == 1 && $info['advanced_stock_management'] == 0) { StockAvailable::setProductDependsOnStock($product->id, 0, null, $id_product_attribute); } } // Check if warehouse exists if (isset($info['warehouse']) && $info['warehouse']) { if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, warehouse is not set on product with id %d.', array(), 'Admin.Parameters.Notification'), $product->id); } else { if (Warehouse::exists($info['warehouse'])) { $warehouse_location_entity = new WarehouseProductLocation(); $warehouse_location_entity->id_product = $product->id; $warehouse_location_entity->id_product_attribute = $id_product_attribute; $warehouse_location_entity->id_warehouse = $info['warehouse']; if (!$validateOnly) { if (WarehouseProductLocation::getProductLocation($product->id, $id_product_attribute, $info['warehouse']) !== false) { $warehouse_location_entity->update(); } else { $warehouse_location_entity->save(); } StockAvailable::synchronize($product->id); } } else { $this->warnings[] = sprintf($this->trans('Warehouse did not exist, cannot set on product %1$s.', array(), 'Admin.Parameters.Notification'), $product->name[$default_language]); } } } // stock available if (isset($info['depends_on_stock'])) { if ($info['depends_on_stock'] != 0 && $info['depends_on_stock'] != 1) { $this->warnings[] = sprintf($this->trans('Incorrect value for "Depends on stock" for product %1$s ', array(), 'Admin.Notifications.Error'), $product->name[$default_language]); } elseif ((!$info['advanced_stock_management'] || $info['advanced_stock_management'] == 0) && $info['depends_on_stock'] == 1) { $this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, cannot set "Depends on stock" for product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language]); } elseif (!$validateOnly) { StockAvailable::setProductDependsOnStock($product->id, $info['depends_on_stock'], null, $id_product_attribute); } // This code allows us to set qty and disable depends on stock if (isset($info['quantity']) && (int) $info['quantity']) { // if depends on stock and quantity, add quantity to stock if ($info['depends_on_stock'] == 1) { $stock_manager = StockManagerFactory::getManager(); $price = str_replace(',', '.', $info['wholesale_price']); if ($price == 0) { $price = 1.0E-6; } $price = round(floatval($price), 6); $warehouse = new Warehouse($info['warehouse']); if (!$validateOnly && $stock_manager->addProduct((int) $product->id, $id_product_attribute, $warehouse, (int) $info['quantity'], 1, $price, true)) { StockAvailable::synchronize((int) $product->id); } } elseif (!$validateOnly) { if ($shop_is_feature_active) { foreach ($id_shop_list as $shop) { StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], (int) $shop); } } else { StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], $this->context->shop->id); } } } } elseif (!$validateOnly) { // if not depends_on_stock set, use normal qty if ($shop_is_feature_active) { foreach ($id_shop_list as $shop) { StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], (int) $shop); } } else { StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], $this->context->shop->id); } } } }
/** * @param Product $product * @param Currency|array|int $currency * @return string */ public function renderListAttributes($product, $currency) { $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->addRowAction('edit'); $this->addRowAction('default'); $this->addRowAction('delete'); $default_class = 'highlighted'; $this->fields_list = array('attributes' => array('title' => $this->l('Attribute - value pair'), 'align' => 'left'), 'price' => array('title' => $this->l('Impact on price'), 'type' => 'price', 'align' => 'left'), 'weight' => array('title' => $this->l('Impact on weight'), 'align' => 'left'), 'reference' => array('title' => $this->l('Reference'), 'align' => 'left'), 'ean13' => array('title' => $this->l('EAN-13'), 'align' => 'left'), 'upc' => array('title' => $this->l('UPC'), 'align' => 'left')); if ($product->id) { /* Build attributes combinations */ $combinations = $product->getAttributeCombinations($this->context->language->id); $groups = array(); $comb_array = array(); if (is_array($combinations)) { $combination_images = $product->getCombinationImages($this->context->language->id); foreach ($combinations as $k => $combination) { $price_to_convert = Tools::convertPrice($combination['price'], $currency); $price = Tools::displayPrice($price_to_convert, $currency); $comb_array[$combination['id_product_attribute']]['id_product_attribute'] = $combination['id_product_attribute']; $comb_array[$combination['id_product_attribute']]['attributes'][] = array($combination['group_name'], $combination['attribute_name'], $combination['id_attribute']); $comb_array[$combination['id_product_attribute']]['wholesale_price'] = $combination['wholesale_price']; $comb_array[$combination['id_product_attribute']]['price'] = $price; $comb_array[$combination['id_product_attribute']]['weight'] = $combination['weight'] . Configuration::get('PS_WEIGHT_UNIT'); $comb_array[$combination['id_product_attribute']]['unit_impact'] = $combination['unit_price_impact']; $comb_array[$combination['id_product_attribute']]['reference'] = $combination['reference']; $comb_array[$combination['id_product_attribute']]['ean13'] = $combination['ean13']; $comb_array[$combination['id_product_attribute']]['upc'] = $combination['upc']; $comb_array[$combination['id_product_attribute']]['id_image'] = isset($combination_images[$combination['id_product_attribute']][0]['id_image']) ? $combination_images[$combination['id_product_attribute']][0]['id_image'] : 0; $comb_array[$combination['id_product_attribute']]['available_date'] = strftime($combination['available_date']); $comb_array[$combination['id_product_attribute']]['default_on'] = $combination['default_on']; if ($combination['is_color_group']) { $groups[$combination['id_attribute_group']] = $combination['group_name']; } } } if (isset($comb_array)) { foreach ($comb_array as $id_product_attribute => $product_attribute) { $list = ''; /* In order to keep the same attributes order */ asort($product_attribute['attributes']); foreach ($product_attribute['attributes'] as $attribute) { $list .= $attribute[0] . ' - ' . $attribute[1] . ', '; } $list = rtrim($list, ', '); $comb_array[$id_product_attribute]['image'] = $product_attribute['id_image'] ? new Image($product_attribute['id_image']) : false; $comb_array[$id_product_attribute]['available_date'] = $product_attribute['available_date'] != 0 ? date('Y-m-d', strtotime($product_attribute['available_date'])) : '0000-00-00'; $comb_array[$id_product_attribute]['attributes'] = $list; $comb_array[$id_product_attribute]['name'] = $list; if ($product_attribute['default_on']) { $comb_array[$id_product_attribute]['class'] = $default_class; } } } } foreach ($this->actions_available as $action) { if (!in_array($action, $this->actions) && isset($this->{$action}) && $this->{$action}) { $this->actions[] = $action; } } $helper = new HelperList(); $helper->identifier = 'id_product_attribute'; $helper->table_id = 'combinations-list'; $helper->token = $this->token; $helper->currentIndex = self::$currentIndex; $helper->no_link = true; $helper->simple_header = true; $helper->show_toolbar = false; $helper->shopLinkType = $this->shopLinkType; $helper->actions = $this->actions; $helper->list_skip_actions = $this->list_skip_actions; $helper->colorOnBackground = true; $helper->override_folder = $this->tpl_folder . 'combination/'; return $helper->generateList($comb_array, $this->fields_list); }
public function generateXML($cron) { $shop_url = 'http://' . Tools::getHttpHost(false, true) . __PS_BASE_URI__; $id_lang = (int) Configuration::get('PS_LANG_DEFAULT'); $currency_default = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $this->currency_iso = $currency_default->iso_code; $country = new Country(Configuration::get('PS_COUNTRY_DEFAULT')); $this->country_name = $country->name; $currencies = Currency::getCurrencies(); $categories = Category::getCategories($id_lang, false, false); $yamarket_set_combinations = Configuration::get('YA_MARKET_SET_COMBINATIONS'); $this->yamarket_availability = Configuration::get('YA_MARKET_DOSTUPNOST'); $this->gzip = Configuration::get('YA_MARKET_SET_GZIP'); /*-----------------------------------------------------------------------------*/ $cats = array(); if ($c = Configuration::get('YA_MARKET_CATEGORIES')) { $uc = unserialize($c); if (is_array($uc)) { $cats = $uc; } } $yml = new Yml(); $yml->yml('utf-8'); $yml->setShop(Configuration::get('PS_SHOP_NAME'), Configuration::get('YA_MARKET_NAME'), $shop_url); if (Configuration::get('YA_MARKET_SET_ALLCURRENCY')) { foreach ($currencies as $currency) { $yml->addCurrency($currency['iso_code'], (double) $currency_default->conversion_rate / (double) $currency['conversion_rate']); } unset($currencies); } else { $yml->addCurrency($currency_default->iso_code, (double) $currency_default->conversion_rate); } foreach ($categories as $category) { if (!in_array($category['id_category'], $cats) || $category['id_category'] == 1) { continue; } if (Configuration::get('YA_MARKET_SET_NACTIVECAT')) { if (!$category['active']) { continue; } } if (Configuration::get('YA_MARKET_CATALL')) { if (in_array($category['id_category'], $cats)) { $yml->addCategory($category['name'], $category['id_category'], $category['id_parent']); } } else { $yml->addCategory($category['name'], $category['id_category'], $category['id_parent']); } } foreach ($yml->categories as $cat) { $category_object = new Category($cat['id']); $products = $category_object->getProducts($id_lang, 1, 10000); if ($products) { foreach ($products as $product) { if ($product['id_category_default'] != $cat['id']) { continue; } $data = array(); if ($yamarket_set_combinations && !Configuration::get('YA_MARKET_SHORT')) { $product_object = new Product($product['id_product'], false, $id_lang); $combinations = $product_object->getAttributeCombinations($id_lang); } else { $combinations = false; } if (is_array($combinations) && count($combinations) > 0) { $comb_array = array(); foreach ($combinations as $combination) { $comb_array[$combination['id_product_attribute']]['id_product_attribute'] = $combination['id_product_attribute']; $comb_array[$combination['id_product_attribute']]['price'] = Product::getPriceStatic($product['id_product'], true, $combination['id_product_attribute']); $comb_array[$combination['id_product_attribute']]['reference'] = $combination['reference']; $comb_array[$combination['id_product_attribute']]['ean13'] = $combination['ean13']; $comb_array[$combination['id_product_attribute']]['quantity'] = $combination['quantity']; $comb_array[$combination['id_product_attribute']]['minimal_quantity'] = $combination['minimal_quantity']; $comb_array[$combination['id_product_attribute']]['weight'] = $combination['weight']; $comb_array[$combination['id_product_attribute']]['attributes'][$combination['group_name']] = $combination['attribute_name']; if (!isset($comb_array[$combination['id_product_attribute']]['comb_url'])) { $comb_array[$combination['id_product_attribute']]['comb_url'] = ''; } $comb_array[$combination['id_product_attribute']]['comb_url'] .= '/' . Tools::str2url($combination['group_name']) . '-' . str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::str2url(str_replace(array(',', '.'), '-', $combination['attribute_name']))); } foreach ($comb_array as $combination) { $data = $this->makeData($product, $combination); $available = $data['available']; unset($data['available']); if (!empty($data) && $data['price'] != 0) { $yml->addOffer($data['id'], $data, $available); } } } else { $data = $this->makeData($product); $available = $data['available']; unset($data['available']); if (!empty($data) && (int) $data['price'] != 0) { $yml->addOffer($data['id'], $data, $available); } } unset($data); } } unset($product); } unset($categories); $xml = $yml->getXml(); if ($cron) { if ($fp = fopen(_PS_UPLOAD_DIR_ . 'yml.' . $this->context->shop->id . '.xml' . ($this->gzip ? '.gz' : ''), 'w')) { fwrite($fp, $xml); fclose($fp); $this->logSave('market_generate: Cron ' . $this->l('Generate price')); } } else { if ($this->gzip) { header('Content-type:application/x-gzip'); header('Content-Disposition: attachment; filename=yml.' . $this->context->shop->id . '.xml.gz'); $this->logSave('market_generate: gzip view ' . $this->l('Generate price')); } else { header('Content-type:application/xml; charset=windows-1251'); } $this->logSave('market_generate: view ' . $this->l('Generate price')); echo $xml; exit; } }
public function attributeImport() { $default_language = Configuration::get('PS_LANG_DEFAULT'); $groups = array(); foreach (AttributeGroup::getAttributesGroups($default_language) as $group) { $groups[$group['name']] = (int) $group['id_attribute_group']; } $attributes = array(); foreach (Attribute::getAttributes($default_language) as $attribute) { $attributes[$attribute['attribute_group'] . '_' . $attribute['name']] = (int) $attribute['id_attribute']; } $this->receiveTab(); $handle = $this->openCsvFile(); AdminImportController::setLocale(); for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) { if (count($line) == 1 && empty($line[0])) { continue; } if (Tools::getValue('convert')) { $line = $this->utf8EncodeArray($line); } $info = AdminImportController::getMaskedRow($line); $info = array_map('trim', $info); AdminImportController::setDefaultValues($info); if (!Shop::isFeatureActive()) { $info['shop'] = 1; } elseif (!isset($info['shop']) || empty($info['shop'])) { $info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID()); } // Get shops for each attributes $info['shop'] = explode($this->multiple_value_separator, $info['shop']); $id_shop_list = array(); foreach ($info['shop'] as $shop) { if (!is_numeric($shop)) { $id_shop_list[] = Shop::getIdByName($shop); } else { $id_shop_list[] = $shop; } } if (isset($info['id_product'])) { $product = new Product((int) $info['id_product'], false, $default_language); } else { continue; } $id_image = null; //delete existing images if "delete_existing_images" is set to 1 if (array_key_exists('delete_existing_images', $info) && $info['delete_existing_images'] && !isset($this->cache_image_deleted[(int) $product->id])) { $product->deleteImages(); $this->cache_image_deleted[(int) $product->id] = true; } if (isset($info['image_url']) && $info['image_url']) { $product_has_images = (bool) Image::getImages($this->context->language->id, $product->id); $url = $info['image_url']; $image = new Image(); $image->id_product = (int) $product->id; $image->position = Image::getHighestPosition($product->id) + 1; $image->cover = !$product_has_images ? true : false; $field_error = $image->validateFields(UNFRIENDLY_ERROR, true); $lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true); if ($field_error === true && $lang_field_error === true && $image->add()) { $image->associateTo($id_shop_list); if (!AdminImportController::copyImg($product->id, $image->id, $url)) { $this->warnings[] = sprintf(Tools::displayError('Error copying image: %s'), $url); $image->delete(); } else { $id_image = array($image->id); } } else { $this->warnings[] = sprintf(Tools::displayError('%s cannot be saved'), isset($image->id_product) ? ' (' . $image->id_product . ')' : ''); $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . mysql_error(); } } elseif (isset($info['image_position']) && $info['image_position']) { $images = $product->getImages($default_language); if ($images) { foreach ($images as $row) { if ($row['position'] == (int) $info['image_position']) { $id_image = array($row['id_image']); break; } } } if (!$id_image) { $this->warnings[] = sprintf(Tools::displayError('No image was found for combination with id_product = %s and image position = %s.'), $product->id, (int) $info['image_position']); } } $id_attribute_group = 0; // groups $groups_attributes = array(); if (isset($info['group'])) { foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) { $tab_group = explode(':', $group); $group = trim($tab_group[0]); if (!isset($tab_group[1])) { $type = 'select'; } else { $type = trim($tab_group[1]); } // sets group $groups_attributes[$key]['group'] = $group; // if position is filled if (isset($tab_group[2])) { $position = trim($tab_group[2]); } else { $position = false; } if (!isset($groups[$group])) { $obj = new AttributeGroup(); $obj->is_color_group = false; $obj->group_type = pSQL($type); $obj->name[$default_language] = $group; $obj->public_name[$default_language] = $group; $obj->position = !$position ? AttributeGroup::getHigherPosition() + 1 : $position; if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { $obj->add(); $obj->associateTo($id_shop_list); $groups[$group] = $obj->id; } else { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : ''); } // fils groups attributes $id_attribute_group = $obj->id; $groups_attributes[$key]['id'] = $id_attribute_group; } else { $id_attribute_group = $groups[$group]; $groups_attributes[$key]['id'] = $id_attribute_group; } } } // inits attribute $id_product_attribute = 0; $id_product_attribute_update = false; $attributes_to_add = array(); // for each attribute if (isset($info['attribute'])) { foreach (explode($this->multiple_value_separator, $info['attribute']) as $key => $attribute) { $tab_attribute = explode(':', $attribute); $attribute = trim($tab_attribute[0]); // if position is filled if (isset($tab_attribute[1])) { $position = trim($tab_attribute[1]); } else { $position = false; } if (isset($groups_attributes[$key])) { $group = $groups_attributes[$key]['group']; if (!isset($attributes[$group . '_' . $attribute]) && count($groups_attributes[$key]) == 2) { $id_attribute_group = $groups_attributes[$key]['id']; $obj = new Attribute(); // sets the proper id (corresponding to the right key) $obj->id_attribute_group = $groups_attributes[$key]['id']; $obj->name[$default_language] = str_replace('\\n', '', str_replace('\\r', '', $attribute)); $obj->position = !$position && isset($groups[$group]) ? Attribute::getHigherPosition($groups[$group]) + 1 : $position; if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { $obj->add(); $obj->associateTo($id_shop_list); $attributes[$group . '_' . $attribute] = $obj->id; } else { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : ''); } } $info['minimal_quantity'] = isset($info['minimal_quantity']) && $info['minimal_quantity'] ? (int) $info['minimal_quantity'] : 1; $info['wholesale_price'] = str_replace(',', '.', $info['wholesale_price']); $info['price'] = str_replace(',', '.', $info['price']); $info['ecotax'] = str_replace(',', '.', $info['ecotax']); $info['weight'] = str_replace(',', '.', $info['weight']); // if a reference is specified for this product, get the associate id_product_attribute to UPDATE if (isset($info['reference']) && !empty($info['reference'])) { $id_product_attribute = Combination::getIdByReference($product->id, strval($info['reference'])); // updates the attribute if ($id_product_attribute) { // gets all the combinations of this product $attribute_combinations = $product->getAttributeCombinations($default_language); foreach ($attribute_combinations as $attribute_combination) { if ($id_product_attribute && in_array($id_product_attribute, $attribute_combination)) { $product->updateAttribute($id_product_attribute, (double) $info['wholesale_price'], (double) $info['price'], (double) $info['weight'], 0, (double) $info['ecotax'], $id_image, strval($info['reference']), strval($info['ean13']), (int) $info['default_on'], 0, strval($info['upc']), (int) $info['minimal_quantity'], 0, null, $id_shop_list); $id_product_attribute_update = true; } } } } // if no attribute reference is specified, creates a new one if (!$id_product_attribute) { $id_product_attribute = $product->addCombinationEntity((double) $info['wholesale_price'], (double) $info['price'], (double) $info['weight'], 0, (double) $info['ecotax'], (int) $info['quantity'], $id_image, strval($info['reference']), 0, strval($info['ean13']), (int) $info['default_on'], 0, strval($info['upc']), (int) $info['minimal_quantity'], $id_shop_list); } // fills our attributes array, in order to add the attributes to the product_attribute afterwards if (isset($attributes[$group . '_' . $attribute])) { $attributes_to_add[] = (int) $attributes[$group . '_' . $attribute]; } // after insertion, we clean attribute position and group attribute position $obj = new Attribute(); $obj->cleanPositions((int) $id_attribute_group, false); AttributeGroup::cleanPositions(); } } } $product->checkDefaultAttributes(); if (!$product->cache_default_attribute) { Product::updateDefaultAttribute($product->id); } if ($id_product_attribute) { // now adds the attributes in the attribute_combination table if ($id_product_attribute_update) { Db::getInstance()->execute(' DELETE FROM ' . _DB_PREFIX_ . 'product_attribute_combination WHERE id_product_attribute = ' . (int) $id_product_attribute); } foreach ($attributes_to_add as $attribute_to_add) { Db::getInstance()->execute(' INSERT IGNORE INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute) VALUES (' . (int) $attribute_to_add . ',' . (int) $id_product_attribute . ')'); } StockAvailable::setQuantity($product->id, $id_product_attribute, (int) $info['quantity']); } } $this->closeCsvFile($handle); }
public function hookdisplayProductAttributesPL($params) { if (!Configuration::get($this->config_name . '_productl_size')) { return; } $product = new Product($params['productid']); $combinations = $product->getAttributeCombinations($this->context->language->id); $avaiable_sizes = array(); $checked_sizes = array(); foreach ($combinations as $combination) { if ($combination['quantity'] > 0 && $combination['id_attribute_group'] == (int) Configuration::get($this->config_name . '_attribute_size')) { if (!in_array($combination['id_attribute'], $checked_sizes)) { $avaiable_sizes[$combination['id_product_attribute']]['attribute_name'] = $combination['attribute_name']; $checked_sizes[] = $combination['id_attribute']; } } } $this->smarty->assign('combinations', $avaiable_sizes); return $this->display(__FILE__, 'combinations.tpl', $this->getCacheId((int) $params['productid'])); }
/** * Updates product combinations on Prestashop. * * @param integer $id_product * @param string $url_photo * @param array $triple_cod_col_siz * @param array $array_combinations * @param integer $language * @return bool * @see $this->createAttributeGroups * @see $this->setArrayElementForLinkRewrite * @see $this->getCodeColor * @see PrestashopImageHandler getIdImageByName() * @see PrestashopImageHandler insertImageInPrestashop() * */ private function updateCombinantionsForPrestashop($id_product, $url_photo, $triple_cod_col_siz, $array_combinations, $language = 1) { $product = new Product((int) $id_product); $id_new_images = array(); $price = '0.000'; //(float)$product->price; $reference = $product->reference; $id_supplier = (int) $product->id_supplier; foreach ($triple_cod_col_siz as $triple) { $array_attributes_and_values = $array_combinations[$triple]; $attributes = $array_attributes_and_values["Attributi"]; $values = $array_attributes_and_values["Valori"]; $image = trim($array_attributes_and_values["Immagine"]); $quantity = (int) $array_attributes_and_values["Qta"]; $variable_tmp_attributes = explode(",", $attributes); $variable_tmp_values = explode(",", $values); $id_attributes_for_combinations = array(); $flag_just_exist_color = 1; $flag_just_exist_size = 1; for ($i = 0; $i < sizeof($variable_tmp_attributes); $i++) { $code = ""; if ($variable_tmp_values[$i] != "") { $id_attribute_group = $this->createAttributeGroups($variable_tmp_attributes[$i], $language); $id_attributes_for_not_repeat = $this->getAttributeColorAndSize($variable_tmp_values[$i], $language); if (strtolower($variable_tmp_attributes[$i]) === "colore" || strtolower($variable_tmp_attributes[$i]) === "colori") { $product_attribute_for_not_reply = $product->getAttributeCombinations($language); if (empty($product_attribute_for_not_reply)) { if ($id_attributes_for_not_repeat === '-1') { $code = $this->getCodeColor(strtolower($variable_tmp_values[$i])); if ($code != "") { $code = "#" . $code; $attribute_for_product = new Attribute(); $attribute_for_product->name = $this->setArrayElementForLinkRewrite($variable_tmp_values[$i], true, $language); $attribute_for_product->color = $code; $attribute_for_product->id_attribute_group = $id_attribute_group; $attribute_for_product->add(); array_push($id_attributes_for_combinations, $attribute_for_product->id); } } else { array_push($id_attributes_for_combinations, (int) $id_attributes_for_not_repeat); } } else { $flag = 1; foreach ($product_attribute_for_not_reply as $more_attributes) { if ($more_attributes['attribute_name'] === $variable_tmp_values[$i]) { array_push($id_attributes_for_combinations, (int) $more_attributes['id_attribute']); $flag = 0; $flag_just_exist_color = 0; break; } } if ($flag) { if ($id_attributes_for_not_repeat === '-1') { $code = $this->getCodeColor(strtolower($variable_tmp_values[$i])); if ($code != "") { $code = "#" . $code; $attribute_for_product = new Attribute(); $attribute_for_product->name = $this->setArrayElementForLinkRewrite($variable_tmp_values[$i], true, $language); $attribute_for_product->color = $code; $attribute_for_product->id_attribute_group = $id_attribute_group; $attribute_for_product->add(); array_push($id_attributes_for_combinations, $attribute_for_product->id); } } else { array_push($id_attributes_for_combinations, (int) $id_attributes_for_not_repeat); } } } } if (strtolower($variable_tmp_attributes[$i]) === "taglia" || strtolower($variable_tmp_attributes[$i]) === "taglie") { $product_attribute_for_not_reply = $product->getAttributeCombinations($language); if (empty($product_attribute_for_not_reply)) { if ($id_attributes_for_not_repeat === '-1') { $attribute_for_product = new Attribute(); $attribute_for_product->name = $this->setArrayElementForLinkRewrite($variable_tmp_values[$i], true, $language); $attribute_for_product->id_attribute_group = $id_attribute_group; $attribute_for_product->add(); array_push($id_attributes_for_combinations, $attribute_for_product->id); } else { array_push($id_attributes_for_combinations, (int) $id_attributes_for_not_repeat); } } else { $flag = 1; foreach ($product_attribute_for_not_reply as $more_attributes) { $vrbls_1 = trim($more_attributes['attribute_name']); $vrbls_2 = trim($variable_tmp_values[$i]); if (gettype($vrbls_1) === "string" && gettype($vrbls_2) === "string") { if ($vrbls_1 === $vrbls_2) { array_push($id_attributes_for_combinations, (int) $more_attributes['id_attribute']); $flag = 0; $flag_just_exist_size = 0; break; } } if (gettype($vrbls_1) === "integer" && gettype($vrbls_2) === "integer") { if ($vrbls_1 == $vrbls_2) { array_push($id_attributes_for_combinations, (int) $more_attributes['id_attribute']); $flag = 0; $flag_just_exist_size = 0; break; } } } if ($flag) { if ($id_attributes_for_not_repeat === '-1') { $attribute_for_product = new Attribute(); $attribute_for_product->name = $this->setArrayElementForLinkRewrite($variable_tmp_values[$i], true, $language); $attribute_for_product->id_attribute_group = $id_attribute_group; $attribute_for_product->add(); array_push($id_attributes_for_combinations, $attribute_for_product->id); } else { array_push($id_attributes_for_combinations, (int) $id_attributes_for_not_repeat); } } } } } else { if (strtolower($variable_tmp_attributes[$i]) === "colore" || strtolower($variable_tmp_attributes[$i]) === "colori") { $flag_just_exist_color = 0; } if (strtolower($variable_tmp_attributes[$i]) === "taglia" || strtolower($variable_tmp_attributes[$i]) === "taglie") { $flag_just_exist_size = 0; } } } if ($flag_just_exist_color || $flag_just_exist_size) { $id_images = array(); $tmp_photo = explode(".jpg,", $image); for ($i = 0; $i < sizeof($tmp_photo); $i++) { if (!empty($tmp_photo[$i])) { $image_for_prestashop = new PrestashopImageHandler(); $id_image = $image_for_prestashop->getIdImageByName(trim($tmp_photo[$i])); if (!empty($id_image)) { array_push($id_images, $id_image); } else { $id_image = $image_for_prestashop->insertImageInPrestashop($id_product, trim($url_photo), trim($tmp_photo[$i])); array_push($id_images, $id_image); array_push($id_new_images, $id_image . ";" . trim($tmp_photo[$i]) . '.jpg'); } } } $id_product_attributes = $product->addProductAttribute($price, 0, 0, 0, $quantity, "", $reference, $id_supplier, 0, 1); $combinations = new CombinationCore((int) $id_product_attributes); $combinations->setAttributes($id_attributes_for_combinations); $combinations->setImages($id_images); } else { $id_images = array(); $tmp_photo = explode(".jpg,", $image); for ($i = 0; $i < sizeof($tmp_photo); $i++) { if (!empty($tmp_photo[$i])) { $image_for_prestashop = new PrestashopImageHandler(); $id_image = $image_for_prestashop->getIdImageByName(trim($tmp_photo[$i])); if (empty($id_image)) { $id_image = $image_for_prestashop->insertImageInPrestashop($id_product, trim($url_photo), trim($tmp_photo[$i])); array_push($id_images, $id_image); array_push($id_new_images, $id_image . ";" . trim($tmp_photo[$i]) . ".jpg"); } } } if (!empty($id_images)) { $array_product_attribute_combinations_get = $product->getCombinationImages($language); for ($i = 0; $i < sizeof($id_images); $i++) { $id_della_immagine = $id_images[$i]; foreach ($array_product_attribute_combinations_get as $single_array_of_attribute_product) { foreach ($single_array_of_attribute_product as $array_di_combinazioni) { $id_arr_comb = $array_di_combinazioni['id_product_attribute']; $combinazioni_attributi = new CombinationCore((int) $id_arr_comb); $attribute_combinations = $combinazioni_attributi->getAttributesName($language); $attr_comb1 = $attribute_combinations[0]; $attr_comb2 = $attribute_combinations[1]; $id_attr_comb1 = $attr_comb1['id_attribute']; $id_attr_comb2 = $attr_comb2['id_attribute']; $id_attributi_input = $id_attributes_for_combinations; $id_color_or_size = $id_attributi_input[0]; $id_size_or_color = $id_attributi_input[1]; if ($id_color_or_size == $id_attr_comb1 || $id_color_or_size == $id_attr_comb2) { if ($id_size_or_color == $id_attr_comb1 || $id_size_or_color == $id_attr_comb2) { $new_image = array(); $new_array_image = $combinazioni_attributi->getWsImages(); for ($j = 0; $j < sizeof($new_array_image); $j++) { $tmp_image_ = $new_array_image[$j]; array_push($new_image, (int) $tmp_image_['id']); } array_push($new_image, $id_della_immagine); $fff = $product->updateProductAttribute($id_arr_comb, 0, $price, 0, 0, 0, $new_image, $reference, $id_supplier, 0, 1, null, null, 1, '0000-00-00'); } } } } } } } } return $id_new_images; }
/** * @param \Product $product * * @return null|string * @throws \Exception * @author Panagiotis Vagenas <*****@*****.**> * @since 150213 */ protected function getProductSizes(\Product &$product) { $mapSizes = $this->Options->getValue('map_size'); if (empty($mapSizes)) { return null; } $sizes = array(); foreach ($product->getAttributeCombinations($this->defaultLang) as $key => $comp) { if ($comp['is_color_group'] || !in_array($comp['id_attribute'], $mapSizes) || $comp['quantity'] < 1 && !$this->backOrdersAllowed($product)) { continue; } $size = $this->sanitizeVariationString($comp['attribute_name']); if ($this->isValidSizeString($size)) { array_push($sizes, $size); } } return implode(', ', array_unique($sizes)); }
public function getAttributeCombinations($id_product, $id_product_attributes) { $product = new Product($id_product, $this->context->language->id); if ($product->id) { /* Build attributes combinations */ $combinations = $product->getAttributeCombinations($this->context->language->id); $groups = array(); $comb_array = array(); if (is_array($combinations)) { foreach ($combinations as $k => $combination) { $price_to_convert = Tools::convertPrice($combination['price'], Context::getContext()->currency->id); $price = Tools::displayPrice($price_to_convert, Context::getContext()->currency->id); $comb_array[$combination['id_product_attribute']]['id_product_attribute'] = $combination['id_product_attribute']; $comb_array[$combination['id_product_attribute']]['attributes'][] = array($combination['group_name'], $combination['attribute_name'], $combination['id_attribute']); $comb_array[$combination['id_product_attribute']]['wholesale_price'] = $combination['wholesale_price']; $comb_array[$combination['id_product_attribute']]['price'] = $price; $comb_array[$combination['id_product_attribute']]['unit_impact'] = $combination['unit_price_impact']; $comb_array[$combination['id_product_attribute']]['reference'] = $combination['reference']; $comb_array[$combination['id_product_attribute']]['ean13'] = $combination['ean13']; $comb_array[$combination['id_product_attribute']]['upc'] = $combination['upc']; } } } }
private function getAlertCategories() { $alert = ''; $sql_getCatNonMultiSku = "SELECT * FROM " . _DB_PREFIX_ . "ebay_category_configuration AS ecc\n\t\t\t\t\t\tINNER JOIN " . _DB_PREFIX_ . "ebay_category AS ec ON ecc.id_ebay_category = ec.id_ebay_category"; $CatNonMultiSku = Db::getInstance()->ExecuteS($sql_getCatNonMultiSku); $catWithProblem = array(); foreach ($CatNonMultiSku as $cat) { if ($cat['is_multi_sku'] != 1 && $this->findIfCategoryParentIsMultiSku($cat['id_category_ref']) != 1) { $categorie = new Category($cat['id_category']); $products = $categorie->getProductsWs($this->id_lang, 0, 300); $catProblem = 0; foreach ($products as $productArray) { $product = new Product($productArray['id']); $combinations = $this->isVersionOneDotFive() ? $product->getAttributeCombinations($this->context->cookie->id_lang) : $product->getAttributeCombinaisons($this->context->cookie->id_lang); if (count($combinations) > 0 && $catProblem == 0) { $catWithProblem[] = $cat['name']; $catProblem = 1; } } } } $var = ''; $j = 0; foreach ($catWithProblem as $cat) { if ($j != 0) { $var .= ', '; } $var .= $cat; $j++; } if (count($catWithProblem) > 0) { if (count($catWithProblem == 1)) { $alert = '<b>' . $this->l('You have chosen eBay category : ') . $var . $this->l(' which does not support multivariation products. Each variation of a product will generate a new product in eBay') . '</b>'; } else { $alert = '<b>' . $this->l('You have chosen eBay categories : ') . $var . $this->l(' which do not support multivariation products. Each variation of a product will generate a new product in eBay') . '</b>'; } } return $alert; }
private function generateFile($lang, $id_curr, $id_shop) { $id_lang = (int) $lang['id_lang']; $curr = new Currency($id_curr); $this->shop = new Shop($id_shop); $root = Category::getRootCategory($id_lang, $this->shop); $this->id_root = $root->id_category; // Get module configuration for this shop $this->module_conf = $this->getConfigFieldsValues($id_shop); // Init categories special attributes : // Google's matching category, gender, age_group, color_group, material, pattern, size... $this->getGCategValues($id_lang, $id_shop); // Init file_path value if ($this->module_conf['gen_file_in_root']) { $generate_file_path = dirname(__FILE__) . '/../../' . $this->_getOutputFileName($lang['iso_code'], $curr->iso_code, $id_shop); } else { $generate_file_path = dirname(__FILE__) . '/export/' . $this->_getOutputFileName($lang['iso_code'], $curr->iso_code, $id_shop); } if ($this->shop->name == 'Prestashop') { $this->shop->name = Configuration::get('PS_SHOP_NAME'); } // Google Shopping XML $xml = '<?xml version="1.0" encoding="' . self::CHARSET . '" ?>' . "\n"; $xml .= '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">' . "\n\n"; $xml .= '<channel>' . "\n"; // Shop name $xml .= '<title><![CDATA[' . $this->shop->name . ']]></title>' . "\n"; // Shop description $xml .= '<description><![CDATA[' . $this->getShopDescription($id_lang, $id_shop) . ']]></description>' . "\n"; $xml .= '<link href="' . htmlspecialchars($this->uri, self::REPLACE_FLAGS, self::CHARSET, false) . '" rel="alternate" type="text/html"/>' . "\n"; $xml .= '<image>' . "\n"; $xml .= '<url>' . htmlspecialchars($this->context->link->getMediaLink(_PS_IMG_ . Configuration::get('PS_LOGO')), self::REPLACE_FLAGS, self::CHARSET, false) . '</url>' . "\n"; $xml .= '<link>' . htmlspecialchars($this->uri, self::REPLACE_FLAGS, self::CHARSET, false) . '</link>' . "\n"; $xml .= '</image>' . "\n"; $xml .= '<modified>' . date('Y-m-d') . ' T01:01:01Z</modified>' . "\n"; $xml .= '<author>' . "\n" . '<name>' . htmlspecialchars(Configuration::get('PS_SHOP_NAME'), self::REPLACE_FLAGS, self::CHARSET, false) . '</name>' . "\n" . '</author>' . "\n\n"; $googleshoppingfile = fopen($generate_file_path, 'w'); // Add UTF-8 byte order mark fwrite($googleshoppingfile, pack("CCC", 0xef, 0xbb, 0xbf)); // File header fwrite($googleshoppingfile, $xml); $sql = 'SELECT DISTINCT p.*, pl.*, ps.id_category_default as category_default, gc.*, glc.tax_included, gl.* ' . 'FROM ' . _DB_PREFIX_ . 'product p ' . 'INNER JOIN ' . _DB_PREFIX_ . 'product_lang pl ON pl.id_product = p.id_product ' . 'INNER JOIN ' . _DB_PREFIX_ . 'product_shop ps ON ps.id_product = p.id_product ' . 'INNER JOIN ' . _DB_PREFIX_ . 'category c ON c.id_category = p.id_category_default ' . 'INNER JOIN ' . _DB_PREFIX_ . 'gshoppingflux gc ON gc.id_gcategory = ps.id_category_default ' . 'INNER JOIN ' . _DB_PREFIX_ . 'gshoppingflux_lc glc ON glc.`id_glang` = ' . $id_lang . ' ' . 'INNER JOIN ' . _DB_PREFIX_ . 'gshoppingflux_lang gl ON gl.id_gcategory = ps.id_category_default ' . 'WHERE `p`.`price` > 0 AND `p`.`active` = 1 AND `c`.`active` = 1 AND `gc`.`export` = 1 ' . 'AND `pl`.`id_lang` = ' . $id_lang . ' AND `gl`.`id_lang` = ' . $id_lang; // Multishops filter if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && count(Shop::getShops(true, null, true)) > 1) { $sql .= ' AND `gc`.`id_shop` = ' . $id_shop . ' AND `pl`.`id_shop` = ' . $id_shop . ' AND `ps`.`id_shop` = ' . $id_shop . ' AND `gl`.`id_shop` = ' . $id_shop; } // Check EAN13 if ($this->module_conf['no_gtin'] != 1) { $sql .= ' AND `p`.`ean13` != "" AND `p`.`ean13` != 0'; } // Check BRAND if ($this->module_conf['no_brand'] != 1) { $sql .= ' AND `p`.`id_manufacturer` != "" AND `p`.`id_manufacturer` != 0'; } $sql .= ' GROUP BY `p`.`id_product`;'; $products = Db::getInstance()->ExecuteS($sql); $this->nb_total_products = 0; $this->nb_not_exported_products = 0; $this->nb_combinations = 0; $this->nb_prd_w_attr = array(); foreach ($products as $product) { $p = new Product($product['id_product'], true, $id_lang, $id_shop, $this->context); $attributeCombinations = null; if ($this->module_conf['export_attributes'] == 1) { $attributeCombinations = $p->getAttributeCombinations($id_lang); } if ($this->module_conf['mpn_type'] == 'reference' && !empty($product['reference'])) { $product['pid'] = $product['reference']; } else { if ($this->module_conf['mpn_type'] == 'supplier_reference' && !empty($product['supplier_reference'])) { $product['pid'] = $product['supplier_reference']; } else { $product['pid'] = $product['id_product']; } } $product['gid'] = $product['pid']; $xml_googleshopping = $this->getItemXML($product, $lang, $id_curr, $id_shop); fwrite($googleshoppingfile, $xml_googleshopping); if (count($attributeCombinations) > 0 && $this->module_conf['export_attributes'] == 1) { $attr = array(); foreach ($attributeCombinations as $a => $attribute) { $attr[$attribute['id_product_attribute']][$attribute['id_attribute_group']] = $attribute; } $combinum = 0; foreach ($attr as $id_attr => $v) { foreach ($v as $k => $a) { foreach ($this->categories_values[$product['id_gcategory']]['gcat_color[]'] as $c) { if ($k == $c) { $product['color'] = $a['attribute_name']; } } foreach ($this->categories_values[$product['id_gcategory']]['gcat_material[]'] as $c) { if ($k == $c) { $product['material'] = $a['attribute_name']; } } foreach ($this->categories_values[$product['id_gcategory']]['gcat_pattern[]'] as $c) { if ($k == $c) { $product['pattern'] = $a['attribute_name']; } } foreach ($this->categories_values[$product['id_gcategory']]['gcat_size[]'] as $c) { if ($k == $c) { $product['size'] = $a['attribute_name']; } } foreach ($a as $k => $v) { $product[$k] = $v; } } if (empty($product['color']) && empty($product['material']) && empty($product['pattern']) && empty($product['size'])) { continue 2; } $combinum++; $product['item_group_id'] = $product['pid']; $product['gid'] = $product['pid'] . '-' . $combinum; $xml_googleshopping = $this->getItemXML($product, $lang, $id_curr, $id_shop, $id_attr); fwrite($googleshoppingfile, $xml_googleshopping); $product['color'] = ''; $product['material'] = ''; $product['pattern'] = ''; $product['size'] = ''; } } } $xml = '</channel>' . "\n" . '</rss>'; fwrite($googleshoppingfile, $xml); fclose($googleshoppingfile); @chmod($generate_file_path, 0777); return array('nb_products' => $this->nb_total_products, 'nb_combinations' => $this->nb_combinations, 'nb_prod_w_attr' => count($this->nb_prd_w_attr), 'non_exported_products' => $this->nb_not_exported_products); }
public function attributeImport() { $default_language = Configuration::get('PS_LANG_DEFAULT'); $groups = array(); foreach (AttributeGroup::getAttributesGroups($default_language) as $group) { $groups[$group['name']] = (int) $group['id_attribute_group']; } $attributes = array(); foreach (Attribute::getAttributes($default_language) as $attribute) { $attributes[$attribute['attribute_group'] . '_' . $attribute['name']] = (int) $attribute['id_attribute']; } $this->receiveTab(); $handle = $this->openCsvFile(); AdminImportController::setLocale(); for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) { if (count($line) == 1 && empty($line[0])) { continue; } if (Tools::getValue('convert')) { $line = $this->utf8EncodeArray($line); } $info = AdminImportController::getMaskedRow($line); $info = array_map('trim', $info); if (self::ignoreRow($info)) { continue; } AdminImportController::setDefaultValues($info); if (!Shop::isFeatureActive()) { $info['shop'] = 1; } elseif (!isset($info['shop']) || empty($info['shop'])) { $info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID()); } $info['shop'] = explode($this->multiple_value_separator, $info['shop']); $id_shop_list = array(); if (is_array($info['shop']) && count($info['shop'])) { foreach ($info['shop'] as $shop) { if (!empty($shop) && !is_numeric($shop)) { $id_shop_list[] = Shop::getIdByName($shop); } elseif (!empty($shop)) { $id_shop_list[] = $shop; } } } if (isset($info['id_product']) && is_string($info['id_product'])) { $prod = self::findProductByName($default_language, $info['id_product']); if ($prod['id_product']) { $info['id_product'] = $prod['id_product']; } else { unset($info['id_product']); } } if (!isset($info['id_product']) && Tools::getValue('match_ref') && isset($info['product_reference']) && $info['product_reference']) { $datas = Db::getInstance()->getRow(' SELECT p.`id_product` FROM `' . _DB_PREFIX_ . 'product` p ' . Shop::addSqlAssociation('product', 'p') . ' WHERE p.`reference` = "' . pSQL($info['product_reference']) . '" '); if (isset($datas['id_product']) && $datas['id_product']) { $info['id_product'] = $datas['id_product']; } } if (isset($info['id_product'])) { $product = new Product((int) $info['id_product'], false, $default_language); } else { continue; } $id_image = array(); if (array_key_exists('delete_existing_images', $info) && $info['delete_existing_images'] && !isset($this->cache_image_deleted[(int) $product->id])) { $product->deleteImages(); $this->cache_image_deleted[(int) $product->id] = true; } if (isset($info['image_url']) && $info['image_url']) { $info['image_url'] = explode(',', $info['image_url']); if (is_array($info['image_url']) && count($info['image_url'])) { foreach ($info['image_url'] as $url) { $url = trim($url); $product_has_images = (bool) Image::getImages($this->context->language->id, $product->id); $image = new Image(); $image->id_product = (int) $product->id; $image->position = Image::getHighestPosition($product->id) + 1; $image->cover = !$product_has_images ? true : false; $field_error = $image->validateFields(UNFRIENDLY_ERROR, true); $lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true); if ($field_error === true && $lang_field_error === true && $image->add()) { $image->associateTo($id_shop_list); if (!AdminImportController::copyImg($product->id, $image->id, $url, 'products', !Tools::getValue('regenerate'))) { $this->warnings[] = sprintf(Tools::displayError('Error copying image: %s'), $url); $image->delete(); } else { $id_image[] = (int) $image->id; } } else { $this->warnings[] = sprintf(Tools::displayError('%s cannot be saved'), isset($image->id_product) ? ' (' . $image->id_product . ')' : ''); $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . mysql_error(); } } } } elseif (isset($info['image_position']) && $info['image_position']) { $info['image_position'] = explode(',', $info['image_position']); if (is_array($info['image_position']) && count($info['image_position'])) { foreach ($info['image_position'] as $position) { $images = $product->getImages($default_language); if ($images) { foreach ($images as $row) { if ($row['position'] == (int) $position) { $id_image[] = (int) $row['id_image']; break; } } } if (empty($id_image)) { $this->warnings[] = sprintf(Tools::displayError('No image was found for combination with id_product = %s and image position = %s.'), $product->id, (int) $position); } } } } $id_attribute_group = 0; $groups_attributes = array(); if (isset($info['group'])) { foreach (explode($this->multiple_value_separator, $info['group']) as $key => $group) { if (empty($group)) { continue; } $tab_group = explode(':', $group); $group = trim($tab_group[0]); if (!isset($tab_group[1])) { $type = 'select'; } else { $type = trim($tab_group[1]); } $groups_attributes[$key]['group'] = $group; if (isset($tab_group[2])) { $position = trim($tab_group[2]); } else { $position = false; } if (!isset($groups[$group])) { $obj = new AttributeGroup(); $obj->is_color_group = false; $obj->group_type = pSQL($type); $obj->name[$default_language] = $group; $obj->public_name[$default_language] = $group; $obj->position = !$position ? AttributeGroup::getHigherPosition() + 1 : $position; if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { $obj->add(); $obj->associateTo($id_shop_list); $groups[$group] = $obj->id; } else { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : ''); } $id_attribute_group = $obj->id; $groups_attributes[$key]['id'] = $id_attribute_group; } else { $id_attribute_group = $groups[$group]; $groups_attributes[$key]['id'] = $id_attribute_group; } } } $id_product_attribute = 0; $id_product_attribute_update = false; $attributes_to_add = array(); if (isset($info['attribute'])) { foreach (explode($this->multiple_value_separator, $info['attribute']) as $key => $attribute) { if (empty($attribute)) { continue; } $tab_attribute = explode(':', $attribute); $attribute = trim($tab_attribute[0]); if (isset($tab_attribute[1])) { $position = trim($tab_attribute[1]); } else { $position = false; } if (isset($groups_attributes[$key])) { $group = $groups_attributes[$key]['group']; if (!isset($attributes[$group . '_' . $attribute]) && count($groups_attributes[$key]) == 2) { $id_attribute_group = $groups_attributes[$key]['id']; $obj = new Attribute(); $obj->id_attribute_group = $groups_attributes[$key]['id']; $obj->name[$default_language] = str_replace('\\n', '', str_replace('\\r', '', $attribute)); $obj->position = !$position && isset($groups[$group]) ? Attribute::getHigherPosition($groups[$group]) + 1 : $position; if (($field_error = $obj->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $obj->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) { $obj->add(); $obj->associateTo($id_shop_list); $attributes[$group . '_' . $attribute] = $obj->id; } else { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : ''); } } $info['minimal_quantity'] = isset($info['minimal_quantity']) && $info['minimal_quantity'] ? (int) $info['minimal_quantity'] : 1; $info['wholesale_price'] = str_replace(',', '.', $info['wholesale_price']); $info['price'] = str_replace(',', '.', $info['price']); $info['ecotax'] = str_replace(',', '.', $info['ecotax']); $info['weight'] = str_replace(',', '.', $info['weight']); $info['available_date'] = Validate::isDate($info['available_date']) ? $info['available_date'] : null; if (!Validate::isEan13($info['ean13'])) { $this->warnings[] = sprintf(Tools::displayError('EAN13 "%1s" has incorrect value for product with id %2d.'), $info['ean13'], $product->id); $info['ean13'] = ''; } if ($info['default_on']) { $product->deleteDefaultAttributes(); } if (isset($info['reference']) && !empty($info['reference'])) { $id_product_attribute = Combination::getIdByReference($product->id, (string) $info['reference']); if ($id_product_attribute) { $attribute_combinations = $product->getAttributeCombinations($default_language); foreach ($attribute_combinations as $attribute_combination) { if ($id_product_attribute && in_array($id_product_attribute, $attribute_combination)) { $product->updateAttribute($id_product_attribute, (double) $info['wholesale_price'], (double) $info['price'], (double) $info['weight'], 0, Configuration::get('PS_USE_ECOTAX') ? (double) $info['ecotax'] : 0, $id_image, (string) $info['reference'], (string) $info['ean13'], (int) $info['default_on'], 0, (string) $info['upc'], (int) $info['minimal_quantity'], $info['available_date'], null, $id_shop_list); $id_product_attribute_update = true; if (isset($info['supplier_reference']) && !empty($info['supplier_reference'])) { $product->addSupplierReference($product->id_supplier, $id_product_attribute, $info['supplier_reference']); } } } } } if (!$id_product_attribute) { $id_product_attribute = $product->addCombinationEntity((double) $info['wholesale_price'], (double) $info['price'], (double) $info['weight'], 0, Configuration::get('PS_USE_ECOTAX') ? (double) $info['ecotax'] : 0, (int) $info['quantity'], $id_image, (string) $info['reference'], 0, (string) $info['ean13'], (int) $info['default_on'], 0, (string) $info['upc'], (int) $info['minimal_quantity'], $id_shop_list, $info['available_date']); if (isset($info['supplier_reference']) && !empty($info['supplier_reference'])) { $product->addSupplierReference($product->id_supplier, $id_product_attribute, $info['supplier_reference']); } } if (isset($attributes[$group . '_' . $attribute])) { $attributes_to_add[] = (int) $attributes[$group . '_' . $attribute]; } $obj = new Attribute(); $obj->cleanPositions((int) $id_attribute_group, false); AttributeGroup::cleanPositions(); } } } $product->checkDefaultAttributes(); if (!$product->cache_default_attribute) { Product::updateDefaultAttribute($product->id); } if ($id_product_attribute) { if ($id_product_attribute_update) { Db::getInstance()->execute(' DELETE FROM ' . _DB_PREFIX_ . 'product_attribute_combination WHERE id_product_attribute = ' . (int) $id_product_attribute); } foreach ($attributes_to_add as $attribute_to_add) { Db::getInstance()->execute(' INSERT IGNORE INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute) VALUES (' . (int) $attribute_to_add . ',' . (int) $id_product_attribute . ')'); } if (isset($info['advanced_stock_management'])) { if ($info['advanced_stock_management'] != 1 && $info['advanced_stock_management'] != 0) { $this->warnings[] = sprintf(Tools::displayError('Advanced stock management has incorrect value. Not set for product with id %d.'), $product->id); } elseif (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $info['advanced_stock_management'] == 1) { $this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, cannot enable on product with id %d.'), $product->id); } else { $product->setAdvancedStockManagement($info['advanced_stock_management']); } if (StockAvailable::dependsOnStock($product->id) == 1 && $info['advanced_stock_management'] == 0) { StockAvailable::setProductDependsOnStock($product->id, 0, null, $id_product_attribute); } } if (isset($info['warehouse']) && $info['warehouse']) { if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, warehouse is not set on product with id %d.'), $product->id); } else { if (Warehouse::exists($info['warehouse'])) { $warehouse_location_entity = new WarehouseProductLocation(); $warehouse_location_entity->id_product = $product->id; $warehouse_location_entity->id_product_attribute = $id_product_attribute; $warehouse_location_entity->id_warehouse = $info['warehouse']; if (WarehouseProductLocation::getProductLocation($product->id, $id_product_attribute, $info['warehouse']) !== false) { $warehouse_location_entity->update(); } else { $warehouse_location_entity->save(); } StockAvailable::synchronize($product->id); } else { $this->warnings[] = sprintf(Tools::displayError('Warehouse did not exist, cannot set on product %1$s.'), $product->name[$default_language]); } } } if (isset($info['depends_on_stock'])) { if ($info['depends_on_stock'] != 0 && $info['depends_on_stock'] != 1) { $this->warnings[] = sprintf(Tools::displayError('Incorrect value for depends on stock for product %1$s '), $product->name[$default_language]); } elseif ((!$info['advanced_stock_management'] || $info['advanced_stock_management'] == 0) && $info['depends_on_stock'] == 1) { $this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, cannot set depends on stock %1$s '), $product->name[$default_language]); } else { StockAvailable::setProductDependsOnStock($product->id, $info['depends_on_stock'], null, $id_product_attribute); } if (isset($info['quantity']) && $info['quantity']) { if ($info['depends_on_stock'] == 1) { $stock_manager = StockManagerFactory::getManager(); $price = str_replace(',', '.', $info['wholesale_price']); if ($price == 0) { $price = 1.0E-6; } $price = round((double) $price, 6); $warehouse = new Warehouse($info['warehouse']); if ($stock_manager->addProduct((int) $product->id, $id_product_attribute, $warehouse, $info['quantity'], 1, $price, true)) { StockAvailable::synchronize((int) $product->id); } } else { if (Shop::isFeatureActive()) { foreach ($id_shop_list as $shop) { StockAvailable::setQuantity((int) $product->id, $id_product_attribute, $info['quantity'], (int) $shop); } } else { StockAvailable::setQuantity((int) $product->id, $id_product_attribute, $info['quantity'], $this->context->shop->id); } } } } else { if (Shop::isFeatureActive()) { foreach ($id_shop_list as $shop) { StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], (int) $shop); } } else { StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], $this->context->shop->id); } } } } $this->closeCsvFile($handle); }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); if (!$this->errors) { if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) { $this->product->quantity = 0; } $this->product->description = $this->transformDescriptionWithImg($this->product->description); // Assign to the template the id of the virtual product. "0" if the product is not downloadable. $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id)); $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); if (Tools::isSubmit('submitCustomizedDatas')) { // If cart has not been saved, we need to do it so that customization fields can have an id_cart // We check that the cookie exists first to avoid ghost carts if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) { $this->context->cart->add(); $this->context->cookie->id_cart = (int) $this->context->cart->id; } $this->pictureUpload(); $this->textRecord(); $this->formTargetFormat(); } elseif (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) { $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture.'); } $pictures = array(); $text_fields = array(); if ($this->product->customizable) { $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true); foreach ($files as $file) { $pictures['pictures_' . $this->product->id . '_' . $file['index']] = $file['value']; } $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true); foreach ($texts as $text_field) { $text_fields['textFields_' . $this->product->id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']); } } $this->context->smarty->assign(array('pictures' => $pictures, 'textFields' => $text_fields)); $this->product->customization_required = false; $customization_fields = $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false; if (is_array($customization_fields)) { foreach ($customization_fields as $customization_field) { if ($this->product->customization_required = $customization_field['required']) { break; } } } // Assign template vars related to the category + execute hooks related to the category $this->assignCategory(); // Assign template vars related to the price and tax $this->assignPriceAndTax(); // Assign template vars related to the images $this->assignImages(); // Assign attribute groups to the template $this->assignAttributesGroups(); // Assign attributes combinations to the template $this->assignAttributesCombinations(); // Pack management $pack_items = $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array(); $this->context->smarty->assign('packItems', $pack_items); $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1)); if (isset($this->category->id) && $this->category->id) { $return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category)); } else { $return_link = 'javascript: history.back();'; } $category_id = $this->category->id; if ($category_id === 13) { $foundations = array(); $foundations_ids = array(28, 29, 30, 31); foreach ($foundations_ids as $id) { $product = new Product($id, true, $this->context->language->id); $cover = $product->getCover($id); $foundations[$id]['img_src'] = $this->context->link->getImageLink($product->link_rewrite, $cover['id_image'], 'large_default'); $foundations[$id]['name'] = $product->name; $foundations[$id]['href'] = $this->context->link->getProductLink($product->id); $combListArr = $product->getAttributeCombinations($this->context->language->id); $foundations[$id]['combs'] = $combListArr; $foundations[$id]['price'] = $product->price; } // echo '<pre>'.print_r($foundations,true).'</pre>'; $this->context->smarty->assign(array('foundations' => $foundations)); // echo '<pre>'.print_r(get_class_methods($product),true).'</pre>'; unset($product); } $this->context->smarty->assign(array('stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => $customization_fields, 'accessories' => $this->product->getAccessories($this->context->language->id), 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->id) : array(), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'HOOK_PRODUCT_CONTENT' => Hook::exec('displayProductContent', array('product' => $this->product)), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'body_classes' => array($this->php_self . '-' . $this->product->id, $this->php_self . '-' . $this->product->link_rewrite, 'category-' . (isset($this->category) ? $this->category->id : ''), 'category-' . (isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : '')), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE'))); } $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl'); }
public function generate($cron = false) { self::setCurrency(); include 'classes/ymlCatalog.php'; //Язык по умолчанию $id_lang = (int) Configuration::get('PS_LANG_DEFAULT'); //Валюта по умолчанию $currency_default = new Currency($this->context->cookie->id_currency); $this->currency_iso = $currency_default->iso_code; //Адрес магазина $shop_url = 'http://' . Tools::getHttpHost(false, true) . __PS_BASE_URI__; //Категории для экспорта $yamarket_с_categories = unserialize(Configuration::get('yamarket_с_categories')); //$yamarket_с_suppliers = unserialize(Configuration::get('yamarket_с_supplier')); $yamarket_с_combinations = Configuration::get('yamarket_с_combinations'); $this->yamarket_с_availability = Configuration::get('yamarket_с_availability'); $this->yamarket_с_shipping = unserialize(Configuration::get('yamarket_с_shipping')); //создаем новый магазин $catalog = new ymlCatalog(); $catalog->gzip = Configuration::get('yamarket_с_gzip'); $shop = new ymlShop(); $shop->name = Configuration::get('yamarket_с_shop'); $shop->company = Configuration::get('yamarket_с_company'); $shop->url = $shop_url; $shop->platform = 'PrestaShop'; $shop->version = _PS_VERSION_; $shop->agency = 'PrestaLab'; $shop->email = '*****@*****.**'; //Валюты $shop->startTag(ymlCurrency::$collectionName); if (Configuration::get('yamarket_с_currencies')) { $currencies = Currency::getCurrencies(); foreach ($currencies as $currency) { $shop->add(new ymlCurrency($currency['iso_code'], (double) $currency['conversion_rate'])); } unset($currencies); } else { $shop->add(new ymlCurrency($currency_default->iso_code, (double) $currency_default->conversion_rate)); } $shop->endTag(ymlCurrency::$collectionName); //Категории $categories = Category::getCategories($id_lang, false, false); $shop->startTag(ymlCategory::$collectionName); foreach ($categories as $category) { if ($category['active'] && in_array($category['id_category'], $yamarket_с_categories)) { $shop->add(new ymlCategory($category['id_category'], $category['name'], $category['id_parent'])); } } $shop->endTag(ymlCategory::$collectionName); //Стоимость доставки $shop->addString('<local_delivery_cost>' . Configuration::get('yamarket_с_shippingcost') . '</local_delivery_cost>'); //Товары $shop->startTag(ymlOffer::$collectionName); foreach ($categories as $category) { if ($category['active'] && in_array($category['id_category'], $yamarket_с_categories)) { $category_object = new Category($category['id_category']); $products = $category_object->getProducts($id_lang, 1, 10000); if ($products) { foreach ($products as $product) { if ($product['id_category_default'] != $category['id_category']) { continue; } // if (count($yamarket_с_suppliers)&&(!in_array($product['id_supplier'], $yamarket_с_suppliers))) // continue; //Для комбинаций if ($yamarket_с_combinations) { $product_object = new Product($product['id_product'], false, $id_lang); $combinations = $product_object->getAttributeCombinations($id_lang); } else { $combinations = false; } if (is_array($combinations) && count($combinations) > 0) { $comb_array = array(); foreach ($combinations as $combination) { $comb_array[$combination['id_product_attribute']]['id_product_attribute'] = $combination['id_product_attribute']; $comb_array[$combination['id_product_attribute']]['price'] = Product::getPriceStatic($product['id_product'], true, $combination['id_product_attribute']); $comb_array[$combination['id_product_attribute']]['reference'] = $combination['reference']; $comb_array[$combination['id_product_attribute']]['ean13'] = $combination['ean13']; $comb_array[$combination['id_product_attribute']]['quantity'] = $combination['quantity']; $comb_array[$combination['id_product_attribute']]['attributes'][$combination['group_name']] = $combination['attribute_name']; $comb_array[$combination['id_product_attribute']]['oldprice'] = $product['orderprice'] + $combination['price']; if (!isset($comb_array[$combination['id_product_attribute']]['comb_url'])) { $comb_array[$combination['id_product_attribute']]['comb_url'] = ''; } $comb_array[$combination['id_product_attribute']]['comb_url'] .= '/' . (self::combinationUrlPrepare($combination['group_name']) . '-' . self::combinationUrlPrepare($combination['attribute_name'])); } foreach ($comb_array as $combination) { self::_addProduct($shop, $product, $combination); } } else { self::_addProduct($shop, $product); } } } unset($product); } } unset($categories); $shop->endTag(ymlOffer::$collectionName); $catalog->add($shop); if ($cron) { if ($fp = fopen(_PS_UPLOAD_DIR_ . 'yml.' . $this->context->shop->id . '.xml' . ($catalog->gzip ? '.gz' : ''), 'w')) { fwrite($fp, $catalog->generate()); fclose($fp); } } else { if ($catalog->gzip) { header('Content-type:application/x-gzip'); header('Content-Disposition: attachment; filename=yml.' . $this->context->shop->id . '.xml.gz'); } else { header('Content-type:application/xml; charset=utf-8'); } echo $catalog->generate(); } }
private function _getAlertCategories() { $alert = ''; $cat_with_problem = array(); $sql_get_cat_non_multi_sku = 'SELECT * FROM ' . _DB_PREFIX_ . 'ebay_category_configuration AS ecc INNER JOIN ' . _DB_PREFIX_ . 'ebay_category AS ec ON ecc.id_ebay_category = ec.id_ebay_category'; foreach (Db::getInstance()->ExecuteS($sql_get_cat_non_multi_sku) as $cat) { if ($cat['is_multi_sku'] != 1 && EbayCategory::getInheritedIsMultiSku($cat['id_category_ref']) != 1) { $catProblem = 0; $category = new Category($cat['id_category']); $products = $category->getProductsWs($this->ebay_country->getIdLang(), 0, 300); foreach ($products as $product_ar) { $product = new Product($product_ar['id']); $combinations = version_compare(_PS_VERSION_, '1.5', '>') ? $product->getAttributeCombinations($this->context->cookie->id_lang) : $product->getAttributeCombinaisons($this->context->cookie->id_lang); if (count($combinations) > 0 && !$catProblem) { $cat_with_problem[] = $cat['name']; $catProblem = 1; } } } } $var = implode(', ', $cat_with_problem); if (count($cat_with_problem) > 0) { if (count($cat_with_problem == 1)) { // RAPH: pb here in the test. Potential typo $alert = '<b>' . $this->l('You have chosen eBay category : ') . $var . $this->l(' which does not support multivariation products. Each variation of a product will generate a new product in eBay') . '</b>'; } else { $alert = '<b>' . $this->l('You have chosen eBay categories : ') . $var . $this->l(' which do not support multivariation products. Each variation of a product will generate a new product in eBay') . '</b>'; } } return $alert; }
/** * function to get all necessary data of products combinations * @param $products An array of products data * @return array products combinations */ public function getProductAttributeCombinations($products) { $combinations = array(); foreach ($products as $product) { // load product object $product = new Product($product['id_product'], $this->context->language->id); // get the product combinations data // create array combinations with key = id_product $combinations[$product->id] = $product->getAttributeCombinations($this->context->language->id); } return $combinations; }
public static function getMultiVarToNonMultiSku($ebay_profile, $context) { $cat_with_problem = array(); $sql_get_cat_non_multi_sku = 'SELECT * FROM ' . _DB_PREFIX_ . 'ebay_category_configuration AS ecc INNER JOIN ' . _DB_PREFIX_ . 'ebay_category AS ec ON ecc.id_ebay_category = ec.id_ebay_category WHERE ecc.id_ebay_profile = ' . (int) $ebay_profile->id . ' GROUP BY name'; foreach (Db::getInstance()->ExecuteS($sql_get_cat_non_multi_sku) as $cat) { if ($cat['is_multi_sku'] != 1 && EbayCategory::getInheritedIsMultiSku($cat['id_category_ref'], $ebay_profile->ebay_site_id) != 1) { $catProblem = 0; $category = new Category($cat['id_category']); $ebay_country = EbayCountrySpec::getInstanceByKey($ebay_profile->getConfiguration('EBAY_COUNTRY_DEFAULT')); $products = $category->getProductsWs($ebay_country->getIdLang(), 0, 300); foreach ($products as $product_ar) { $product = new Product($product_ar['id']); $combinations = version_compare(_PS_VERSION_, '1.5', '>') ? $product->getAttributeCombinations($context->cookie->id_lang) : $product->getAttributeCombinaisons($context->cookie->id_lang); if (count($combinations) > 0 && !$catProblem) { $cat_with_problem[] = $cat['name']; $catProblem = 1; } } } } return $cat_with_problem; }
protected function getData($layers) { if ($this->option == 42) { $products = $this->getProducts($this->context->language->id); foreach ($products as $product) { $this->_values[0][] = $product['reference']; $this->_values[1][] = $product['name']; $this->_values[2][] = $product['quantity']; $this->_legend[] = $product['id_product']; } } else { if ($this->option != 3) { $this->setDateGraph($layers, true); } else { $product = new Product($this->id_product, false, (int) $this->getLang()); $comb_array = array(); $assoc_names = array(); $combinations = $product->getAttributeCombinations((int) $this->getLang()); foreach ($combinations as $combination) { $comb_array[$combination['id_product_attribute']][] = array('group' => $combination['group_name'], 'attr' => $combination['attribute_name']); } foreach ($comb_array as $id_product_attribute => $product_attribute) { $list = ''; foreach ($product_attribute as $attribute) { $list .= trim($attribute['group']) . ' - ' . trim($attribute['attr']) . ', '; } $list = rtrim($list, ', '); $assoc_names[$id_product_attribute] = $list; } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query); foreach ($result as $row) { $this->_values[] = $row['total']; $this->_legend[] = @$assoc_names[$row['product_attribute_id']]; } } } }
private function hasOptions() { $this->combinations = $this->product->getAttributeCombinations($this->context->language->id); return (bool) $this->combinations; }