Created
December 8, 2022 09:46
-
-
Save nympheastudio/7f84507a9c0b02c83bb4dd323c37299c to your computer and use it in GitHub Desktop.
insert new category from each manufacturers (for Prestashop 1.6)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ERROR | E_WARNING | E_PARSE); //good (and pretty enough) for most hostings | |
ini_set('display_errors',1); | |
if (!ini_get('safe_mode')) { | |
@set_time_limit(0); //no time limiting for script, doesn't work in safe mode | |
} else { | |
@ini_set('max_execution_time', '0'); // no time limiting for script, works in SAFE mode | |
} | |
include(dirname(__FILE__).'/../../config/config.inc.php'); | |
include(dirname(__FILE__).'/../../init.php'); | |
// for Prestashop 1.6 | |
// foreach manufacturers insert new category with id_parent = ? | |
$manufacturers = Manufacturer::getManufacturers( | |
$id_lang = (int)Context::getContext()->language->id, | |
$id_shop = (int)Context::getContext()->shop->id, | |
$get_nb_products = false, | |
$active = false, | |
$group_by = false, | |
$like = false, | |
$p = false, | |
$n = false, | |
$all_group = false | |
); | |
foreach ($manufacturers as $manufacturer) { | |
$cat = createCategory( $manufacturer['name'], $parent_id = 25, $active = 1, $id_shop = 1, $id_lang = 1, $link_rewrite = 'lr', $meta_description = 'md', $meta_keywords = 'mk', $meta_title = 'mt' ); | |
echo $manufacturer['name']."<br>"; | |
} | |
function createCategory( $name, $parent_id = 2, $active = 1, $id_shop = 1, $id_lang = 1, $link_rewrite = 'lr', $meta_description = 'md', $meta_keywords = 'mk', $meta_title = 'mt' ) { | |
$cat = new Category(); | |
$cat->id_parent = $parent_id; | |
$cat->is_root_category = false; | |
$cat->link_rewrite = [ $id_lang => $link_rewrite ]; | |
$cat->meta_description = [ $id_lang => $meta_description ]; | |
$cat->meta_keywords = [ $id_lang => $meta_keywords ]; | |
$cat->meta_title = [ $id_lang => $meta_title ]; | |
$cat->name = [ $id_lang => $name ]; | |
$cat->active = $active; | |
$cat->id_shop_default = $id_shop; | |
$cat->add(); | |
return $cat; | |
} | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment