Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 1243 posts 3708 karma points admin c-trib
    Jul 06, 2018 @ 15:10
    Dan
    0

    Merchello stock level not adjusting after purchases

    Hi,

    I don't know if I'm missing something, but I have a Merchello 2.5.0 implementation in which we're selling tickets to events. The 'variant is shippable' checkbox on the products is NOT checked as there is no shipping element to the orders. The 'this variant has digital goods' is also NOT checked as the event tickets aren't downloads, they're handled by administrators. If we set an amount of stock on each product, that number does not change even after one of those products has been purchased via either Braintree or as a cash/invoice payment.

    The Braintree orders are marked as Paid and Fulfilled in the Merchello admin area as soon as the purchase is completed, so this is when I'd expect the stock to be reduced. For invoice payments I'd expect stock to be reduced either when the order is placed or when the order is marked as paid via the Merchello admin interface, but neither happens. Nothing seems to effect the stock level.

    Can anyone suggest what to do, as this is a pretty big show-stopper at the moment? Perhaps I've missed a setting somewhere?

    Thanks

  • Puck Holshuijsen 83 posts 323 karma points
    Mar 01, 2019 @ 08:39
    Puck Holshuijsen
    0

    I am experiencing the same issue (also same merchello version). Did you find the solution to this problem?

  • Puck Holshuijsen 83 posts 323 karma points
    Mar 12, 2019 @ 09:11
    Puck Holshuijsen
    0

    I actually fixed it myself. Here's my solution on how I fixed it in my situation.

    Inside the controller where I am handling my order finalizing I added this code:

        //     Get all the productkeys from the invoice
        List<Guid> listProductKeys = invoice.Items.Where(i => i.LineItemType == LineItemType.Product).Select(p => p.ExtendedData.GetProductKey()).Distinct().ToList();
                            if (listProductKeys.Any()) {
    //go through each productkey
                                foreach (Guid pk in listProductKeys) {
    //sum the ordered quantity for that productkey
                                    int qty = invoice.Items.Where(i => i.LineItemType == LineItemType.Product && i.ExtendedData.GetProductKey() == pk).Sum(p => p.Quantity);
    //get the product
                                    var product = _merchelloContext.Services.ProductService.GetByKey(pk);
                                    var inventory = product.CatalogInventories.First();
    //get the inventory
                                    if (inventory != null) {
    //subtract the ordered quantity
                                        inventory.Count = inventory.Count - qty;
    //save the product
    _merchelloContext.Services.ProductService.Save(product);
                                    }
                                }
                            }
    

    I hope anyone can use this

Please Sign in or register to post replies

Write your reply to:

Draft