PrestaSharp icon indicating copy to clipboard operation
PrestaSharp copied to clipboard

Update stock not working with combinations

Open polaije opened this issue 5 years ago • 0 comments

Hello, Here is the code used for updating combination but the update return no error but Nothing is changed in the product : CombinationFactory Combination = new CombinationFactory(Properties.Settings.Default.BaseUrl2, Properties.Settings.Default.Account2, ""); Dictionary<string, string> filterComb = new Dictionary<string, string>(); filterComb.Add("id_product", prestaProduct.id.ToString()); SelCom = Combination.GetByFilter(filterComb, null, null); StockAvailableFactory St = new StockAvailableFactory(BaseUrl2, Account2, ""); Dictionary<string, string> filterSt = new Dictionary<string, string>();

            for (int ii = 0; ii <= SelCom.Count - 1; ii++)
            {
                filterSt.Clear();
                filterSt.Add("id_product_attribute", SelCom[ii].id.ToString());
                var St1 = St.GetByFilter(filterSt, null, null);
                if (St1.Count == 1)
                {
                    SelCom[ii].quantity = St1[0].quantity;
                    combination Combinaison = SelCom[ii];
                    decimal TVA = prestaProduct.id_tax_rules_group == 17 ? 6 : 21;
                    decimal Prix = prestaProduct.price + Combinaison.price;
                    decimal PrixTVAC = (Math.Ceiling(Prix * (100 + TVA)));
                    int Stock = Combinaison.quantity;
                    if (Stock == 0)
                    {
                         //Check on website factory if stock >0                            
                        Retour = CheckFebelco(prestaProduct, "Com", Combinaison.reference, Stock);
                        if (Retour.Substring(0, 1) == "D") // stock OK
                        {
                            Combinaison.quantity = 20;
                            Combination.Update(Combinaison);
                            St.Update(St1[0]); // I am not sure if I have to do it
                           
                        }
                    }
                }

                else
                    MessageBox.Show("Erreur recherche stock " + SelCom[ii].id.ToString());
            }

Can you help me with this issue.

Jean-Marie

polaije avatar May 31 '20 15:05 polaije