Hello. I need help in my script. I need to create a new shop from script, then create custom url for this shop.
My code now is:
//Create new root category for new shop
$object = new Category();
$link1 = Tools::link_rewrite($customer->lastname);
$object->name = 'NEW_CAT';
$object->id_parent = Configuration::get('PS_HOME_CATEGORY')-1;
$object->link_rewrite = 'NEW_LINK';
$object->is_root_category = 1;
$object->add();
//Get last category id
unset ($last_category_id);
$last_category_id = $object->id;
//Create shop
$object = new Shop();
$object->name = 'NEW_SHOP_NAME';
$object->id_shop_group = 2;
$object->id_theme = 1;
$object->id_category = $last_category_id;
$object->uri = _PS_BASE_URL_.__PS_BASE_URI__.'NEW_LINK'; //url for new shop
$object->active = 1;
$object->add();
//Get last shop id
unset($last_shop_id);
$last_shop_id = $object->id;
//URL to SHOP
$object = new ShopUrl();
//Get domain name
$urlParts = parse_url(_PS_BASE_URL_);
$object->id_shop = $last_shop_id;
$object->id_category = $last_category_id;
$object->domain = $urlParts['host'];
$object->domain_ssl = $urlParts['host'];
$object->virtual_uri = $customer->lastname;
$object->active = 1;
$object->main = 1;
$object->add();
It works, but theme doesn't link with new shop. So it you go to new url (www.mydomane.com/newshop), you sea the page without theme style. But if you resave the shop url in multistore menu, then theme will links to the shop and it opens correct.
Help me please with that problem. Thanks.