For every ProductSpecificationAttribute in OrderItems

Posted: September 13, 2019 at 5:03 PM Quote #246308
Hello!  What if I need to iterate throught every ProductSpecificationAttribute in an order?  The following code fails because OrderItem does not have GetEnumerator.


foreach (OrderItem item in order.OrderItems)
            {
                foreach (ProductSpecificationAttribute spec in item)
                {

                }
            }


Thanks!

Jeremy
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: September 14, 2019 at 2:33 AM Quote #246320
Hi Jeremy,

You can iterate through an enumerator but, order item isn't enumerator. Besides that, ProductSpecificationAttribute collection is a member of the product entity class, not order item. So, your code should look like this:

foreach (OrderItem item in order.OrderItems)
{
    foreach (ProductSpecificationAttribute spec in item.Product.ProductSpecificationAttributes)
    {

    }
}
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
ResanehLab, Digital Agency
E-commerce solutions
nopCommerec solution partner
-------------------------------
Website: resanehlab.com/en
Posted: September 17, 2019 at 3:07 PM Quote #246532
resanehlab wrote:
Hi Jeremy,

You can iterate through an enumerator but, order item isn't enumerator. Besides that, ProductSpecificationAttribute collection is a member of the product entity class, not order item. So, your code should look like this:

foreach (OrderItem item in order.OrderItems)
{
    foreach (ProductSpecificationAttribute spec in item.Product.ProductSpecificationAttributes)
    {

    }
}


resanehlab, that works perfectly.  Thanks for the clarity.

Have an excellent day!

Jeremy
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.