public void EditProductRelationship(ProductRelationship obj)
        {
            var item = productRelationshipRepository.GetById(obj.Id);

            item.IsAvailable     = obj.IsAvailable;
            item.ProductId       = obj.ProductId;
            item.ProductRelateId = obj.ProductRelateId;
            productRelationshipRepository.Update(item);
            SaveProductRelationship();
        }
        /// <summary>
        ///     Allows the REST API to create or update a product relationship
        /// </summary>
        /// <param name="parameters">
        ///     Parameters passed in the URL of the REST API call. If there is a first parameter found in the
        ///     URL, the method will assume it is the product relationship ID (bvin) and that this is an update, otherwise it
        ///     assumes to create a product relationship.
        /// </param>
        /// <param name="querystring">Name/value pairs from the REST API call querystring. This is not used in this method.</param>
        /// <param name="postdata">Serialized (JSON) version of the ProductRelationshipDTO object</param>
        /// <returns>ProductRelationshipDTO - Serialized (JSON) version of the product relationship</returns>
        public override string PostAction(string parameters, NameValueCollection querystring, string postdata)
        {
            var  data = string.Empty;
            var  ids  = FirstParameter(parameters);
            long id   = 0;

            long.TryParse(ids, out id);

            var response = new ApiResponse <ProductRelationshipDTO>();

            ProductRelationshipDTO postedItem = null;

            try
            {
                postedItem = Json.ObjectFromJson <ProductRelationshipDTO>(postdata);
            }
            catch (Exception ex)
            {
                response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                return(Json.ObjectToJson(response));
            }

            var item = new ProductRelationship();

            item.FromDto(postedItem);

            if (id < 1)
            {
                if (HccApp.CatalogServices.ProductRelationships.Create(item))
                {
                    id = item.Id;
                }
            }
            else
            {
                HccApp.CatalogServices.ProductRelationships.Update(item);
            }

            var resultItem = HccApp.CatalogServices.ProductRelationships.Find(id);

            if (resultItem != null)
            {
                response.Content = resultItem.ToDto();
            }

            data = Json.ObjectToJson(response);
            return(data);
        }
Exemple #3
0
        private string RenderSingleItem(ProductRelationship r)
        {
            StringBuilder sb = new StringBuilder();

            string  name = r.RelatedProductId;
            Product p    = MTApp.CatalogServices.Products.Find(r.RelatedProductId);

            if (p != null)
            {
                name = p.Sku + "<br />" + p.ProductName;
            }

            string imageUrl = MerchantTribe.Commerce.Storage.DiskStorage.ProductImageUrlSmall(MTApp, p.Bvin, p.ImageFileSmall, true);

            sb.Append("<div class=\"dragitem\" id=\"item" + r.RelatedProductId.ToString() + "\"><table class=\"formtable\" width=\"100%\"><tr>");
            sb.Append("<td width=\"60\" class=\"imgfield\">");
            sb.Append("<img width=\"50\" src=\"" + imageUrl + "\" border=\"0\" alt=\"" + p.ImageFileSmallAlternateText + "\" /></td>");

            sb.Append("<td class=\"namefield\" style=\"line-height:1.5em;\">");
            sb.Append(name);
            sb.Append("</td>");

            sb.Append("<td width=\"75\" class=\"substitutefield\">");
            if (r.IsSubstitute)
            {
                sb.Append("SUB");
            }
            else
            {
                sb.Append("&nbsp;");
            }
            sb.Append("</td>");

            // Disable Editing for Now
            //sb.Append("<td width=\"75\"><a href=\"#\" class=\"dragitemedit\" id=\"edit" + r.RelatedProductId.ToString() + "\"><img src=\"../images/buttons/edit.png\" alt=\"edit\" /></a></td>");


            sb.Append("<td width=\"30\"><a href=\"#\" class=\"trash\" id=\"rem" + r.RelatedProductId.ToString() + "\"><img src=\"../../images/system/trashcan.png\" alt=\"Delete\" /></a></td>");
            sb.Append("<td width=\"30\"><a href=\"#\" class=\"handle\"><img src=\"../../images/system/draghandle.png\" alt=\"Move\" /></a></td>");
            sb.Append("</tr></table></div>");

            return(sb.ToString());
        }
 public void CreateProductRelationship(ProductRelationship obj)
 {
     productRelationshipRepository.Add(obj);
     SaveProductRelationship();
 }
Exemple #5
0
        public ActionResult Create(ProductFormModel newProduct, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                //Mapping to domain
                Product product = Mapper.Map <ProductFormModel, Product>(newProduct);
                if (String.IsNullOrEmpty(product.Slug))
                {
                    product.Slug = StringConvert.ConvertShortName(product.Name);
                }

                //Create Product
                _productService.CreateProduct(product);

                //Add ProductAttribute after product created
                //product.ProductAttributeMappings = new Collection<ProductAttributeMapping>();
                //var listAttributeId = _productAttributeService.GetProductAttributes().Select(p => p.Id);
                //foreach (var id in listAttributeId)
                //{
                //    product.ProductAttributeMappings.Add(
                //        new ProductAttributeMapping() { ProductAttributeId = id, ProductId = product.Id });

                //}
                //Add Picture default for Labixa
                product.ProductPictureMappings = new Collection <ProductPictureMapping>();
                for (int i = 0; i < 4; i++)
                {
                    var  newPic = new Picture();
                    bool ismain = i == 0;
                    _pictureService.CreatePicture(newPic);
                    product.ProductPictureMappings.Add(
                        new ProductPictureMapping()
                    {
                        PictureId     = newPic.Id,
                        ProductId     = product.Id,
                        IsMainPicture = ismain,
                        DisplayOrder  = 0,
                    });
                }
                _productService.EditProduct(product);


                //create product relation
                #region
                ProductRelationship item2 = new ProductRelationship();
                for (int i = 0; i < 3; i++)
                {
                    ProductRelationship item = new ProductRelationship();
                    item.ProductId       = product.Id;
                    item.ProductRelateId = product.Id;
                    item.isAvailable     = true;
                    _productRelationShipService.CreateProductRelationship(item);
                }
                #endregion
                //Save all after edit
                return(continueEditing ? RedirectToAction("Edit", "Product", new { productId = product.Id })
                                : RedirectToAction("Index", "Product"));
            }
            else
            {
                var listProductCategory = _productCategoryService.GetProductCategories().ToSelectListItems(-1);
                newProduct.ListProductCategory = listProductCategory;
                return(View("Create", newProduct));
            }
        }