BigCommerce Category Name as a Filter in Handlebars - bigcommerce

My products have custom fields that I set up for the purpose of custom sorting. Some products belong to multiple categories so I create a custom field for each category that the product belongs to. I've been setting the Custom Field Name to the Category Name and the Custom Field Value to the sort order. Now I need to call the appropriate Name and Value onto the category page.
I've tried the following:
{{#filter custom_fields 'category.name' property='name'}}
{{#filter custom_fields category.name property='name'}}
{{#filter custom_fields '{{category.name}}' property='name'}}
{{#filter custom_fields {{category.name}} property='name'}}
Is it possible to use the category name as the custom field name filter? Can you please explain/show how to do this? TYIA

The second one is correct. However, since you are in the context of the product card (each category.products), the category context is lost. You would need to add a ../ (or 2) to go back up a level. For example: {{#filter custom_fields ../category.name property='name'}}.
This still may not work, however. I've run into issues in the past when working in a component and trying to get a parent's context. A simple way to ensure the variable gets passed down appropriately would be to specify it on the line that includes the card component. It will probably be found in the grid.html file, and will look something like: {{>components/products/card settings=../settings show_compare=../show_compare show_rating=../settings.show_product_rating theme_settings=../theme_settings customer=../customer event=../event position=(add #index 1)}}.
Simply add the category name here like so: {{>components/products/card settings=../settings show_compare=../show_compare show_rating=../settings.show_product_rating theme_settings=../theme_settings customer=../customer event=../event position=(add #index 1) category_name=../category.name}}.
Now, you can alter the original filter code to just use the new variable: {{#filter custom_fields category_name property='name'}}.

Related

Get value from customer_entity_varchar - Magento

I created a customer attribute in backend magento, but I want to show this attribute to the user so that he can alter its value in the frontend. My input field is being displayed in the frontend, but the value is not there. I am not able to get this value. I found that the value that I need to display is in the apscustomer_entity_varchar table and the column is called 'value'. How can I get that value from that table? I was trying this:
$collection = Mage::getModel('eav/entity_attribute')->getCollection();
foreach ($collection as $data) {
return $data;
}
but it was not working, so I used SQL code and it worked. However I know that's not a nice way to do that in Magento. What I did was something like:
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql = "SELECT * FROM `apscustomer_entity_varchar ` WHERE `entity_id`='$id'";
$rows = $connection->fetchAll($sql);
How can I get the value column from my apscustomer_entity_varchar table in the magento way, using the getModel?
You need to retrieve the customer of the session and then you can get the attribute you want :
Mage::getSingleton('customer/session')->getData('attributeName');
Mage::getSingleton('customer/session')->getAttributeName(); //Magic getter
Where attributeName is the name of the attribute you want to get the value.
I found out how to do that :D
It's actually very simple. Even if this is a custom customer attribute (created in Magento admin panel), I need to get the attribute not using the 'eav/entity_attribute' model, but using the 'customer/customer' model. So I just need to do that:
$customer_data = Mage::getModel('customer/customer')->load($customer_id)->getData();
echo $customer_data['attributeThatYouWant'];
If you are not sure what is the name of your attribute you can look at Magento Admin Panel under Customer/Manage-Attributes, or you can use that after getting the model:
var_dump($customer_data);
Now you are able to get the name of all customer attributes.

Finding products by Tags (Prestashop)

I'm doing some modifications in the way that customers explore products in Prestashop 1.6. So, I'd like to know if is there a function that works similar to the getProducts() function but gets products from a defined tag (or tags)?
Thanks for your help.
I have looked to product class and I couldn`t find any similar function. You can get product tags, all tags, add tags, del and etc..
But you could write an additional functio, yes? In ps_product_tag table you have: id_product and id_tag so:
1) Find id_tag by product name from ps_tag table
2) Get all products ID from ps_product_tag table where product has assigned ID TAG
Thats it. And also you should do it by overiding Product class. Now you have an array with products id. So now you can use cycle and catch all infformation from products or whatever: $product = new Product($id_product);

Is there a way to apply a filter to a treestore that includes a property that does not exist on one of the models specified?

I am trying to populate a treegrid with user stories and defects, but one of the parameters that I would like to use in the filter is a property that does not exist on the defect model.
If the filter includes that property, no results are returned. Is there a workaround or special filter definition?
The treegrid/treestore request data from the artifact wsapi endpoint. There is a hidden queryable field called TypeDefOid that you can use to limit a filter to a specific type, like so:
((TypeDefOid != <defectTypeDefOid>) OR ((TypeDefOid = <defectTypeDefOid>) AND (DefectField = "value")))
You can obtain the defectTypeDefOid from the model once the treestore is built:
var defectTypeDefOid = treeStoreModel.getArtifactComponentModel('Defect').typeDefOid;
You can see a good example of this in action in the IterationTrackingBoardApp here:
https://github.com/RallyApps/app-catalog/blob/master/src/apps/iterationtrackingboard/IterationTrackingBoardApp.js#L227
That example is for story, but very similar. Just below that in the code is also a more complicated defect specific filter as another example.

sitecore mvc value of droplink

I am looking for the simplest way to get the referenced item value for a droplink field.
#Html.Sitecore().Field("Alignment")
I want to get the value of the choice, what's the best approach?
If you need to have ability to edit fields of alignment item which is chosen in 'Alignment' droplink field of context item or just show values of alignment item's fields for visitors:
#{
Sitecore.Data.Fields.ReferenceField alignmentField = Sitecore.Context.Item.Fields["Alignment"];
Sitecore.Data.Items.Item alignmentItem = alignmentField.TargetItem;
}
<div>
#Html.Sitecore().Field("Text of Alignment", alignmentItem)
</div>
This example assumes that Alignment template contains 'Text of Alignment' field.
The Droplink field stores the referenced item's ID. To retrieve this ID (providing the field is present in your current item/model):
((LinkField)Model.Item.Fields["Alignment"]).Value
To output the referenced item's name, you could do something like this:
#(Model.Item.Database.GetItem(((LinkField)Model.Item.Fields["Alignment"]).Value).Name)
But that's really ugly. The preferred approach would be to create an extension method encapsulating some of the above so you're not having to re-type that out :D
The article Extending the SitecoreHelper Class by John West shows how to extend the SitecoreHelper class to add custom field renderers, so you could end up creating a neat re-usable snippet like:
#(Html.Sitecore().ReferenceField("Alignment","Name"))
If this is in a partial view i.e. .cshtml file you can also use something like below:
Sitecore.Data.Fields.TextField alignment= Model.Item.Fields["Alignment"];
This will give you the id of the set item in the drop link , then from that id can retrieve it from the database like:
#if (!string.IsNullOrWhiteSpace(alignment.Value))
{
var setAlignment = Sitecore.Context.Database.GetItem(alignment.Value);
if (setAlignment != null && !string.IsNullOrWhiteSpace(setAlignment.Name))
{
setAlignment.Name
}
}
Personally i prefer this way as i can check if the droplink is set before trying to use the value.

Use Instance method instead of Database field while accessing in Rails

I have database field called name. And i have used user.name in my application. Now I have something like salutation which i wanted to append with the name. So what i basically want is when i am accessing name via user.name it should fetch the value from instance method rather then database field.
def name_with_salutation
"#{salutation} #{name}"
end
So when i am accessing name via user.name it should respond with user.name_with_salutation. I have tried alias_method but it shows stack level too deep because name is getting used in name_with_salutation so it got stuck in infinite process.
I am trying this because i do not want to replace name with name_with_salutation throughout the application. This should not apply when i am assigning values user.name = "abc".
Please let me know, How this will be done.
To overwrite an original Model method, you can write a method with same name, and then use read_attribute(:attr) to represent the original attribute value.
Given name attribute exist, to overwrite #name:
def name
"#{salutation} #{read_attribute(:name)}"
end