我正在尝试在 prestashop 中开发一个功能来应用促销

问题描述

我想在 prestashop 中创建促销功能,但这不起作用

如您所见,我想为多种产品创建多个特定价格。我的问题是这段代码不起作用。

我硬编码

  • specificPrice.id_group = 1;
  • specificPrice.id_group = 1;
  • specificPrice.id_cart = 1;

因为它们是强制性的,但我的数据库中没有它们。有人可以帮我找到正确的解决方案吗?我想为多个产品创建一个特定的价格以适用于所有组和所有 coostumers,但我不知道我应该将什么 id 传递给 specificPrice.id_group....

 public static void Promotion()
        {
            using (sqlConnection con = new sqlConnection(Properties.Settings.Default.HQRConnectionString))
            {
                con.open();

                string cmdstring =
                    "select"
                    + " P.productId,Pd.price,PD.promotionId "
                    + " from promotiondetails PD "
                    + " join products P "
                    + " on P.productId = Pd.productId "
                    + " where P.isecommerceenabled = '1' "
                    + " and PD.promotionId in (select promotionid from promotionstores where storeid = @StoreId)"; 






                sqlCommand cmd = new sqlCommand(cmdstring,con);
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add("@StoreId",sqlDbType.Int).Value = Settings.Default.WebStoreId;

                sqlDataAdapter sda = new sqlDataAdapter(cmd);
                DataTable table = new DataTable();
                sda.Fill(table);

                foreach (DaTarow row in table.Rows)
                {
                   
                    string productId = Convert.ToString(row["ProductId"]);
                    IPosXPO.Products product = unitOfWork.GetobjectByKey<Products>(productId);
                    Bukimedia.PrestaSharp.Entities.product prod = GetPrestashopProduct(product);

                    if (product.IsEcommerceEnabled && prod != null)
                        {
                        specific_price specificPrice = new specific_price();
                        specificPrice.id_product = prod.id;
                        
                        int promotionId= Convert.ToInt16(row["PromotionId"]);
                        IPosXPO.Promotions promotion = unitOfWork.GetobjectByKey<Promotions>(promotionId);
                        //   string format = Convert.ToString(promotion.StartDate);
                        //DateTime dt = DateTime.ParseExact(format,"YYYY-MM-DD HH:MM:SS",CultureInfo.InvariantCulture);

                        int year = promotion.StartDate.Year;
                        int month = promotion.StartDate.Month;
                        int day = promotion.StartDate.Day;
                        specificPrice.from =  year + "-" + month + "-" + day + " " + "00" + ":" + "00" + ":" + "00";
                     

                       
                         year = promotion.EndDate.Year;
                         month = promotion.EndDate.Month;
                        day = promotion.EndDate.Day;
                        specificPrice.to = year + "-" + month + "-" + day + " " + "00" + ":" + "00" + ":" + "00";

                        decimal price = Convert.ToDecimal(row["Price"]);
                        specificPrice.id_shop = Settings.Default.WebStoreId;
                        specificPrice.price = price;
                        specificPrice.id_cart = 1;
                       Currencies currency = unitOfWork.GetobjectByKey<Currencies>("EUR");
                        specificPrice.id_currency = 1;
                        specificPrice.id_group = 1;
                        specificPrice.id_customer = null;
                        specificPrice.reduction_type = "amount";
                        specificPrice.reduction_tax = 1;
                        specificPrice.id_country = promotion.CountryId.CountryId;
                        specificPriceFactory.Add(specificPrice);

                    }
                    
                }
                con.Close();
            }
        }

解决方法

只需将其设置为零即可。

在创建 specific_price 时,将值保留为 0 意味着价格将应用于所有实体值。

此外,您还应该设置 id_cart = 0,因为我猜您不希望将特定价格绑定到特定客户购物车。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...