Closed RCallejo2 closed 9 years ago
Hello @RCallejo2 You can guide with this method. Regards.
private void AddPrestaSharpCombination(Bukisync.Common.Entities.Core.combination combination, Bukimedia.PrestaSharp.Entities.product PrestaSharpProduct, Bukisync.Common.Entities.Core.product product, int StockAvailableIndex, Bukimedia.PrestaSharp.Entities.combination PrestaSharpCombination)
{
bool flag = true;
while (flag)
{
try
{
this.CatalogMemory.Logger.LogInfoStampNewLine("Añadiendo combinación y stock de combinación. Referencia: " + combination.reference + " .......................... iniciado");
lock (this.CombinationFactory)
{
PrestaSharpCombination = this.CombinationFactory.Add(PrestaSharpCombination);
}
flag = false;
//Actualización de la cantidad de stockaje del objeto combination que acabamos de crear
bool flag2 = true;
while (flag2)
{
try
{
PrestaSharpProduct = RefreshPrestaSharpProduct(PrestaSharpProduct);
Bukimedia.PrestaSharp.Entities.stock_available StockAvailable = this.StockAvailableFactory.Get((long)PrestaSharpProduct.associations.stock_availables[StockAvailableIndex + 1].id);
StockAvailable.quantity = combination.quantity;
StockAvailable.out_of_stock = combination.out_of_stock ? 1 : 0;
StockAvailable.depends_on_stock = combination.depends_of_stock ? 1 : 0;
lock (this.StockAvailableFactory)
{
this.StockAvailableFactory.Update(StockAvailable);
}
this.CatalogMemory.Logger.LogInfoStampNewLine("Añadiendo combinación y stock de combinación. Referencia: " + combination.reference + " .......................... completado");
flag2 = false;
this.AddPrestaSharpCombinationImages(PrestaSharpProduct, combination, PrestaSharpCombination);
}
catch (System.ArgumentOutOfRangeException ex)
{
string AuxMessage = "";
AuxMessage += "PrestaSharpProduct.reference: " + PrestaSharpProduct.reference;
AuxMessage += "combination.reference: " + combination.reference;
AuxMessage += "i: " + StockAvailableIndex;
AuxMessage += "PrestaSharpProduct.associations.stock_availables.Count(): " + PrestaSharpProduct.associations.stock_availables.Count();
this.CatalogMemory.Logger.LogErrorStampNewLine("Se produjo un error con la conexión a PrestaShop. Se reintentará la conexión en 5 minutos. " + AuxMessage + Environment.NewLine + ex.ToString());
this.CatalogMemory.Logger.LogDebugStampNewLine(ex.ToString());
Thread.Sleep(300000);
}
catch (Exception ex)
{
this.CatalogMemory.Logger.LogErrorStampNewLine("Se produjo un error con la conexión a PrestaShop. Se reintentará la conexión en 5 minutos. " + Environment.NewLine + ex.ToString());
this.CatalogMemory.Logger.LogDebugStampNewLine(ex.ToString());
Thread.Sleep(300000);
}
}
}
catch (ApplicationException ex)
{
flag = false;
ex.ToString();
//Actualización de la cantidad de stockaje del objeto combination que acabamos de crear
bool flag2 = true;
while (flag2)
{
try
{
PrestaSharpProduct = this.GetPrestaSharpProduct((long)PrestaSharpProduct.id);
Bukimedia.PrestaSharp.Entities.stock_available StockAvailable = this.StockAvailableFactory.Get((long)PrestaSharpProduct.associations.stock_availables[StockAvailableIndex + 1].id);
StockAvailable.quantity = product.quantity;
StockAvailable.out_of_stock = combination.out_of_stock ? 1 : 0;
StockAvailable.depends_on_stock = combination.depends_of_stock ? 1 : 0;
lock (this.StockAvailableFactory)
{
this.StockAvailableFactory.Update(StockAvailable);
}
this.CatalogMemory.Logger.LogInfoStampNewLine("Añadiendo combinación y stock de combinación. Referencia: " + combination.reference + " .......................... completado");
flag2 = false;
}
catch (Exception ex2)
{
this.CatalogMemory.Logger.LogErrorStampNewLine("Se produjo un error con la conexión a PrestaShop. Se reintentará la conexión en 5 minutos. " + Environment.NewLine + ex2.ToString());
this.CatalogMemory.Logger.LogDebugStampNewLine(ex.ToString());
Thread.Sleep(300000);
}
}
}
catch (Exception ex)
{
this.CatalogMemory.Logger.LogErrorStampNewLine("Se produjo un error con la conexión a PrestaShop. Se reintentará la conexión en 5 minutos. " + Environment.NewLine + ex.ToString());
this.CatalogMemory.Logger.LogDebugStampNewLine(ex.ToString());
Thread.Sleep(300000);
}
}
}
Thanks a lot Edu for your support.
The code you sent has a lots of things to learn from. Unfortunately, my expertise goes far away from your example and I do not know if I will be able to understand it but I´ll try. I will appreciate a couple of small examples of how to: 1.- Create a combination (Size,Color) and "associate" it to the product. 1.- Create an association (Categories of a product) and how to "associate" it to the product.
Surely I am too "green" and I need also to start learning Prestashop internals..Is it there any good manual or technical paper available??
I appreciate very much your support.
Hello i like set a example, of how create an combination product in prestashop with prestasharpt, I hope it is of interest.
CombinationFactory CombinationFactory = new CombinationFactory(BaseUrl, Account, Password); Bukimedia.PrestaSharp.Entities.combination Combination = new Bukimedia.PrestaSharp.Entities.combination(); Dictionary<string, string> dtn = new Dictionary<string, string>(); dtn.Add("reference", referer);
Bukimedia.PrestaSharp.Entities.combination fabricanteobject = new Bukimedia.PrestaSharp.Entities.combination();
List
Combination.id_product = idproduct; Combination.quantity = quantity; Combination.reference = referer; Combination.minimal_quantity = minimaunidad; Combination.unit_price_impact = impactoprecio;
List
Bukimedia.PrestaSharp.Entities.combination fabricanteobject2 = new Bukimedia.PrestaSharp.Entities.combination(); combinationexist = CombinationFactory.GetByFilter(dtn, null, null); if (size != " ") { int combinacion = check_combination(1, size, 1); productvalue[0].id = Convert.ToInt32(combinacion); combinationexist[0].associations.product_option_values.Add(productvalue[0]); combinationexist[0].quantity = quantity; combinationexist[0].id_product = idproduct; combinationexist[0].quantity = quantity; combinationexist[0].minimal_quantity = minimaunidad; combinationexist[0].unit_price_impact = impactoprecio; combinationexist.Add(combinationexist[0]); } try { CombinationFactory.Update(combinationexist[0]); } catch{}
Hello @Digitaldot-Murcia , i have any questions.
1- I can not find the function check_combination(1,x,1) 2- dtn.Add("reference", referer); referer????
Thanks for your help!!!
Hi, the funtion check_combination give 0 if not exist and else return id of combination.
Referer is the reference for my combination.
static Int32 check_combination(int idlanguage, string valueofcombination, int grupo)
{
Int32 idcombinacion = 0;
ProductOptionValueFactory ProductOptionValueFactory = new ProductOptionValueFactory(BaseUrl, Account, Password);
Dictionary<string, string> dtnbuscarvalueofcombination = new Dictionary<string, string>();
dtnbuscarvalueofcombination.Add("name", valueofcombination);
List
Thank you all for your so invaluable contributions !!!
I have the next issue:
I create a product -> ok. I create several combinations -> Everything seems to be ok.
When I go to the prestashop frontend, in the product description, I see that the price corresponds to the "unit_price_impact" value and not to the "base_price + unit_price_impact" as it should be. If I go to the backEnd and I just save one of the combinations (whichever!!), all prices and combinations are showing right prices.
Is this happening to you too?. Is This a problem of RestSharp, Prestasharp or Prestashop webservices? In my oppinion it is a problem of Prestashop. Could you please investigate about that so we can open an issue in prestashop support?
Thanks in advance.
I attach a couple of screeshots of before and after.
Hello @RCallejo2 Have you marked a combination as default?
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I would be very gratefull if someone could send me an Combination code example including any Association for the combination.
Thanks in advance.