Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm doing import products to Merchello but can't set the quantity of products, here's what I did:
var warehouse = MerchelloContext.Current.Services.WarehouseService.GetDefaultWarehouse(); var catalog = warehouse.WarehouseCatalogs.FirstOrDefault(); if (product.Shippable) { product.AddToCatalogInventory(catalog); MerchelloContext.Current.Services.ProductService.Save(product); product.TrackInventory = true; product.CatalogInventories.First().Count = 100; MerchelloContext.Current.Services.ProductService.Save(product); }
Could you help to tell what's wrong here?
Thanks,
Nick
Hi Nick,
I'm not sure what's wrong, but it could be the save after the addtocataloginventory.
Here's some code of mine (it is the productvariant, but should work the same).
var productVariant = merchelloServices.ProductVariantService.GetBySku(productId); if (productVariant == null) { productVariant = merchelloServices.ProductVariantService.CreateProductVariantWithKey(masterProduct, description, productId, price, attributes); productVariant.AddToCatalogInventory(catalog); var inventory = productVariant.CatalogInventories.First(); if (inventory != null) { inventory.Count = 100; merchelloServices.ProductVariantService.Save(productVariant); } } productVariant.SalePrice = masterProduct.SalePrice; productVariant.OnSale = masterProduct.OnSale; productVariant.Shippable = true; productVariant.Taxable = true; productVariant.TrackInventory = true; productVariant.Available = true; productVariant.OutOfStockPurchase = true; merchelloServices.ProductVariantService.Save(productVariant);
Hope this helps :)
//Puck
Thanks @Puck, save after the addtocataloginventory works for me :)
Good to hear!
If you can mark my reply as the solution, others can benefit from this also :)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
How to set product quantity programtically
I'm doing import products to Merchello but can't set the quantity of products, here's what I did:
Could you help to tell what's wrong here?
Thanks,
Nick
Hi Nick,
I'm not sure what's wrong, but it could be the save after the addtocataloginventory.
Here's some code of mine (it is the productvariant, but should work the same).
Hope this helps :)
//Puck
Thanks @Puck, save after the addtocataloginventory works for me :)
Good to hear!
If you can mark my reply as the solution, others can benefit from this also :)
//Puck
is working on a reply...