Developer forum

Forum » Development » getAllProducts() and getProductBySQL() does not work!!! :S

getAllProducts() and getProductBySQL() does not work!!! :S

Vilius Janulis
Reply
 Hi i have this kind of code, that worked in ten custom modules before but does not work now, what could be wrong ?
 It is simple code, and as in below example shown, i have tried few different ways to do that, non of them worked ! Any ideas ?
And there are products , i have tried to import them, to create manually still i can not get at least one a printed.... That means no products in product collection

   Dynamicweb.eCommerce.Products.ProductCollection productCollection = Dynamicweb.eCommerce.Products.Product.getAllProducts();
//.getProductBySQL("SELECT * FROM EcomProducts WHERE ProductID <> ''");
// getAllProducts();

            foreach (Product checkExistsProduct in productCollection)
            {
             
                    importStuff.AppendLine("a");
             
            }


Thank you.

Replies

 
Morten Snedker
Reply
This post has been marked as an answer
 Hi Vilius,

I'm not aware of the context in which you have the code you've provided. The example below will response.write the product name of all products whenever showing a product (hence inheriting from ProductTemplateExtender):

using Dynamicweb;
using Dynamicweb.eCommerce.Products;

namespace Extensibility
{
    public class myProductTemplateExtender : ProductTemplateExtender
    {
        public override void ExtendTemplate(Dynamicweb.Templatev2.Template Template)
        {
            ProductCollection pc = Product.getAllProducts();
            foreach (Product p in pc)
            {
                Base.w(p.Name);                
            }
        }
    }
}
- and this example works. If you still can't get it to work, please elaborate on the context in which your code is being executed.


Regards
Morten Snedker
Votes for this answer: 0
 
Bo Møller
Reply
 Hey Morten,

We fixed the error by updating Dynamicweb to the newest version on engage. It seems this was a bug in the version the site was running.
Thanks for the reply though!

 

You must be logged in to post in the forum