E-Commerce Product Custom Field Kentico 10 - kentico

I am using E-commerce module of Kentico portal and it has two fields for Products pricing : SKUPrice and SKURetailPrice.
I needed one more field to show sell price and I added a new field in Modules application of the portal.(Modules->E-Commerce->Classes->SKU->Fields->New Field)
Now, I need to access this field in my code,but SKUInfo class doesn't show me the newly added field.What I need to do so that the newly added field reflects in my project code ?
I have already build the entire solution multiple times.Any other solutions please.

You can use GetValue and SetValue methods for such fields like this:
SKUInfo sku = ...;
string a = sku.GetValue("field").ToString();
sku.SetValue("field", "value");

JanH has the answer for custom fields you set, also keep in mind though that there is a "SKUCustomData" for other information that you want to store. It takes a Name-Value pair dictionary if memory serves me correctly, and useful if you need to store configuration information or other things that won't be located on the normal SKU table.

Related

Kentico 12 Azure Search

I'm trying to implement Azure Search on Kentico 12. Following the article below.
https://docs.kentico.com/k12/configuring-kentico/setting-up-search-on-your-website/using-azure-search/integrating-azure-search-into-pages
However, I have multiple indexes defined on the smart search not just a single index code name that I can hard code and also cannot aford to hard code index fields. Is there any tutorial out there that I can follow?
It sounds as if you're referring to building an Azure Search web part, is this correct. If so, make a property in your web part which allows you to select the code name from a list in the database. Secondly, regarding field names, you should be using generic field names like DocumentName, NodeAliaspath, etc. Although if you have very specific search results that need to be displayed, simply put in a switch statement to get the field names based on a class name.

Liferay 7 - Get Dynamic Attributes from DDLRecord in Freemarker

How can I get the dynamic attributes from a DDLRecord inside an Application Display Template (ADT) that has an Asset Publisher type using Freemarker?
As far as I know, I don’t have any other choice that doesn’t involve an Asset Publisher ADT, since I use the filters provided by the Asset Publisher. In case you need context, my Dynamic Data List (DDL) has a date attribute and I need to show the record from the latest date.
It is totally possible to get dynamic attributes from the asset publisher. However, you can also display your DDL inside a portlet where you can customize your display.
To do this you would need to know the unique id of the DDL (this can be gotten from your liferay admin interface) and the you can elicit the attributes and then order your list as is appropriate for you.
Check out this example
https://github.com/Temire/Getting-DDL-Attribute-Dynamically/blob/master/GetDDLAttributejava

Reusing a custom ContentPart in the same ContentType

I'm trying to figure out the best way to handle a requirement I have for an Orchard module I'm building.
I have a ContentPart that has a few fields. One field is a ContentPicker that allows for multiple items to be associated to the part. The rest are descriptive information.
The issue I have is that I actually need to be able to include more than one of this ContentPart into a ContentType. I need to create a ContentType that has exactly 3 of this part.
Should I be making this into a field instead of a part? Is it even possible to have a ContentField that has other fields in it?
Or, should I somehow use all the same models and data structures, but somehow define it as 3 distinct parts?
Just wondering what the best practice to do something like this would be.
You can only have one part of each kind on a given type. You can't have fields that have other fields in it (instead - take an existing field and extend it with custom stuff).
As I understand, the actual problem is "how to make groups of fields with some metadata for each group", right? If so, there are a few approaches to solve the problem:
Create a custom field based on Content Picker (basically - take existing Content Picker and extend it with your metadata) and use this without the need for a separate part
Create one part to hold only the metadata for each field attached to it and attach 1 or more fields to it
Create 3 distinct parts. Parts should be thought of as extensions that add some unique features to an item. If you think it's logically ok to have 3 parts then go for it.

Orchard CMS contentfields vs class properties

When should one use Fields from the CMS and when to use class properties and database fields?
My scenario:
Created a product content part with fields usage (text) and price (double). Then I have created a contenttype product and added the part.
I could also have created a product record in models and added a product table. And a part with driver etc.
At first glance I dont see difference besides option 2 requiring programming.
However I did encounter a problem:
In option 2 I could use repository and create a lot of items programmatically.
In option 1 I could create product content items but was not able to fill in the fields of the product part (no errors, but fields remained empty)
So when to use option 1 and when option 2?
And is my problem with option 1 related to that option?
EDIT: Clarifiation of problem with option 1
I have created a productpart. To the productpart I have added the field price which is a decimal and I have added a field Usage of product which is a text field.
In the code I have the following:
dynamic item = _cm.New("Product");
item.TitlePart.Title = "Mijn dummy product";
item.BodyPart.Text = "Some dummy text for this product";
item.ProductPart.Price.Value = new decimal(20.5);
item.ProductPart.Usage.Value = "Some dummy usage of this product";
_cm.Create(item);
After running the code, the product is created with the correct title and body text, but Usage and Price come up emtpy.
I also tried it with the item.As<> method. But that does not compile to As since I have not created an object with that name.
A difference is that fields can only be queried against with projections but more generally parts and fields are for different usage: parts are meant to be reusable, not fields. Price for example is going to be a characteristic of any product so it should probably be a part property. Usage, I don't know, it sounds fairly specific to what you're doing and may be better done as a field.
As for your problems with option 1, it's hard to say without seeing your code but chances are you're doing it wrong.
Apparently the item has to be created first before accessing the contentpart and fields. At least it worked for me.
Please verify if my analysis is correct. If so I will mark it an answer, as well as the answer of Bertrand.
The code now looks like this:
var item = _cm.New("Product");
item.As<TitlePart>().Title = "Mijn dummy product";
item.As<BodyPart>().Text = "Some dummy text for this product";
//Create first before accessing the contentparts that are dynamic.
_cm.Create(item);
//And then access the product via dynamic object.
dynamic dyn = item;
item.ProductPart.Price.Value = new decimal(20.5);
item.ProductPart.Usage.Value = "Some dummy usage of this product";

Sharepoint Extenal List and Custom Field Types

I have an odd issue.
I have client that wants a sharepoint list what is populated from a WCFService. That part is working quite well.
I have a bdcmodel that is mapping the WCF data and I can create an external list from the bdcmodel as well so that is working fine.
The issue I have is that one of the properties in the model is actually a collection of entities called Attributes. The objects in this collection simply have 2 properties Name and Value so really they are just a key value pair.
The client wants to see the list of attributes of the parent entity in the external list. So there would be an Attributes column and within that column would be the list of attributes for each parent object.
Is there even a way to do this? I am looking into Custom Field Types, but it seems like these are really intended to be singular values.
How would I create a list within and external list?
Any help anyone can give would be great even if its just to tell me that there really isn't a stable way to do this so I can go back to the client and tell them we will need to build a custom list to support this because the OOB external list and custom fields and custom field types won't support this kind of nested listing.
I decided to set up the custom field as a string and when I get my collection in from the BdcModel I am serializing it to JSON and then passing it to the field. When the field is viewed in display, edit or new I have overridden the FieldRenderingControl and I am tiling the collection out that way.

Resources