Copied to clipboard

Flag this post as spam?

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


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Matt Nolan 45 posts 65 karma points
    May 11, 2012 @ 11:12
    Matt Nolan
    0

    Delete products from code

    Hi,

    How can I delete a product from code?
    When I call .Delete() on the product i get the following error

    deleted object would be re-saved by cascade (remove deleted object from associations)[UCommerce.EntitiesV2.Product#4466]

    Thanks,

    Matt

  • Søren Spelling Lund 1797 posts 2786 karma points
    May 14, 2012 @ 09:01
    Søren Spelling Lund
    0

    Hi Matt,

    This is caused when the product is loaded into memory and associated with a child collection of another object. For products this is typically caused by category or product relationships such a related products or variants.

    I need to know more about the code to be more specific.

  • Matt Nolan 45 posts 65 karma points
    May 14, 2012 @ 10:45
    Matt Nolan
    0

    Hi Soren,

    Basically, I'm trying to override the delete variant button on the EditProductVariants page so that i can check if the variant has been purchased and only allow it to be deleted if it hasn't.

    I've gotten passed the error above but i still can't actually delete the variants. Below is the code i'm using, the product appears to be deleted but is still in the db and returns when i refresh the product

    this.View.Product.Variants.Remove(_product);
    UCommerce.EntitiesV2.Product.Delete(p => p == _product);
    this.Variants = this.View.Product.Variants;
    this.Variants.Add(new UCommerce.EntitiesV2.Product() { ProductDefinition = this.View.Product.ProductDefinition });
    this.DataBind();

    Thanks,

    Matt 

  • Søren Spelling Lund 1797 posts 2786 karma points
    May 14, 2012 @ 11:38
    Søren Spelling Lund
    0

    Try this instead:

    Product.Variants.Remove(_product);
    Product.Save();

    The save method will cascade deletes for you.

  • Matt Nolan 45 posts 65 karma points
    May 14, 2012 @ 12:18
    Matt Nolan
    0

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft