Example #1
0
        public void Exec(Int32 ArticleSend)
        {
            try
            {
                Model.Local.ArticleRepository        ArticleRepository = new Model.Local.ArticleRepository();
                Model.Local.Article                  Article           = ArticleRepository.ReadArticle(ArticleSend);
                Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository();
                Model.Prestashop.PsProduct           Product           = new Model.Prestashop.PsProduct();
                // If the Article have a connection with Prestashop
                if (Article.Pre_Id != null)
                {
                    //Article.Art_Date = Article.Art_Date.AddMilliseconds(-Article.Art_Date.Millisecond);
                    if (ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value)))
                    {
                        Product = ProductRepository.ReadId(Convert.ToUInt32(Article.Pre_Id.Value));

                        Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                        if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
                        {
                            SynchronisationArticle.ExecFeature(Article);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Example #2
0
 public void Exec(Int32 ArticleSend)
 {
     try
     {
         Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
         Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);
         // If the catalog is sync with Prestashop
         if (Article.Catalog.Pre_Id != null || Article.Catalog.Pre_Id != 0)
         {
             Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository();
             Model.Prestashop.PsProduct           Product           = new Model.Prestashop.PsProduct();
             // If the Article have a connection with Prestashop
             if (Article.Pre_Id != null)
             {
                 if (ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value)))
                 {
                     this.ExecLocalToDistant(Article);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
Example #3
0
        public void Exec(Int32 ArticleSend)
        {
            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);

                // If the catalog is sync with Prestashop
                //if (Article.Catalog.Pre_Id != null || Article.Catalog.Pre_Id != 0)
                {
                    Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository();
                    Boolean isProduct = false;
                    // If the Article have a connection with Prestashop
                    if (Article.Pre_Id != null &&
                        ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value)))
                    {
                        Model.Prestashop.PsProduct Product = ProductRepository.ReadId(Convert.ToUInt32(Article.Pre_Id.Value));
                        isProduct = true;
                        if (Product.DateUpd.Ticks > Article.Art_Date.Ticks)
                        {
                            this.ExecDistantToLocal(Product, Article, ArticleRepository);
                        }
                        else if (Product.DateUpd.Ticks < Article.Art_Date.Ticks)
                        {
                            this.ExecLocalToDistant(Article, Product, ArticleRepository, ProductRepository, isProduct);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Example #4
0
        public ImportPrestashopArticleManuel()
        {
            InitializeComponent();
            Model.Prestashop.PsProductRepository  PsProductRepository = new Model.Prestashop.PsProductRepository();
            List <Model.Prestashop.ProductResume> list = PsProductRepository.ListResume();

            Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
            List <int> listlocal = ArticleRepository.ListPrestashop();

            list = list.Where(p => !listlocal.Contains((int)p.id_product)).ToList();
            dataGridPsProduct.ItemsSource = list;
        }
Example #5
0
        public void Exec(Int32 ArticleSend, out List <string> log_chrono, out uint pre_id)
        {
            log_chrono = new List <string>();
            pre_id     = 0;
            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                Model.Local.Article           Article           = ArticleRepository.ReadArticle(ArticleSend);

                DateTime start = DateTime.UtcNow;
                if (Core.Global.GetConfig().ChronoSynchroStockPriceActif)
                {
                    log_chrono.Add("----" + Article.Art_Ref + "----" + start.ToString("HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture));
                }

                Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository();
                Model.Prestashop.PsProduct           Product           = new Model.Prestashop.PsProduct();
                // If the Article have a connection with Prestashop
                if (Article.Pre_Id != null)
                {
                    //Article.Art_Date = Article.Art_Date.AddMilliseconds(-Article.Art_Date.Millisecond);
                    if (ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value)))
                    {
                        Product = ProductRepository.ReadId(Convert.ToUInt32(Article.Pre_Id.Value));
                        List <string> log;
                        this.ExecLocalToDistant(Article, Product, ProductRepository, out log);
                        if (log != null && log.Count > 0)
                        {
                            log_chrono.AddRange(log);
                        }
                        pre_id = Product.IDProduct;
                    }
                }
                if (Core.Global.GetConfig().ChronoSynchroStockPriceActif)
                {
                    log_chrono.Add("----" + Article.Art_Ref + "----" + (DateTime.UtcNow - start).ToString());
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Example #6
0
 public void Exec(Int32 ArticleSend)
 {
     try
     {
         Model.Local.ArticleRepository        ArticleRepository = new Model.Local.ArticleRepository();
         Model.Local.Article                  Article           = ArticleRepository.ReadArticle(ArticleSend);
         Model.Prestashop.PsProductRepository ProductRepository = new Model.Prestashop.PsProductRepository();
         Model.Prestashop.PsProduct           Product           = new Model.Prestashop.PsProduct();
         // If the Article have a connection with Prestashop
         if (Article.Pre_Id != null)
         {
             //Article.Art_Date = Article.Art_Date.AddMilliseconds(-Article.Art_Date.Millisecond);
             if (ProductRepository.ExistId(Convert.ToUInt32(Article.Pre_Id.Value)))
             {
                 Product = ProductRepository.ReadId(Convert.ToUInt32(Article.Pre_Id.Value));
                 this.ExecLocalToDistant(Article, ArticleRepository, Product, ProductRepository);
             }
         }
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
Example #7
0
 private void ExecLocalToDistant(Model.Local.Article Article, Model.Local.ArticleRepository ArticleRepository, Model.Prestashop.PsProduct Product, Model.Prestashop.PsProductRepository ProductRepository)
 {
     try
     {
         Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
         if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
         {
             Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);
             Model.Prestashop.PsPackRepository PsPackRepository = new Model.Prestashop.PsPackRepository();
             List <Model.Prestashop.PsPack>    ListPsPack       = PsPackRepository.ListProductPack(Product.IDProduct);
             foreach (Model.Prestashop.PsPack PsPack in ListPsPack)
             {
                 PsPackRepository.Delete(PsPack);
             }
             #region Pack/nomenclature
             if (Article.Art_Pack == true)
             {
                 Model.Sage.F_NOMENCLATRepository F_NOMENCLATRepository = new Model.Sage.F_NOMENCLATRepository();
                 List <Model.Sage.F_NOMENCLAT>    ListF_NOMENCLAT       = F_NOMENCLATRepository.ListRef(F_ARTICLE.AR_Ref);
                 Model.Sage.F_ARTICLE             F_ARTICLENOMENCLAT;
                 Model.Local.Article     ArticleNomenclat;
                 Model.Prestashop.PsPack PsPackAdd;
                 foreach (Model.Sage.F_NOMENCLAT F_NOMENCLAT in ListF_NOMENCLAT)
                 {
                     if (F_ARTICLERepository.ExistReference(F_NOMENCLAT.NO_RefDet))
                     {
                         F_ARTICLENOMENCLAT = F_ARTICLERepository.ReadReference(F_NOMENCLAT.NO_RefDet);
                         if (ArticleRepository.ExistSag_Id(F_ARTICLENOMENCLAT.cbMarq) &&
                             F_ARTICLENOMENCLAT.AR_SuiviStock != (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_SuiviStock.Aucun)
                         // pour ne pas prendre en compte les articles non suivi en stock
                         {
                             ArticleNomenclat = ArticleRepository.ReadSag_Id(F_ARTICLENOMENCLAT.cbMarq);
                             if (ArticleNomenclat.Pre_Id != null && ArticleNomenclat.Pre_Id.Value != 0)
                             {
                                 if (ProductRepository.ExistId((UInt32)ArticleNomenclat.Pre_Id.Value))
                                 {
                                     PsPackAdd = new Model.Prestashop.PsPack()
                                     {
                                         IDProductPack = Product.IDProduct,
                                         IDProductItem = (UInt32)ArticleNomenclat.Pre_Id.Value,
                                         Quantity      = (UInt32)F_NOMENCLAT.NO_Qte.Value
                                     };
                                     PsPackRepository.Add(PsPackAdd);
                                 }
                             }
                         }
                     }
                 }
             }
             #endregion
         }
     }
     catch (Exception ex)
     {
         Core.Error.SendMailError(ex.ToString());
     }
 }
Example #8
0
        //<YH> 23/08/2012
        private void ExecLocalToDistant(Model.Local.Article Article)
        {
            try
            {
                Model.Prestashop.PsAttachmentRepository PsAttachmentRepository = new Model.Prestashop.PsAttachmentRepository();
                Model.Prestashop.PsAttachment           PsAttachment;

                Model.Prestashop.PsAttachmentLangRepository PsAttachmentLangRepository = new Model.Prestashop.PsAttachmentLangRepository();
                Model.Prestashop.PsAttachmentLang           PsAttachmentLang;

                Model.Prestashop.PsProductAttachmentRepository PsProductAttachmentRepository = new Model.Prestashop.PsProductAttachmentRepository();
                Model.Prestashop.PsProductAttachment           PsProductAttachment;

                Boolean isAttachmentLang = false;

                String FTP      = Core.Global.GetConfig().ConfigFTPIP;
                String User     = Core.Global.GetConfig().ConfigFTPUser;
                String Password = Core.Global.GetConfig().ConfigFTPPassword;

                Model.Local.AttachmentRepository AttachmentRepository = new Model.Local.AttachmentRepository();
                List <Model.Local.Attachment>    ListAttachment       = AttachmentRepository.ListArticle(Article.Art_Id);
                foreach (Model.Local.Attachment Attachment in ListAttachment)
                {
                    try
                    {
                        if (Attachment.Pre_Id == null)
                        {
                            String PathAttachment = Path.Combine(Global.GetConfig().Folders.RootAttachment, Attachment.Att_File);
                            if (System.IO.File.Exists(PathAttachment))
                            {
                                #region infos document joint
                                PsAttachment          = new Model.Prestashop.PsAttachment();
                                PsAttachment.File     = Attachment.Att_File;
                                PsAttachment.FileName = Attachment.Att_FileName;
                                PsAttachment.Mime     = Attachment.Att_Mime;
                                PsAttachmentRepository.Add(PsAttachment);

                                isAttachmentLang = false;
                                PsAttachmentLang = new Model.Prestashop.PsAttachmentLang();
                                if (PsAttachmentLangRepository.ExistAttachmentLang(PsAttachment.IDAttachment, Core.Global.Lang))
                                {
                                    PsAttachmentLang = PsAttachmentLangRepository.ReadAttachmentLang(PsAttachment.IDAttachment, Core.Global.Lang);
                                    isAttachmentLang = true;
                                }
                                PsAttachmentLang.Name        = Attachment.Att_Name;
                                PsAttachmentLang.Description = Attachment.Att_Description;
                                if (isAttachmentLang == true)
                                {
                                    PsAttachmentLangRepository.Save();
                                }
                                else
                                {
                                    PsAttachmentLang.IDAttachment = PsAttachment.IDAttachment;
                                    PsAttachmentLang.IDLang       = Core.Global.Lang;
                                    PsAttachmentLangRepository.Add(PsAttachmentLang);
                                }
                                #endregion

                                // <JG> 24/05/2013 ajout insertion autres langues actives si non renseignées
                                #region Multi-langues
                                try
                                {
                                    Model.Prestashop.PsLangRepository PsLangRepository = new Model.Prestashop.PsLangRepository();
                                    foreach (Model.Prestashop.PsLang PsLang in PsLangRepository.ListActive(1, Global.CurrentShop.IDShop))
                                    {
                                        if (!PsAttachmentLangRepository.ExistAttachmentLang(PsAttachment.IDAttachment, PsLang.IDLang))
                                        {
                                            PsAttachmentLang = new Model.Prestashop.PsAttachmentLang()
                                            {
                                                IDAttachment = PsAttachment.IDAttachment,
                                                IDLang       = PsLang.IDLang,
                                                Name         = Attachment.Att_Name,
                                                Description  = Attachment.Att_Description
                                            };
                                            PsAttachmentLangRepository.Add(PsAttachmentLang);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Core.Error.SendMailError(ex.ToString());
                                }
                                #endregion

                                // affectation au produit
                                PsProductAttachment = new Model.Prestashop.PsProductAttachment();
                                if (PsProductAttachmentRepository.ExistProductAttachment(Convert.ToUInt32(Article.Pre_Id), PsAttachment.IDAttachment) == false)
                                {
                                    PsProductAttachment.IDProduct    = Convert.ToUInt32(Article.Pre_Id);
                                    PsProductAttachment.IDAttachment = PsAttachment.IDAttachment;
                                    PsProductAttachmentRepository.Add(PsProductAttachment);
                                }

                                try
                                {
                                    #region upload

                                    string ftpfullpath           = FTP + "/download/" + Attachment.Att_File;
                                    System.Net.FtpWebRequest ftp = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(ftpfullpath);
                                    ftp.Credentials = new System.Net.NetworkCredential(User, Password);
                                    //userid and password for the ftp server to given

                                    ftp.UseBinary = true;
                                    ftp.Method    = System.Net.WebRequestMethods.Ftp.UploadFile;
                                    System.IO.FileStream fs = System.IO.File.OpenRead(PathAttachment);
                                    byte[] buffer           = new byte[fs.Length];
                                    fs.Read(buffer, 0, buffer.Length);
                                    fs.Close();
                                    System.IO.Stream ftpstream = ftp.GetRequestStream();
                                    ftpstream.Write(buffer, 0, buffer.Length);
                                    ftpstream.Close();
                                    ftp.Abort();

                                    #endregion

                                    #region update Product field cache_as_attachements

                                    Model.Prestashop.PsProductRepository PsProductRepository = new Model.Prestashop.PsProductRepository();
                                    Model.Prestashop.PsProduct           PsProduct           = PsProductRepository.ReadId(PsProductAttachment.IDProduct);
                                    if (PsProduct.CacheHasAttachments == 0)
                                    {
                                        PsProduct.CacheHasAttachments = (sbyte)1;
                                        PsProductRepository.Save();
                                    }

                                    #endregion

                                    Attachment.Pre_Id = Convert.ToInt32(PsAttachment.IDAttachment);
                                    AttachmentRepository.Save();
                                }
                                catch (Exception ex)
                                {
                                    Core.Error.SendMailError("[UPLOAD FTP DOCUMENT]<br />" + ex.ToString());
                                    PsProductAttachmentRepository.Delete(PsProductAttachmentRepository.ListAttachment(PsAttachment.IDAttachment));
                                    PsAttachmentLangRepository.Delete(PsAttachmentLangRepository.ListAttachment(PsAttachment.IDAttachment));
                                    PsAttachmentRepository.Delete(PsAttachment);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Core.Error.SendMailError("[SYNCHRO DOCUMENT ARTICLE]<br />" + ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Example #9
0
        private void ExecLocalToDistant(Model.Local.Article Article, Model.Prestashop.PsProduct Product, Model.Prestashop.PsProductRepository PsProductRepository,
                                        out List <string> log_chrono)
        {
            log_chrono = new List <string>();
            try
            {
                if (Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
                {
                    if (Core.UpdateVersion.License.Option2)
                    {
                        Product.Price    = 0;
                        Product.Quantity = 0;
                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                        ExecCompositionArticle(Article, Product);
                    }
                }
                else
                {
                    Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                    if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
                    {
                        Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);
                        SynchronisationArticle.ReadQuantity(F_ARTICLE, Product);

                        #region Stock pack limité par composés
                        if (Article.Art_Pack == true || F_ARTICLE.AR_Nomencl == (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_Nomencl.Commerciale_Composant ||
                            F_ARTICLE.AR_Nomencl == (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_Nomencl.Commerciale_Compose)                                        // pour que les articles en nomenclature soient pris en compte
                        {
                            Model.Sage.F_NOMENCLATRepository F_NOMENCLATRepository = new Model.Sage.F_NOMENCLATRepository();
                            List <Model.Sage.F_NOMENCLAT>    ListF_NOMENCLAT       = F_NOMENCLATRepository.ListRef(F_ARTICLE.AR_Ref);
                            Model.Sage.F_ARTICLE             F_ARTICLENOMENCLAT;
                            Int32 QuantityPack = 0;
                            foreach (Model.Sage.F_NOMENCLAT F_NOMENCLAT in ListF_NOMENCLAT)
                            {
                                if (F_ARTICLERepository.ExistReference(F_NOMENCLAT.NO_RefDet))
                                {
                                    F_ARTICLENOMENCLAT = F_ARTICLERepository.ReadReference(F_NOMENCLAT.NO_RefDet);
                                    if (F_ARTICLENOMENCLAT.AR_SuiviStock != (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_SuiviStock.Aucun)                                                            // pour ne pas prendre en compte les articles non suivi en stock
                                    {
                                        Int32 CurrentQuantity = SynchronisationArticle.ReadQuantityPack(F_ARTICLENOMENCLAT, F_NOMENCLAT.NO_Qte.Value);
                                        if (Core.Global.GetConfig().ArticleStockNegatifZero&& CurrentQuantity < 0)
                                        {
                                            CurrentQuantity = 0;
                                        }
                                        if (CurrentQuantity < QuantityPack)
                                        {
                                            QuantityPack = CurrentQuantity;
                                        }
                                        else if (QuantityPack == 0)
                                        {
                                            QuantityPack = CurrentQuantity;
                                            // <AM> 14/08/2014 Si un des articles composant n'a pas de stock on sort de la fonction pour que l'article parent ai un stock à 0
                                            if (CurrentQuantity == 0)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            Product.Quantity = QuantityPack;
                        }
                        #endregion

                        int CatComptaArticle      = Core.Global.GetConfig().ConfigArticleCatComptable;
                        Model.Sage.F_TAXE TaxeTVA = SynchronisationArticle.ReadTaxe(F_ARTICLE, Product, CatComptaArticle);
                        Model.Sage.F_TAXE TaxeEco = SynchronisationArticle.ReadEcoTaxe(F_ARTICLE, Product, TaxeTVA, CatComptaArticle);
                        // <JG> 03/06/2016
                        if (Article.Art_SyncPrice)
                        {
                            SynchronisationArticle.ReadPrice(F_ARTICLE, Product, TaxeTVA);
                        }

                        if (Core.Global.GetConfig().MajPoidsSynchroStock)
                        {
                            SynchronisationArticle.ReadWeight(F_ARTICLE, Product);
                        }

                        if (Core.Global.GetConfig().ArticleDateDispoInfoLibreActif)
                        {
                            SynchronisationArticle.ReadDateDispo(Product, F_ARTICLE);
                        }

                        PsProductRepository.Save();
                        PsProductRepository.WriteDate(Product.IDProduct);

                        // <JG> 05/11/2013 déplacement pour application taxes et pdt spécifiques sur nouvelles déclinaisons
                        this.ExecAttribute(Article, Product, TaxeTVA, PsProductRepository);
                        this.ExecConditioning(Article, Product, TaxeTVA, PsProductRepository);

                        // <JG> 03/06/2016
                        if (Article.Art_SyncPrice)
                        {
                            List <string> log;
                            SynchronisationArticle.ExecSpecificPrice(F_ARTICLE, Product, Article, null, TaxeTVA, TaxeEco, out log);
                            if (log != null && log.Count > 0)
                            {
                                log_chrono.AddRange(log);
                            }
                        }

                        // <JG> 17/12/2012
                        SynchronisationArticle.ExecShopProduct(Product);

                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Example #10
0
        private void ExecConditioning(Model.Local.Article Article, Model.Prestashop.PsProduct PsProduct, Model.Sage.F_TAXE TaxeTVA, Model.Prestashop.PsProductRepository PsProductRepository)
        {
            try
            {
                Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
                {
                    Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);

                    Model.Local.ConditioningGroupRepository     ConditioningGroupRepository = new Model.Local.ConditioningGroupRepository();
                    Model.Prestashop.PsAttributeGroupRepository PsAttributeGroupRepository  = new Model.Prestashop.PsAttributeGroupRepository();

                    Boolean isProductAttribute;

                    if (F_ARTICLE.AR_Condition != null && F_ARTICLE.AR_Condition != 0 &&
                        ConditioningGroupRepository.ExistSage((int)F_ARTICLE.AR_Condition) &&
                        PsAttributeGroupRepository.ExistAttributeGroup((uint)ConditioningGroupRepository.ReadSage((int)F_ARTICLE.AR_Condition).Pre_Id))
                    {
                        Model.Local.ConditioningArticleRepository ConditioningArticleRepository = new Model.Local.ConditioningArticleRepository();
                        List <Model.Local.ConditioningArticle>    ListConditioningArticle       = ConditioningArticleRepository.ListArticleSync(Article.Art_Id, true);

                        Model.Prestashop.PsProductAttributeRepository PsProductAttributeRepository = new Model.Prestashop.PsProductAttributeRepository();
                        Model.Prestashop.PsProductAttribute           PsProductAttribute;
                        int stockmaxunity = 0;
                        foreach (Model.Local.ConditioningArticle ConditioningArticle in ListConditioningArticle)
                        {
                            if (ConditioningArticle.EnumereF_CONDITION != null)
                            {
                                PsProductAttribute = new Model.Prestashop.PsProductAttribute();
                                isProductAttribute = false;
                                if (ConditioningArticle.Pre_Id != null && ConditioningArticle.Pre_Id != 0)
                                {
                                    if (PsProductAttributeRepository.ExistProductAttribute((UInt32)ConditioningArticle.Pre_Id))
                                    {
                                        PsProductAttribute = PsProductAttributeRepository.ReadProductAttribute((UInt32)ConditioningArticle.Pre_Id);
                                        isProductAttribute = true;
                                    }
                                }

                                if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                {
                                    SynchronisationArticle.ReadWeightConditioning(PsProduct, PsProductAttribute, ConditioningArticle.EnumereF_CONDITION);
                                }

                                SynchronisationArticle.ReadQuantityConditioning(PsProductAttribute, F_ARTICLE, ConditioningArticle.EnumereF_CONDITION);

                                if (Core.Global.GetConfig().LimiteStockConditionnement&& PsProductAttribute.Quantity >= stockmaxunity)
                                {
                                    stockmaxunity      = PsProductAttribute.Quantity;
                                    PsProduct.Quantity = stockmaxunity;
                                    PsProductRepository.Save();
                                }

                                // <JG> 03/06/2016
                                if (Article.Art_SyncPrice)
                                {
                                    SynchronisationArticle.ReadPriceConditioning(PsProduct, PsProductAttribute, F_ARTICLE, ConditioningArticle.EnumereF_CONDITION, TaxeTVA);
                                }

                                //PsProductAttribute.DefaultOn = (ConditioningArticle.ConArt_Default) ? (byte)1 : (byte)0;
                                if (isProductAttribute == true)
                                {
                                    PsProductAttributeRepository.Save();
                                    SynchronisationArticle.ExecShopProductAttribute(PsProductAttribute);

                                    SynchronisationArticle.WriteStockAvailableProductAttribute(PsProduct, PsProductAttribute);
                                }
                            }
                        }
                        PsProductAttributeRepository.WriteDate(PsProduct.IDProduct);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Example #11
0
        private void ExecAttribute(Model.Local.Article Article, Model.Prestashop.PsProduct PsProduct, Model.Sage.F_TAXE TaxeTVA, Model.Prestashop.PsProductRepository PsProductRepository)
        {
            try
            {
                Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
                {
                    Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);

                    Model.Local.AttributeGroupRepository        AttributeGroupRepository   = new Model.Local.AttributeGroupRepository();
                    Model.Prestashop.PsAttributeGroupRepository PsAttributeGroupRepository = new Model.Prestashop.PsAttributeGroupRepository();

                    Boolean isProductAttribute;

                    if (F_ARTICLE.AR_Gamme1 != null && F_ARTICLE.AR_Gamme1 != 0 &&
                        AttributeGroupRepository.ExistSage((int)F_ARTICLE.AR_Gamme1) &&
                        PsAttributeGroupRepository.ExistAttributeGroup((uint)AttributeGroupRepository.ReadSage((int)F_ARTICLE.AR_Gamme1).Pre_Id) &&
                        ((F_ARTICLE.AR_Gamme2 == null || F_ARTICLE.AR_Gamme2 == 0) ||
                         (AttributeGroupRepository.ExistSage((int)F_ARTICLE.AR_Gamme2) &&
                          PsAttributeGroupRepository.ExistAttributeGroup((uint)AttributeGroupRepository.ReadSage((int)F_ARTICLE.AR_Gamme2).Pre_Id))))
                    {
                        Model.Local.AttributeArticleRepository AttributeArticleRepository = new Model.Local.AttributeArticleRepository();
                        List <Model.Local.AttributeArticle>    ListAttributeArticle       = AttributeArticleRepository.ListArticleSync(Article.Art_Id, true);

                        Model.Prestashop.PsProductAttributeRepository PsProductAttributeRepository = new Model.Prestashop.PsProductAttributeRepository();
                        Model.Prestashop.PsProductAttribute           PsProductAttribute;

                        int CumulStockGammes = 0;
                        foreach (Model.Local.AttributeArticle AttributeArticle in ListAttributeArticle)
                        {
                            if (AttributeArticle.EnumereF_ARTENUMREF != null)
                            {
                                PsProductAttribute = new Model.Prestashop.PsProductAttribute();
                                isProductAttribute = false;

                                if (AttributeArticle.Pre_Id != null && AttributeArticle.Pre_Id != 0)
                                {
                                    if (PsProductAttributeRepository.ExistProductAttribute((UInt32)AttributeArticle.Pre_Id))
                                    {
                                        PsProductAttribute = PsProductAttributeRepository.ReadProductAttribute((UInt32)AttributeArticle.Pre_Id);
                                        isProductAttribute = true;
                                    }
                                }

                                if (isProductAttribute == true)
                                {
                                    if (Core.Global.GetConfig().MajPoidsSynchroStock)
                                    {
                                        SynchronisationArticle.ReadWeightAttribute(PsProduct, PsProductAttribute, F_ARTICLE, AttributeArticle.EnumereGamme1);
                                    }

                                    SynchronisationArticle.ReadQuantityAttribute(PsProductAttribute, F_ARTICLE, AttributeArticle.EnumereGamme1, AttributeArticle.EnumereGamme2);
                                    CumulStockGammes += PsProductAttribute.Quantity;

                                    // <JG> 03/06/2016
                                    if (Article.Art_SyncPrice)
                                    {
                                        SynchronisationArticle.ReadPriceAttribute(PsProduct, PsProductAttribute, F_ARTICLE, AttributeArticle.EnumereGamme1, AttributeArticle.EnumereGamme2, TaxeTVA);
                                    }

                                    PsProductAttributeRepository.Save();
                                    SynchronisationArticle.ExecShopProductAttribute(PsProductAttribute);

                                    SynchronisationArticle.WriteStockAvailableProductAttribute(PsProduct, PsProductAttribute);
                                }
                            }
                        }
                        if (PsProduct.Quantity != CumulStockGammes)
                        {
                            PsProduct.Quantity = CumulStockGammes;
                            PsProductRepository.Save();
                        }
                        PsProductAttributeRepository.WriteDate(PsProduct.IDProduct);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Example #12
0
        private void ExecLocalToDistant(Model.Local.Article Article, Model.Prestashop.PsProduct Product, Model.Local.ArticleRepository ArticleRepository, Model.Prestashop.PsProductRepository ProductRepository, Boolean isProduct)
        {
            try
            {
                if (isProduct)
                {
                    Model.Local.CatalogRepository CatalogRepository = new Model.Local.CatalogRepository();
                    Model.Local.Catalog           Catalog           = CatalogRepository.ReadId(Article.Cat_Id);

                    if (Catalog.Pre_Id != null && new Model.Prestashop.PsCategoryRepository().ExistId((int)Catalog.Pre_Id))
                    {
                        Product.IDCategoryDefault = Convert.ToUInt32(Catalog.Pre_Id);

                        ProductRepository.Save();

                        this.AssignCatalogProduct(Article, Product, ArticleRepository);

                        // <JG> 17/12/2012
                        this.ExecShopProduct(Product);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
Example #13
0
        private void ExecLocalToDistant(Model.Local.Article Article, Model.Prestashop.PsProduct Product, Model.Prestashop.PsProductRepository PsProductRepository)
        {
            try
            {
                if (Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
                {
                    if (Core.UpdateVersion.License.Option2)
                    {
                        Product.Quantity = 0;
                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                        ExecCompositionArticle(Article, Product);
                    }
                }
                else
                {
                    Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                    if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
                    {
                        Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);
                        SynchronisationArticle.ReadQuantity(F_ARTICLE, Product);

                        #region Stock pack limité par composés
                        if (Article.Art_Pack == true || F_ARTICLE.AR_Nomencl == (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_Nomencl.Commerciale_Composant ||
                            F_ARTICLE.AR_Nomencl == (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_Nomencl.Commerciale_Compose)                                        // pour que les articles en nomenclature soient pris en compte
                        {
                            Model.Sage.F_NOMENCLATRepository F_NOMENCLATRepository = new Model.Sage.F_NOMENCLATRepository();
                            List <Model.Sage.F_NOMENCLAT>    ListF_NOMENCLAT       = F_NOMENCLATRepository.ListRef(F_ARTICLE.AR_Ref);
                            Model.Sage.F_ARTICLE             F_ARTICLENOMENCLAT;
                            Int32 QuantityPack = 0;
                            foreach (Model.Sage.F_NOMENCLAT F_NOMENCLAT in ListF_NOMENCLAT)
                            {
                                if (F_ARTICLERepository.ExistReference(F_NOMENCLAT.NO_RefDet))
                                {
                                    F_ARTICLENOMENCLAT = F_ARTICLERepository.ReadReference(F_NOMENCLAT.NO_RefDet);
                                    if (F_ARTICLENOMENCLAT.AR_SuiviStock != (short)ABSTRACTION_SAGE.F_ARTICLE.Obj._Enum_AR_SuiviStock.Aucun)                                            // pour ne pas prendre en compte les articles non suivi en stock
                                    {
                                        Int32 CurrentQuantity = SynchronisationArticle.ReadQuantityPack(F_ARTICLENOMENCLAT, F_NOMENCLAT.NO_Qte.Value);
                                        if (Core.Global.GetConfig().ArticleStockNegatifZero&& CurrentQuantity < 0)
                                        {
                                            CurrentQuantity = 0;
                                        }
                                        if (CurrentQuantity < QuantityPack)
                                        {
                                            QuantityPack = CurrentQuantity;
                                            // <AM> 14/08/2014 Si un des articles composant n'a pas de stock on sort de la fonction pour que l'article parent ai un stock à 0
                                            if (CurrentQuantity == 0)
                                            {
                                                break;
                                            }
                                        }
                                        else if (QuantityPack == 0)
                                        {
                                            QuantityPack = CurrentQuantity;
                                            // <AM> 14/08/2014 Si un des articles composant n'a pas de stock on sort de la fonction pour que l'article parent ai un stock à 0
                                            if (CurrentQuantity == 0)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            Product.Quantity = QuantityPack;
                        }
                        #endregion

                        // <JG> 29/10/2012 ajout synchronisation des stocks seule
                        //SynchronisationArticle.ReadEcoTaxe(F_ARTICLE, Product);
                        //SynchronisationArticle.ReadPrice(F_ARTICLE, Product);

                        if (Core.Global.GetConfig().MajPoidsSynchroStock)
                        {
                            SynchronisationArticle.ReadWeight(F_ARTICLE, Product);
                        }

                        if (Core.Global.GetConfig().ArticleDateDispoInfoLibreActif)
                        {
                            SynchronisationArticle.ReadDateDispo(Product, F_ARTICLE);
                        }

                        PsProductRepository.Save();
                        PsProductRepository.WriteDate(Product.IDProduct);

                        this.ExecAttribute(Article, Product, PsProductRepository);
                        this.ExecConditioning(Article, Product, PsProductRepository);

                        //SynchronisationArticle.ExecSpecificPrice(F_ARTICLE, Product);

                        // <JG> 17/12/2012
                        SynchronisationArticle.ExecShopProduct(Product);

                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        public void Exec(Int32 ProductSend)
        {
            try
            {
                Model.Local.ArticleRepository ArticleRepository = new Model.Local.ArticleRepository();
                if (ArticleRepository.ExistPre_Id(ProductSend) == false)
                {
                    Model.Prestashop.PsProductLangRepository PsProductLangRepository = new Model.Prestashop.PsProductLangRepository();
                    if (PsProductLangRepository.ExistProductLang(ProductSend, Global.Lang, Global.CurrentShop.IDShop))
                    {
                        Model.Prestashop.PsProductRepository PsProductRepository = new Model.Prestashop.PsProductRepository();
                        Model.Prestashop.PsProduct           PsProduct           = PsProductRepository.ReadId(Convert.ToUInt32(ProductSend));
                        Model.Prestashop.PsProductLang       PsProductLang       = PsProductLangRepository.ReadProductLang(ProductSend, Global.Lang, Global.CurrentShop.IDShop);

                        Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                        string product_reference = PsProduct.Reference;
                        product_reference = product_reference.Replace(" ", "_");
                        if (F_ARTICLERepository.ExistReference(product_reference))
                        {
                            Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadReference(product_reference);
                            Model.Local.Article  Article   = new Model.Local.Article()
                            {
                                Art_Name              = PsProductLang.Name,
                                Art_Description       = PsProductLang.Description,
                                Art_Description_Short = PsProductLang.DescriptionShort,
                                Art_LinkRewrite       = PsProductLang.LinkRewrite,
                                Art_MetaTitle         = PsProductLang.MetaTitle,
                                Art_MetaKeyword       = PsProductLang.MetaKeywords,
                                Art_MetaDescription   = PsProductLang.MetaDescription,
                                Art_Ref             = PsProduct.Reference,
                                Art_Ean13           = PsProduct.EAn13,
                                Art_Pack            = PsProduct.CacheIsPack == 1,
                                Art_Solde           = Convert.ToBoolean(PsProduct.OnSale),
                                Art_Active          = Convert.ToBoolean(PsProduct.Active),
                                Art_Sync            = true,
                                Art_SyncPrice       = true,
                                Art_Date            = (PsProduct.DateUpd != null && PsProduct.DateUpd > new DateTime(1753, 1, 2)) ? PsProduct.DateUpd : DateTime.Now.Date,
                                Sag_Id              = F_ARTICLE.cbMarq,
                                Pre_Id              = Convert.ToInt32(PsProduct.IDProduct),
                                Cat_Id              = this.ReadCatalog(PsProduct.IDCategoryDefault),
                                Art_RedirectType    = new Model.Internal.RedirectType(Core.Parametres.RedirectType.NoRedirect404).Page,
                                Art_RedirectProduct = 0,
                                Art_Manufacturer    = (PsProduct.IDManufacturer != null) ? (int)PsProduct.IDManufacturer : 0,
                                Art_Supplier        = (PsProduct.IDSupplier != null) ? (int)PsProduct.IDSupplier : 0,
                            };

                            if (Article.Cat_Id == 0)
                            {
                                foreach (Model.Prestashop.PsCategoryProduct PsCategoryProduct in new Model.Prestashop.PsCategoryProductRepository().ListProduct(PsProduct.IDProduct))
                                {
                                    Article.Cat_Id = this.ReadCatalog(PsCategoryProduct.IDCategory);
                                    if (Article.Cat_Id != 0)
                                    {
                                        break;
                                    }
                                }
                            }

                            if (PsProduct.CacheIsPack == 1)
                            {
                                Article.Art_Pack = true;
                            }
                            if (Article.Cat_Id != 0)
                            {
                                ArticleRepository.Add(Article);
                                RecoveryChildData(Article, PsProduct, ArticleRepository, false);
                            }
                        }
                    }
                }
                else
                {
                    Model.Local.Article Article = ArticleRepository.ReadPre_Id(ProductSend);
                    Model.Prestashop.PsProductRepository PsProductRepository = new Model.Prestashop.PsProductRepository();
                    Model.Prestashop.PsProduct           PsProduct           = PsProductRepository.ReadId(Convert.ToUInt32(ProductSend));
                    RecoveryChildData(Article, PsProduct, ArticleRepository, true);
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }
        private void ExecLocalToDistant(Model.Local.Article Article, Model.Prestashop.PsProduct Product, Model.Prestashop.PsProductRepository ProductRepository)
        {
            try
            {
                if (Article.TypeArticle == Model.Local.Article.enum_TypeArticle.ArticleComposition)
                {
                    if (Core.UpdateVersion.License.Option2)
                    {
                        Product.Quantity = 0;
                        Product.Price    = 0;
                        SynchronisationArticle.WriteStockAvailableProduct(Product);
                        SynchronisationArticle.ExecCompositionArticle(Article, Product, ProductRepository);
                    }
                }
                else
                {
                    Model.Sage.F_ARTICLERepository F_ARTICLERepository = new Model.Sage.F_ARTICLERepository();
                    if (F_ARTICLERepository.ExistArticle(Article.Sag_Id))
                    {
                        Model.Sage.F_ARTICLE F_ARTICLE = F_ARTICLERepository.ReadArticle(Article.Sag_Id);

                        if ((F_ARTICLE.AR_Gamme1 != null && F_ARTICLE.AR_Gamme1 != 0) || (F_ARTICLE.AR_Condition != null && F_ARTICLE.AR_Condition != 0))
                        {
                            int CatComptaArticle      = Core.Global.GetConfig().ConfigArticleCatComptable;
                            Model.Sage.F_TAXE TaxeTVA = SynchronisationArticle.ReadTaxe(F_ARTICLE, Product, CatComptaArticle);
                            Model.Sage.F_TAXE TaxeEco = SynchronisationArticle.ReadEcoTaxe(F_ARTICLE, Product, TaxeTVA, CatComptaArticle);
                            SynchronisationArticle.ReadPrice(F_ARTICLE, Product, TaxeTVA);


                            // <JG> 19/02/2013 déplacement pour correction problème prix spécifiques lors de la création de l'article
                            SynchronisationArticle.ExecAttribute(Article, Product, ProductRepository, TaxeTVA);
                            SynchronisationArticle.ExecConditioning(Article, Product, ProductRepository, TaxeTVA);

                            //List<string> log;
                            //SynchronisationArticle.ExecSpecificPrice(F_ARTICLE, Product, Article.Art_Id, TaxeTVA, TaxeEco, out log);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Error.SendMailError(ex.ToString());
            }
        }