Jump to content

Create Specific Price With Object Model


prestashopmediarete

Recommended Posts

Hello,

 

i'm writing a routine to create / update product using Prestashop Object Model.

 

The creation and the update of products works fine (I want to share my code)

$product = new Product();
$product->id_manufacturer = 0;
$product->id_supplier = 0;
$product->id_category_default = $id_category;
$product->id_shop_default = 1;
$product->name = array((int)Configuration::get('PS_LANG_DEFAULT') => substr($arrPrd[1],0,128));
$product->description = '';
$product->description_short = '';
$product->quantity = 100;
$product->minimal_quantity = 1; 
$product->price = (float)str_replace(',','.',$arrPrd[3]);
$product->additional_shipping_cost = 0;
$product->wholesale_price = 0; 
$product->on_sale = false;
$product->online_only = false;
$product->unity = null;
$product->unit_price = 0;
$product->unit_price_ratio = 0;
$product->ecotax = 0;
$product->reference = $arrPrd[0];
$product->supplier_reference = '';
$product->location = '';
$product->width = 0;
$product->height = 0;
$product->depth = 0;
$product->weight = 0;
$product->ean13 = 0;
$product->upc = '';
$product->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') => Tools::link_rewrite(substr($arrPrd[1],0,128)));
$product->meta_description = '';
$product->meta_keywords = '';
$product->meta_title = '';
$product->quantity_discount = 0;
$product->customizable = 0;
$product->new = 1;
$product->uploadable_files = 0;
$product->text_fields = 0;
$product->active = true;
$product->redirect_type = '404';
$product->id_product_redirected = 0;
$product->available_for_order = true;
$product->available_date = '0000-00-00';
$product->condition = 'new';
$product->show_price = true;
$product->indexed = 1;
$product->visibility = 'both';
$product->date_add = date('Y/m/d H:i:s', time());
$product->date_upd = date('Y/m/d H:i:s', time());;
$product->tags = array();
$product->id_tax_rules_group = 1;
$product->add();
$product->addToCategories(array($id_category));

StockAvailable::setQuantity($product->id, 0, (int) $product->quantity);

Now I have to create a specific price rule.

specific_price_box.png

 

How can I proceed? There is a SpecificPrice.php class with an add function but I don't know hot to use it.

 

If someone can help me with this code would be appreciated

 

Thank you

 

 

 

 

 

 

 

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...