Just wondering if any one else has had issues with deleteing products from ucommerce. I have tried 2 methods and neither seem to delete the records from the database.
Method 1.
//[uCommerce_CategoryProductRelation]
ProductRelation.Delete( x => x.Product == product );
//[uCommerce_PriceGroupPrice]
PriceGroupPrice.Delete( x => x.Product == product );
//[uCommerce_ProductDescription]
ProductDescription.Find( x => x.Product == product );
//[uCommerce_ProductProperty]
ProductProperty.Delete( x => x.Product == product );
//[uCommerce_ProductRelation]
ProductRelation.Delete( x => x.RelatedProduct == product || x.Product == product );
//[uCommerce_ProductReviewComment]
foreach( var review in product.ProductReviews ) {
ProductReviewComment.Delete( x => x.ProductReview == review );
}
//[uCommerce_ProductReview]
ProductReview.Delete( x => x.Product == product );
product.Delete();
Method 2
//[uCommerce_CategoryProductRelation]
ProductRelation.Find( x => x.Product == product ).ForEach( d => d.Delete() );
//[uCommerce_PriceGroupPrice]
PriceGroupPrice.Find( x => x.Product == product ).ForEach( d => d.Delete() ); ;
//[uCommerce_ProductDescription]
ProductDescription.Find( x => x.Product == product ).ForEach( d => d.Delete() ); ;
//[uCommerce_ProductProperty]
ProductProperty.Find( x => x.Product == product ).ForEach( d => d.Delete() ); ;
//[uCommerce_ProductRelation]
ProductRelation.Find( x => x.RelatedProduct == product || x.Product == product ).ForEach( d => d.Delete() ); ;
//[uCommerce_ProductReviewComment]
foreach( var review in product.ProductReviews ) {
ProductReviewComment.Find( x => x.ProductReview == review ).ForEach( d => d.Delete() ); ;
}
//[uCommerce_ProductReview]
ProductReview.Find( x => x.Product == product ).ForEach( d => d.Delete() ); ;
product.Delete();
Going by documentation from uCommerce I should be able to just call
and it will delete all related records(also showing the same error)
When you delete an object which has relationships with other objects using the default API uCommerce will handle removing or updating the related objects, e.g. PurchaseOrder.Delete() also deletes associated order lines, customer, addresses, etc..
However
i am getting back
deleted object would be re-saved by cascade (remove deleted object from associations)
ok so i have run this to the most basic i can get it.
Product.Delete( x => x.ProductId == 180 ); Product.Delete( x => x.ProductId == 181 );
this fails on first pass. Same exception as thrown above. but if i try and delete it again than we have success. Is there any access to the context so I can Delete all Product Associations and then fire the context off to delete the Product itself.
Solution
As it turns out someone me needs to RTFM. I was trying to delete everything that was associated to the product as, mistakenly, I thought uCommrece wouldn't be smart enough to do that for me. The errors were coming from the context trying to delete something that I had already tried to delete. All you need to do is:
Product.Delete( x => x.ProductId == product_Id_To_Delete );
Delete a Product
hey all.
Just wondering if any one else has had issues with deleteing products from ucommerce. I have tried 2 methods and neither seem to delete the records from the database.
Method 1.
Method 2
Going by documentation from uCommerce I should be able to just call
and it will delete all related records(also showing the same error)
However
i am getting back
any help would be appreciated.
Which version of uCommerce are you using?
Could you try this piece of code:
var product = Product.Get(someProductId);
product.Delete();
version: uCommerce 2.6.1.0
The Product that is comming back is a legit product. It deletes all the associated properties for the product just falls over on the product itself.
ok so i have run this to the most basic i can get it.
this fails on first pass. Same exception as thrown above. but if i try and delete it again than we have success. Is there any access to the context so I can Delete all Product Associations and then fire the context off to delete the Product itself.
Solution
As it turns out someone me needs to RTFM. I was trying to delete everything that was associated to the product as, mistakenly, I thought uCommrece wouldn't be smart enough to do that for me. The errors were coming from the context trying to delete something that I had already tried to delete. All you need to do is:
KJ
Beautiful isn't it :)
To clarify: Just delete to top-most level. uCommerce will cascade the the delete to any child objects like variants, relations, etc.
So for a structure like this:
Product (id = 1)
Variant (id = 20)
Variant (id = 30)
Just go:
This will delete Variants 20 and 30 too along with anything else associated with the product.
is working on a reply...