/** * Triggers CLDR download * * @param Event $event * @throws \Exception * @throws \PrestaShopDatabaseException */ public static function init(Event $event) { $event->getIO()->write("Init CLDR data download..."); $root_dir = realpath(''); $cldr_update = new Update($root_dir . '/translations/'); $cldr_update->init(); // If settings file exist if (file_exists($root_dir . '/config/settings.inc.php')) { //load prestashop config to get locale env require $root_dir . '/config/config.inc.php'; //get each defined languages and fetch cldr datas $langs = \DbCore::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'lang'); foreach ($langs as $lang) { $language_code = explode('-', $lang['language_code']); if (empty($language_code[1])) { $language_code[1] = $language_code[0]; } $cldr_update->fetchLocale($language_code['0'] . '-' . strtoupper($language_code[1])); } } $event->getIO()->write("Finished..."); }
/** * Get combination images ids * * @param int $idAttribute * * @return array */ public function getImages($idAttribute) { return \DbCore::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT a.`id_image` as id FROM `' . _DB_PREFIX_ . 'product_attribute_image` a ' . \ShopCore::addSqlAssociation('product_attribute', 'a') . ' WHERE a.`id_product_attribute` = ' . (int) $idAttribute . ' '); }
/** * Install Cldr Datas */ public function installCldrDatas() { $cldrUpdate = new Update(_PS_TRANSLATIONS_DIR_); $cldrUpdate->init(); //get each defined languages and fetch cldr datas $langs = \DbCore::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'lang'); foreach ($langs as $lang) { $language_code = explode('-', $lang['language_code']); if (count($language_code) == 1) { $cldrUpdate->fetchLocale($language_code['0']); } else { $cldrUpdate->fetchLocale($language_code['0'] . '-' . Tools::strtoupper($language_code[1])); } } }
function importCategories($file, $blindMode) { $date = date('Y-m-d H:i:s'); $xml = new XMLReader(); $xml->open($file); $depth = array(); $parentId = null; $parents = array(); $depth = 0; $db = DbCore::getInstance(); $table = 'category'; $query = new DbQuery(); $query->select('id_category'); $query->from($table, 'p'); $query->where("p.is_root_category = 1"); $rootCategory = (int) $db->getValue($query); while ($xml->read()) { if ($xml->nodeType == XmlReader::ELEMENT && $xml->name == 'ctg:name') { $xml->read(); $name = $xml->value; } if ($xml->nodeType == XmlReader::ELEMENT && $xml->name == 'ctg:description') { $xml->read(); $description = $xml->value; } if ($xml->nodeType == XmlReader::ELEMENT && $xml->name == 'ctg:sequence') { $xml->read(); $sequence = $xml->value; } if ($xml->nodeType == XmlReader::ELEMENT && $xml->name == 'ctg:displayed') { $xml->read(); $displayed = $xml->value == 'true'; } if ($xml->nodeType == XmlReader::ELEMENT && $xml->name == 'ctg:id') { $xml->read(); $id = (int) $xml->value; } if ($xml->nodeType == XmlReader::ELEMENT && $xml->name == 'ctg:internetParams') { // hack - we insert category here $parent = $rootCategory; // root category if (isset($parents[$depth])) { $parent = $parents[$depth]; } if ($blindMode) { try { // hack - we can not save category unless it already exists $db->insert('category', array('id_category' => $id, 'id_parent' => $parent, 'date_add' => $date)); } catch (Exception $e) { } } else { try { $category = new Category(); $category->id = $id; $category->id_category = $id; $category->name = $name; $category->link_rewrite = createUrlSlug($name); $category->description = $description; $category->position = $sequence; $category->id_parent = $parent; $category->active = (int) $displayed; $category->doNotRegenerateNTree = true; $category->save(); $db->update('category_shop', array('position' => $sequence), "id_category = '" . $db->escape($id) . "'"); } catch (Exception $e) { echo $e->getMessage() . " {$id} {$parent}\n"; } } // debug //echo str_repeat('+', $depth) . ' ' . $id . " ($parent)\n"; } if ($xml->nodeType == XmlReader::ELEMENT && $xml->name == 'ctg:subCategories') { $depth++; if (!isset($parents[$depth])) { $parents[$depth] = $id; } } if ($xml->nodeType == XmlReader::END_ELEMENT && $xml->name == 'ctg:subCategories') { unset($parents[$depth]); $depth--; } } $xml->close(); if ($blindMode) { $db->update('category', array('date_add' => $date), "date_add = '0000-00-00 00:00:00'"); } }
if (!empty($content)) { $file = "stock" . date("_Y-m-d_H-i-s") . ".xml"; file_put_contents($file, $content); } $dom = new DomDocument(); $dom->load($file); $xpath = new DOMXPath($dom); // version 1.0 //$roots = $xpath->query('//rsp:responsePackItem[@state=\'ok\']/lst:listStock[@state=\'ok\']'); // version 2.0 $roots = $xpath->query('//rsp:responsePackItem/lStk:listStock'); //var_dump($roots->length); //var_dump($roots); $shopId = 1; // administration $db = DbCore::getInstance(); $query = new DbQuery(); $query->select("id_lang"); $query->from("lang"); $query->where("iso_code = 'cs'"); $langId = $db->getValue($query); $date = date('Y-m-d H:i:s'); if ($roots->length > 0) { for ($i = 0; $i < $roots->length; $i++) { $products = $xpath->query('./lStk:stock', $roots->item($i)); for ($j = 0; $j < $products->length; $j++) { $node = $products->item($j); $id = $xpath->query('./stk:stockHeader/stk:id', $node)->item(0)->nodeValue; $name = $xpath->query('./stk:stockHeader/stk:name', $node)->item(0)->nodeValue; $shortName = @$xpath->query('./stk:stockHeader/stk:shortName', $node)->item(0)->nodeValue; $nameComplement = @$xpath->query('./stk:stockHeader/stk:nameComplement', $node)->item(0)->nodeValue;