Skip to content

Instantly share code, notes, and snippets.

@anegoda1995
Created March 31, 2017 14:24
Show Gist options
  • Save anegoda1995/f5fca6ceb7ba09b9562f151b8dd820d7 to your computer and use it in GitHub Desktop.
Save anegoda1995/f5fca6ceb7ba09b9562f151b8dd820d7 to your computer and use it in GitHub Desktop.
[[[PrestaShop]]] add new product by script in PrestaShop CMS
<?php
require('./config/config.inc.php');
//$tmp = new ProductCore();
$product = new ProductCore();
$product->ean13 = 9999999999999;
$product->name = array((int)Configuration::get('PS_LANG_DEFAULT') => 'Test importu');;
$product->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') => 'test-importu');
$product->id_category = 2;
$product->id_category_default = 2;
$product->redirect_type = '404';
$product->price = 22;
$product->quantity = 1;
$product->minimal_quantity = 1;
$product->show_price = 1;
$product->on_sale = 0;
$product->online_only = 1;
$product->meta_keywords = 'test';
$product->is_virtual=1;
$product->add();
echo $product->id;
$product->addToCategories(array(2));
$id_product = $product->id;
$shops = Shop::getShops(true, null, true);
$image = new Image();
$image->id_product = $id_product;
$image->position = Image::getHighestPosition($id_product) + 1;
$image->cover = true; // or false;
if (($image->validateFields(false, true)) === true &&
($image->validateFieldsLang(false, true)) === true && $image->add())
{
$image->associateTo($shops);
if (!AdminImportController::copyImg($id_product, $image->id, $url, 'products', false))
{
$image->delete();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment