Bukimedia / PrestaSharp

CSharp .Net client library for the PrestaShop API via web service
GNU General Public License v3.0
155 stars 152 forks source link

Example to Add new category #276

Closed pc4service closed 5 years ago

pc4service commented 7 years ago

Have you example in C# , who to add new category using PrestaSharp ?

LuisFReis commented 7 years ago
using Bukimedia.PrestaSharp.Factories;
using Bukimedia.PrestaSharp.Entities;

namespace Prestashop
{
    public partial class CategoryPost
    {
        public CategoryPost()
        {
                category category = new category();
                category.AddName(new Bukimedia.PrestaSharp.Entities.AuxEntities.language { id = 1, Value = "Lang 1" });
                category.AddName(new Bukimedia.PrestaSharp.Entities.AuxEntities.language { id = 2, Value = "Lang 2" });
                category.id_parent = 2; // This is the beginning category
                category.AddLinkRewrite(new Bukimedia.PrestaSharp.Entities.AuxEntities.language { id = 1, Value = "test_lang1" });
                category.AddLinkRewrite(new Bukimedia.PrestaSharp.Entities.AuxEntities.language { id = 2, Value = "test_lang2" });
                category.active = 1;
                category.is_root_category = 0;
                category.id_shop_default = 1;

                CategoryFactory Category = new CategoryFactory(PrestashopForm.BaseUrl, PrestashopForm.Account, PrestashopForm.Password);
                Category.Add(category);
         }
   }
}

However in this case I can insert the category but it is not enable under the frontstore. Needs to add it to the top menu in modules configuration in backoffice.

mowcixo commented 5 years ago

Hello @pc4service, the example provided by @LuisFReis should work.

lock[bot] commented 4 years ago

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.