narkha Posted July 9, 2012 Share Posted July 9, 2012 I am trying to create shops automatically: the users fill a form and they obtain a shop with an with an administrator user. First i tried to create with the shop web service. I had a few problems: the shop was created without any modules, then the site does not render; the shop was created without web services asociated, then i can not create a employee with the web services. Knowing that, i modified Shop::add for do the extra things: import data from a template shop; create a url for the shop; and create an admin employee. Maybe is not the best place or the best way, but i am starting with prestashop and it looks the easiest place. My problem now is that is the smarty does not update well: i only can enter in the home, and all the links are wrong. if i clean the smarty cache, it works fine for the shop recently created, but if i create a new shop i have the same problem ¿Any Idea? I have not publish this in the bug tracker, because maybe i commite a mistake. This is the code public function add($autodate = true, $null_values = false) { $idTemplate = 0; // if is a web service and i want to create using other shop for impor data if (Tools::getValue('xml') && Tools::getValue('template')) { // obtener la tienda de la que se importaran datos $sql = 'SELECT * FROM '._DB_PREFIX_.'shop s WHERE (s.name = \'' . Tools::getValue('template') . '\') ORDER BY id_shop LIMIT 1'; if ($results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql)) foreach ($results as $row) { $idTemplate = $row['id_shop']; $this->id_shop_group = $row['id_shop_group']; $this->id_category = $row['id_category']; $this->id_theme = $row['id_theme']; } } $res = parent::add($autodate, $null_values); // if the shop have been created and i am importing data if ( $res && $idTemplate != 0) { // import all the data $tables_import = array( // Transportistas 'carrier' => true, 'country' => true, 'currency' => true, 'lang' => true, 'module' => true, 'hook_module' => true, 'meta_lang' => true, 'scene' => true, 'webservice_account' => true, 'attribute_group' => true, 'feature' => true, ); $this->copyShopData($idTemplate, $tables_import); // automatically associate a url for the shop $shopUrl = new ShopUrl(); $shopUrl->id_shop = $this->id; $shopUrl->domain = 'localhost'; $shopUrl->domain_ssl = 'localhost'; $shopUrl->physical_uri = '/prestashop/'; $shopUrl->virtual_uri = 'shop/' . $this->name; $shopUrl->main = 1; $shopUrl->active = $this->active; $shopUrl->setMain(); // si ha habido algun error se devuelve $resUrl = $shopUrl->add(); if (!$resUrl) { return $resUrl; } // copy from AdminShopUrlController::processEdit Tools::generateHtaccess(); } Shop::cacheShops(true); return $res; } Link to comment Share on other sites More sharing options...
Recommended Posts