Jump to content

How To Add Product With Varations Through Php Script ?


Nextlevel131

Recommended Posts

Hello I have 100k product to import, but I have to import them through PHP and I have to update them each day.

 

I am using prestashop class products.php to add a product and my code is like this:

<?php
echo dirname(__FILE__);
include_once 'config/config.inc.php';
include(dirname(__FILE__).'/init.php');
$defaultLanguage = new Language((int)(Configuration::get('PS_LANG_DEFAULT')));  
/* Add a new product */
$object = new Product();
$object->price = 22;
$object->id_tax_rules_group = 1;
$object->name[Configuration::get('PS_LANG_DEFAULT')] = 'ssssssssss';
$object->reference= 'hbvvh';
$object->quantity = 5;
$object->id_manufacturer = 0;
$object->id_supplier = 0;
$object->minimal_quantity = 1;
$object->additional_shipping_cost = 0;
$object->wholesale_price = '100';
$object->ecotax = 0;
$object->width = 0;
$object->height = 0;
$object->depth = 0;
$object->weight = 0;
$object->out_of_stock = 0;
$object->active = 1;
$object->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') =>  'test-importu');
$object->id_category_default = 18;
$object->category = 18;
$object->available_for_order = 0;
$object->show_price = 1;
$object->on_sale = 0;
$object->online_only = 1;
$object->meta_keywords = 'test';


$object->add();
echo "product added";

exit;
?>

But I dont know how to add sizes variation. Each product has a size which can be, S, M, L, 40, 41, 42 and etc can you help me ?

 

Thanks.

Link to comment
Share on other sites

  • 3 months later...

Hey, any update here? I'm have acomplished adding the products, but want to know how to update them (Stock, Prices etc). 

 

I'm looking for something like, "update" instead of new. Does this exist? Can't seem to find information on the Documentation. 

.......

$object = update Product();
$object->price = 22;
$object->id_tax_rules_group = 1;
$object->name[Configuration::get('PS_LANG_DEFAULT')] = 'ssssssssss';
$object->reference= 'hbvvh';
$object->quantity = 5;
$object->id_manufacturer = 0;

 

Thanks, 

 

Ricardo Malla

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...