26
votes
Magento 2: Set Custom product attribute value programmatically on product save
Official method should work, but Not
The official method setCustomAttribute($attributeCode, $attributeValue) below should work but NOT because the official bug https://github.com/magento/magento2/...
25
votes
Accepted
Magento 2: How to display custom attribute in catalog?
We can get custom attribute value like below
Attribute Value
<?php /* @escapeNotVerified */ echo $_product->getResource()->getAttribute('c_address')->getFrontend()->getValue($_product)...
20
votes
Magento2 REST Update custom attributes
To create product, we can use:
POST: /V1/products
For updating:
PUT: /V1/products/{sku}
In your case, your code should be:
$productData = [
'attribute_set_id' => 4,
"type_id": ...
17
votes
Accepted
Magento2 How to add row pattern/dynamic rows to the custom product attribute
Here are the high-level things we need to do.
Create Product custom attribute -> Which attribute you want to show the row pattern / dynamic rows
Create di.xml -> Add our custom Data provider ...
16
votes
Accepted
The configuration parameter "formElement" is a required for custom attribute product field
Solution 1: You should delete attribute code dimension in eav_attribute table and recreate use 'input' => 'text' in array. After then, reindex + clear cache.
[
'type' => 'decimal',
'...
16
votes
Accepted
Customer custom attribute not showing in admin form
In contrast to Magento 1, in Magento 2 you now need to add some XML to make custom attributes appear in the edit customer section of the admin.
Create YourNamespace/YourModule/view/base/ui_component/...
14
votes
Magento 2: How to display custom attribute in catalog?
I created an article about this, that have only 5 steps to do it:
1 - Create your attribute in Stores > Attributes > Product.
2 - Set the attribute in the Default group, go to Stores > Attributes > ...
14
votes
Accepted
Magento2 custom attribute for specific product type
Yes , You can create specific attribute for specific product type programmatically.
Below i have created Boolean type of attribute for configurable product only.
You need to pass 'apply_to' ...
14
votes
Magento 2 how to get custom attribute value in cart page and mini cart
Create File catalog_attributes.xml inside Vendor/Module/etc or any existing module.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
11
votes
(Zend_Db_Statement_Exception): SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous
You can achieve this task by below 2 option
Option - 1
You need to change 'created_at' column in
view/adminhtml/ui-component/sales_order_grid.xml
Change column
<column name="created_at" ...
11
votes
Set value to created customer custom attribute in magento 2
This may help for you to save the custom attribute.
protected $_customerRepositoryInterface;
public function __construct(
\Magento\Customer\Api\CustomerRepositoryInterface $...
11
votes
Accepted
Set value to created customer custom attribute in magento 2
Check below code is working great for me. Tested with Magento 2.3.3
$avatar = $this->request->getParam('avatar');
// \Magento\Customer\Model\Customer $customerModel,
...
10
votes
How to add a customer custom-attribute in the customer address edit form?
Custom customer attributes will never just 'appear' on the frontend like they do in the backend. The code that displays them on the frontend is located in a custom phtml file.
Magento EE has this ...
10
votes
Magento 2 : Is there a way to query products using Custom Attributes in Rest API Call?
Resolved the issue by directly using the attribute_code within the search criteria.
https://{domain}/rest/all/V1/products/?searchCriteria[filterGroups][0][filters][0][field]=isbn_13&...
9
votes
Accepted
Magento 2. Add attribute to Catalog Price Rule
It is pretty easy to do this in Magento 2.1. You need to add a row to the catalogrule table using the module (in your own module):
app/code/Vendor/Rules/Setup/InstallSchema.php
namespace Vendor\...
9
votes
Accepted
Magento 2.1: Add custom category attribute to topmenu classes
I know this is an old question but I just worked on a solution for this. So if anyone else is having this issue...
Have a look at the
Magento\Catalog\Plugin\Block\Topmenu
This is where Magento ...
8
votes
Accepted
Magento 2 - Save additional data to order
For saving data into order table try following way
Vendor/Module/etc/events.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
8
votes
Accepted
Product custom attribute import with CSV Magento 2
Upload from the default CSV generated by Magento
Yes, you need to fill all your custom attributes into the single-column named additional_attributes_code.
Just simply put all your custom attributes ...
8
votes
Magento2: load attribute using attribute code
use \Magento\Catalog\Model\Product\Attribute\Repository;
protected $productAttributeRepository;
public function __construct(
...
Repository $productAttributeRepository
....
) {
....
...
8
votes
Accepted
Magento 2 how to get custom attribute value in cart page and mini cart
For displaying product attribute in minicart
1. Create file catalog_attributes.xml Vendor/Module/etc
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
7
votes
How to add a unique custom attribute for a customer?
You need to InstallData.php like below code :
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$this->logger->info("Username data installed.");
...
7
votes
Magento 2: How to get product custom attribute in product grid
1/ Magento Admin > Stores > Attributes / Product > Click on your custom attribute > Advanced Attribute Properties > Set "Add to Column Options" to "Yes" and click on "Save attribute" button
2/ ...
7
votes
Accepted
Magento 2 rest api get product's attributes options
I've found out how to get list options I was looking for, it's possible to get
attributes groups with array with options like so:
http://magento2.dev/rest/V1/products/attributes?&...
7
votes
Accepted
How to update product eav attribute in magento 2
I used following code
<?php
namespace Custom\Module\Setup;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\...
7
votes
Accepted
Magento 2 how to get custom attribute title and its value in phtml file
As per your comments, I assume that you are getting the product object.
Then use:
$attribute = $_product->getResource()->getAttribute('attribute_code');
This will give the attribute object, ...
6
votes
Accepted
Magento 2 How to add custom product relations?
Magento 2.0.x version:
First of all, there are some notes:
--Replaced event catalog_product_prepare_save with controller product initialization helper that can be customized via plugins - Vendor/...
6
votes
Magento 2: How to display custom attribute in catalog?
Use this
$attribute = $_product->getResource()->getAttribute('identifier');
if ($attribute)
{
$attr_value = $attribute ->getFrontend()->getValue($_product);
}
6
votes
Accepted
How to get all children product from parent configurable product in magento2
You have to just keep below code inside block file and call function inside your template,
protected $productFactory;
protected $dataObjectHelper;
protected $productRepository;
public function ...
6
votes
Product custom attribute import with CSV Magento 2
I have made one more test case and tried to upload with the name of attribute in csv. Instead of "additional_attributes" I have directly added name of a column and tried to upload value of a custom ...
6
votes
Magento2: load attribute using attribute code
Try to use below code
<?php
/*add **\Magento\Eav\Model\Config** in your construct method*/
protected $eavConfig;
public function __construct(
\Magento\Eav\Model\Config $eavConfig
){
$...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
custom-attributes × 669magento2 × 349
product-attribute × 116
attributes × 101
magento-1.9 × 90
customer × 45
customer-attribute × 44
magento-2.1 × 37
product × 33
magento2.3 × 31
rest-api × 28
sales-order × 25
orders × 24
custom × 21
customer-address × 20
category-attribute × 17
checkout × 16
eav × 16
php × 14
event-observer × 14
admin × 13
configurable-product × 13
api × 13
frontend × 12
catalog × 12