Find SKUInfo by Product Number or Custom Property

Jan Peek asked on March 5, 2015 22:15

I need to grab the SKUInfo for a product in the Kentico Store (using v7) but all I have to search for it is either its Product Number or the value of a Custom Property.

I know I'm able to get it via a SKUID or SKUGUID but I don't have those available for my purposes.

Any suggestions how I can retrieve the product's info (name, description, image)?

Thanks

Recent Answers


Reza Zareian Fard answered on March 5, 2015 22:53 (last edited on March 5, 2015 22:53)

If you are using Kentico 8.x you can easily use SKUInfoProvider.GetSKUs().where (your condition) as Kentico 8.x uses DataQuery

0 votesVote for this answer Mark as a Correct answer

Jan Peek answered on March 5, 2015 22:54

We're still using Kentico 7, will that work there as well?

Also would be the DataQuery part look like?

Thanks

0 votesVote for this answer Mark as a Correct answer

Reza Zareian Fard answered on March 6, 2015 00:25

It is not available in Kentico 7 as it is part of improvement in Kentico 8. In Kentico 7 you would get the node first and find the NodeSKUID or get the document and cast it to SKUTreeNode

SKUTreeNode skuNode = CurrentDocument as SKUTreeNode;
if( skuNode != null ) {
skuNode.SKU.SKUID; 
}

and then get the SKUInfoObject using SKUInfoProvider.

Also you can right your custom query and fetch the data you need.

1 votesVote for this answer Mark as a Correct answer

Paul Bruniges answered on August 5, 2015 12:34

Hi Reza Zareian Fard

I'm using Kentico 8, and trying to get the SKUID from the SKUNumber

var skus = SKUInfoProvider.GetSKUs() .Where("SKUNumber", QueryOperator.Equals, SKUNumber);

Can I get the SKUID from this?

Thanks Paul

0 votesVote for this answer Mark as a Correct answer

Josef Dvorak answered on August 31, 2015 15:33

Hi Paul,

The method you are using can return more than one result, so you will need to foreach through the ObjectQuery set:

foreach (var sku in skus)
{
    int skuID = sku.SKUID;
    ...
}

Or modify the result to return the first match:

var sku = SKUInfoProvider.GetSKUs().Where("SKUNumber", QueryOperator.Equals, SKUNumber).FirstResult().FirstObject;
int skuID = sku.SKUID;
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.