Open JM63 opened 5 years ago
Hello @JM63, what do you mean with attribute? A product option? A product feature? If you're not sure just post an image of what you want in your control panel please.
Thanks for the quick reply, i've uploaded an image to check ..
Perfect, those are product_options, so you need to do:
var optionFactory = new ProductOptionFactory("api_url", "api_token", null);
var optionValueFactory = new ProductOptionValueFactory("api_url", "api_token", null);
var productOption = new product_option { id = 1, group_type = "select" };
productOption.name.Add(new language(1, "option name"));
productOption.public_name.Add(new language(1, "Options"));
var optionValues = new List<product_option_value>();
var optionValue = new product_option_value();
optionValue.name.Add(new language(1, feature.Title));
optionValue.id_attribute_group = productOption.id;
optionValue = optionValueFactory.AddList(optionValue);
productOption.associations.product_option_values.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value { id = productOptionValue.id.Value });
return optionFactory.Add(productOption);
Note that:
product_option
with at least one product_option_value
, so you need to specify the same product_option.id
and product_option_value.id_attribute_group
when creating, that will be fixed in PrestaShop 1.7.6.0 (https://github.com/PrestaShop/PrestaShop/pull/12201)Let me know if that works for you :)
Thanks in advance, it was a big help, I'm going to test it now.
Hello @JM63 you need more help about that?
With this code I can enter the options of the product and its values, but the product remains as a simple product and not as a combined product and without the inserted options. What am I doing wrong?
var poFactory = new ProductOptionFactory(_prestashopConfig.baseurl, _prestashopConfig.account, _prestashopConfig.password);
var povFactory = new ProductOptionValueFactory(_prestashopConfig.baseurl, _prestashopConfig.account, _prestashopConfig.password);
var productOption = new product_option
{
id = 1,
group_type = "select",
is_color_group = 0
};
productOption.name.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.language(1, "Size"));
productOption.public_name.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.language(1, "Size"));
productOption = poFactory.Add(productOption);
var optionValues = new List<product_option_value>();
var pov = new product_option_value();
pov.id_attribute_group = productOption.id;
pov.name.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.language(1, "Nano"));
// To get pov.id
pov = povFactory.Add(pov);
var pov1 = new product_option_value();
pov1.id_attribute_group = productOption.id;
pov1.name.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.language(1, "TeraLarge"));
// To get pov1.id
pov1 = povFactory.Add(pov1);
optionValues.Add(pov);
optionValues.Add(pov1);
productOption.associations.product_option_values.Add(
new Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value
{
id = pov.id.Value
});
productOption.associations.product_option_values.Add(
new Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value
{
id = pov1.id.Value,
});
var prod = new Bukimedia.PrestaSharp.Entities.product();
prod.associations.product_option_values
You need to create the combinations separately, for any of your values, for example:
var combinationFactory = new CombinationFactory(_prestashopConfig.baseurl, _prestashopConfig.account, _prestashopConfig.password);
var combination = new combination { id_product = prod.id, minimal_quantity = 0 };
combination.associations.product_option_values.Add(pov);
combinationFactory.Add(combination);
The combination
entity has multiple values, as weight
, reference
, etc... You should take a look to https://github.com/Bukimedia/PrestaSharp/blob/master/PrestaSharp/Entities/combination.cs to see what you need to fill, what I wrote is a minimal example.
Try this and let me know :)
Hello @JM63 did that work for you?
@mowcixo - as i am interested in the same topic, i am just adding my questions here.
i would need to create combinations for specific products and also update the quantity of these combinations regularely, but, for a multilanguage shop. so, basically my questions are then the following ones:
i know, the questions are a bit overlapping, but, maybe you could let me know more detailed samples which are including also the multilanguage part, that would help a lot!
thanks in advance!
How to add product attribute with prestasharp, i have searched but can not find how to do it. One tip please ...