Magento: Attribute always returns default value in catalog view, works fine in product view - attributes

I've created a new Yes/No attribute for products. I've extended the Product model to do some custom logic and the custom functions are working everywhere.
When I initially tried getting the custom attribute value, I ran into some issue. Magento wasn't loading it for me, so calls to $product->getMyAttributeName() did nothing. In the product views, I got it working with this additional function:
public function getAttrVal($attr_name)
{
return $this->getResource()->getAttribute($attr_name)->getFrontend()->getValue($this);
}
So that worked great when viewing a product on the frontend. It would fetch the assigned value if set, or the default if not.
When I view any Category (grid of all products in that category), the same exact code is being executed. But my getAttrVal() function always returns the default value, even if I've explicitly set this value for my product.
I can't, for the life of me, figure out why the attribute loads correctly in the Product view but the Category view always grabs the default value, despite running the same exact code. Any thoughts?

Because Magento uses an EAV model for its extensible catalog attributes, not every attribute may be carried over onto every page. Try fiddling with the "displayed in catalog" and other related variables on the attribute, and it may fix your problem. If not, say so and we can try other things.
Hope that helps!
Thanks,
Joe

Related

Segmented Keys in ACUMATICA

I’ve created new Segmented Keys in ACUMATICA for use in a specific module. I would like to assign the Dimension name dynamically but I noticed it works only with hard code or name like [PXDimension(“VENDOR”)]
Also, I have some limitation to create an IF Conditional inside the customized field… it does not recognize the IF clause (see the image).
I would appreciate any suggestion how to solve this issue.
I haven't seen how your original attempt at PXDimension looked, but I'm going to take a guess and assume you tried to reference a new custom field contained in a setup table, something like:
[PXDimension(typeof(XXMySetup.usrMyCustomField))]
If that's indeed what you tried to do, one very important thing to do is to ensure that you have a view for your table in your graph, otherwise the attribute will not find the table and record in your cache. For instance:
public PXSetup<XXMySetup> XXMySetup;
Without this view declared in the graph, the dimension attribute will not work as expected. It would be nice if a clear exception was thrown in this case - I made the same mistake recently and it would have been helpful.

Backoffice : ClassificationAttributeValue visibility issue

Hybris 6.3.0.2
In ClassAttributeAssignment, user can changed the type to valueList so that he can show a pre-defined list of ClassificationAttributeValues in dropdown in product attribute tab for classificationAttribute.
Problem : The problem is very weird, as for some of classification attribute, value is not showing even though we are setting type as valuelist/enum and giving some classificationAttributeValues to feature descriptor values. Only na is showing, nothing else.
The whole pattern is random, for some of classification attribute, its working, for some of classification attribute, its not working. We are not able to identify why its happening because we match those attributes as well with one which is working with another which is not working. Both having same configuration but one of them its not showing.
In HMC, values are coming for all, but in Backoffice only its giving problem.
Can someone please guide us to fix this issue.
The problem seems to be in FeatureEditor in the below line.
ClassificationAttributeModel attribute = assignment.getClassificationAttribute();
ClassificationClassModel cclass = (ClassificationClassModel)attribute.getClasses().iterator().next();
We extend FeatureEditor to override method and fetched ClassificationClassModel from ClassAttributeAssignmentModel instead of ClassificationAttributeModel .

How does my MVC5 controller find a View?

I was checking through the code on our project, and found an Action method in our code without a view. CustomForms.Index didn't have a matching View, but when I run the code, up comes the view listing the appropriate records.
I'm happy that we don't get an error. But I'm curious how to figure out what View it is using.
By convention, Razor searches for views in the following paths, in order:
~/Areas/{AreaName}/Views/{ControllerName}/{ActionName}.cshtml
~/Areas/{AreaName}/Views/Shared/{ActionName}.cshtml
~/Views/{ControllerName}/{ActionName}.cshtml
~/Views/Shared/{ActionName}.cshtml
Obviously, if you're not utilizing areas, the first two don't apply. Additionally, the view can be explicitly given, by passing a string to the return View call:
return View("Foo");
Would look for a view name Foo.cshtml in all of the above locations, instead of the action name.

SPServices GetListItems returning field values as "undefined"

I ran across a problem for which I found no documented solution, but inadvertently found the solution myself. So I wanted to document this here for others who may encounter the same problem.
I was using a CAML query within SPServices to retrieve list items, then referencing "ows_{fieldname}" as usual to retrieve the field value for each list item. The field value was reported as "undefined" for all items. I quintuple-checked that I was specifying the proper name of the field and that my query was properly constructed.
I eventually discovered that the fields I was trying to reference were not displayed in the default view of the list. As soon as I changed the list properties to include the fields in the default view, the proper field values were returned within my javascript.
I don't know how much of Sharepoint's underpinnings work, but I was very surprised at my finding because it implies that the SPServices GetListItems method gets its data from the list's default view, not the actual underlying list. I realize I could be wrong in this interpretation, but I imagine others could run into this same problem.
The default, although unreliable, way GetListItems works is that it's suppose to returns all fields displayed on the default list view if you don't specify ViewFields on input. This is unreliable. Although you got it working - now - someone could come along later and change the default view thus breaking your sweet customization. Bummer. :)
I suggest always listing the ViewFields you are interested in on the GetListItems method. This ensures that your will get them if they are set. That's right. You could still get rows with an undefined field. This happens mostly on fields of type Lookup that are not set on a row.
Hope this helps you understand what is going on. Over the years I have created my own wrappers around SPServices to ensure I get back a reference to all fields requested, even if they are not in the response by Sharepoint.
When using SPServices' GetListItems method, be sure that any fields that you reference from the list are included in the list's default view, otherwise an undefined value will be returned.

Siebel read only field problem

I'm trying to make a field read only when a given value is selected from a PickList.
I'm using a flag that is set to Y when the list has that value, and N otherwise.
I created a Business Component User Prop with the name Field Read Only Field: MyField set to the flag.
Thing is, this works with the vanilla component but it wont work on my custom component.
I can't figure out what is going on, the properties of the fields and flag are exactly the same. It should work...
Thanks for any help you can give me.
That user property is only supported on the business component class CSSBCBase and its subclasses. My guess is that you probably used CSSBusComp as the class of your business component. CSSBusComp is actually a superclass of CSSBCBase, and is very minimal and does not support Field Read Only Field. If that's the case, change it to CSSBCBase and you should be good to go.
Other option is that- if the record become read-only when the picklist value is being selected- that you'll need to make the picklist field Immediate Post Changes to be sure the user property is triggered.

Resources