Jump to content

Adding value to custom feature of products.


bantumi
 Share

Recommended Posts

Hi,guys!

I am using class Product to import products in my website, but i need some help with this, as long as I am pretty new to Prestashop. The problem is that i can't find how to set value to custom feature of the products. For example: I have custom feature called "phone" how can I set value to this feature using class Product?

Here is a part of my code:

$product->name = array((int)Configuration::get('PS_LANG_DEFAULT') =>  "$title");;
$product->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') =>  "$title_rewrite");
$product->redirect_type = '404';
$product->price = $price;
$product->quantity = 1;
$product->minimal_quantity = 1;
$product->show_price = 1;
$product->on_sale = 0;
$product->online_only = 1;
$product->meta_keywords =$keywords;
$product->is_virtual=1;
$product->id_category_default = 2;
$product->add();
$product->addToCategories(array(0=>2,1=>$cat_info[$cat_rewrite]));


Thanks in advance!

Share this post


Link to post
Share on other sites

I solved this writing my own method in the product class. Here it is : 
 

public function setFeatureProduct($id_feature,$id_product,$id_feature_value,$value) {
$row = array('id_feature' => (int)($id_feature), 'id_product' => (int)$id_product,'id_feature_value'=>(int)$id_feature_value);
Db::getInstance()->autoExecute(_DB_PREFIX_.'feature_product', $row, 'INSERT');
$row = array('id_feature_value' => (int)$id_feature_value,'id_feature'=>(int)$id_feature, 'custom' => 1);
Db::getInstance()->autoExecute(_DB_PREFIX_.'feature_value', $row, 'INSERT');
$row = array('id_feature_value' => (int)$id_feature_value, 'id_lang' => 6,'value'=>$value);
Db::getInstance()->autoExecute(_DB_PREFIX_.'feature_value_lang', $row, 'INSERT');
}

Share this post


Link to post
Share on other sites

  • 1 month later...

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More