在Kentico 10中隐藏产品

时间:2017-02-13 11:53:07

标签: kentico

我正在为kentico 10中的电子商务网站产品执行CRUD操作。我可以使用以下API添加和更新产品

 $this->View->render('medicines/medicine1/info');

还有一个用于删除产品的API

SKUInfoProvider.SetSKUInfo(updateProduct);

但我不希望从数据库中删除该产品,而只是禁用它们,以便它们不会显示给最终用户并仍然留在数据库中。

我尝试将SKUEnabled设置为false但仍然可以看到产品。所以,我使用下面的代码来隐藏产品

SKUInfoProvider.DeleteSKUInfo(updateProduct);

但我的代码设置添加了一个带有上述禁用属性的新产品。这是我的代码

ProductNode.SetValue("DocumentPublishTo", DateTime.Now.AddDays(-1));

请提供可能的解决方案。在SKUInfo中没有诸如DocumentPublishTo之类的属性,因此我将它与SKUTreeNode一起使用,您可以在代码设置中找到它。

 foreach (DataRow dr in dt.Rows)
        {                
            manufacturer = GetManufacturer(Convert.ToString(dr["MANUFACTURER_NAME"]));
            department = GetDepartment(Convert.ToString(dr["CATEGORY_OF_PRODUCT_1"]));

            var sku = new SKUInfo
            {
                SKUNumber = Convert.ToString(dr["MANUFACTURER_PART_NUMBER"]),
                SKUName = Convert.ToString(dr["MANUFACTURER_PART_NUMBER"]),
                SKUDescription = Convert.ToString(dr["TECHNICAL_SPECIFICATIONS"]).Trim('"'),
                SKUShortDescription = Convert.ToString(dr["SHORT_DESCRIPTION"]).Trim('"'),
                SKUPrice = ValidationHelper.GetDouble(dr["RESELLER_BUY_INC"], 0),
                SKURetailPrice = ValidationHelper.GetDouble(dr["RRP_INC"], 0),
                SKUEnabled = false,
                SKUSiteID = siteId,
                SKUProductType = SKUProductTypeEnum.Product,
                SKUManufacturerID = manufacturer.ManufacturerID,
                SKUDepartmentID = department.DepartmentID,
                SKUHeight = ValidationHelper.GetDouble(dr["HEIGHT"], 0),
                SKUWidth = ValidationHelper.GetDouble(dr["WIDTH"], 0),
                SKUWeight = ValidationHelper.GetDouble(dr["WEIGHT"], 0),
                SKUDepth = ValidationHelper.GetDouble(dr["LENGTH"], 0),
                SKUAvailableItems = 1,
                SKUSellOnlyAvailable = true
            };

            try
            {

                SKUInfo updateProduct = SKUInfoProvider.GetSKUs()
                                .WhereEquals("SKUNumber", sku.SKUNumber)
                                .FirstObject;

                sku.SKUPrice += sku.SKUPrice * 0.015;


                if (updateProduct != null)
                {
                    updateProduct.SKUNumber = sku.SKUNumber; updateProduct.SKUName = sku.SKUName;
                    SKUInfoProvider.SetSKUInfo(updateProduct);
                }

                else
                {
                    SKUInfoProvider.SetSKUInfo(sku);
                }

                if (!sku.SKUEnabled)
                {
                    SKUTreeNode productDoc = (SKUTreeNode)SKUTreeNode.New(productDocumentType.ClassName, tree);
                    if (sku.SKUEnabled == false)
                    {
                        productDoc.DocumentPublishTo = DateTime.Now.AddDays(-1);
                    }

                    productDoc.DocumentSKUName = Convert.ToString(dr["MANUFACTURER_PART_NUMBER"]);
                    productDoc.DocumentSKUDescription = sku.SKUDescription;
                    productDoc.NodeSKUID = sku.SKUID;
                    productDoc.DocumentCulture = cultureCode;
                    productDoc.DocumentName = Convert.ToString(dr["MANUFACTURER_PART_NUMBER"]);

                }
            }                

            catch (Exception ex)
            {
                error += "error";
            }

        }

1 个答案:

答案 0 :(得分:2)

您需要获取SKU的节点,而不是创建新节点。来自documentation

    SKUTreeNode productDoc = (SKUTreeNode)tree.SelectNodes()
        .Path("/Products/NewProduct")
        .OnCurrentSite()
        .CombineWithDefaultCulture()
        .FirstObject;
productDoc.DocumentPublishTo = DateTime.Now.AddDays(-1)