Hot answers tagged

55

you can add to the constructor of your class an instance of \Magento\Eav\Model\Config like this: protected $eavConfig; public function __construct( ... \Magento\Eav\Model\Config $eavConfig, ... ){ ... $this->eavConfig = $eavConfig; ... } then you can use that in your class $attribute = $this->eavConfig->getAttribute('...


49

In addition to your code put this: $product = Mage::getModel('catalog/product') ->setStoreId($store_id) ->setBrand($brand_value); // not loading the product - just creating a simple instance $brandLabel = $product->getAttributeText('brand');


39

See Mage_Eav_Model_Entity_Setup::removeAttribute(). It takes two arguments - the first is the entity code, and the second is the attribute code. Edit - to run from a non-installation scope: <?php include 'app/Mage.php'; Mage::app(); $setup = Mage::getResourceModel('catalog/setup','catalog_setup'); $setup->removeAttribute('catalog_product','attr_code')...


32

You can find type and input value from database eav_attribute table. Type static varchar int text datetime decimal Input boolean select text image media_image price date textarea gallery multiselect hidden multiline You can check for backend_type value for your type case and frontend_input for your input value for all attributes from this table. You ...


31

Part 1 For the purpose of this demo I'm going to create a module, let's name it Easylife_News that contains an entity named Article. The module comes with complete CRUD code for backend, including the section for managing attributes, and some simple frontend listing and view page for each article. It also ads a menu item in the top menu to the listing of ...


26

Yes, flat tables are still a thing. You can enable flat tables for products and categories from stores->configuration->catalog->storefront. Why do we need flat tables? They do offer significant performance boost for large catalog data. One of our client has only 5 categories and around 250 products so it doesn't really matter if you have flat on or off. It ...


23

It is my view that this sort of thing should be done via set-up script or if that is not possible then via the admin section. I cannot think of a situation where you need to write a script for this, but maybe there is one. For a set-up script it is incredibly simple: $this->startSetup(); // Remove Product Attribute $this->removeAttribute('...


17

My guess is that it's part legacy and a "convenience" pattern for developers to implement "generic" entities/models. As you've stated, the related tables are usually empty. The reason being is that none of the core EAV entities use this "default" entity table structure. These are the entity tables from a 1.8 install: mysql> select distinct(entity_table) ...


17

The eav_attribute table's column entity_type_id is mapped to the eav_entity_type table, you can see the entities there.


14

LuFFy's answer is technically incorrect as it has 3 issues: it will remove values for admin store view only leaving some store-views related garbage it will remove unused values of attributes of all entity types it will remove ALL values from attributes with "multiple select" type regardless if they are assigned to any products or not because they options ...


14

When you create a attribute for a product EAV comes in a picture. To get a value you need to know basics, which magento uses to store eav data. For this following tables plays a important role. eav_attribute Whenever you create a attribute this table gets entry which stores all important data which helps to make a relation, like entity_type_id,...


13

Yes, it's possible. you need to add an attribute for your main entity that has a custom source model. Let's say your entities are called Article and Author and you want the Article entity to have as attribute and Author so when you add/edit and article you can select from a dropdown one of all the authors. You need to add this in the setup class (...


13

Looks like problem in server settings. Please try increase max_input_vars setting to 100000 and try reproduce problem.


12

The first rule of Magento is: Never edit the database directly. I admit that I broke this rule on numerous occasions, so... you can delete the attributes from eav_attribute, the constraints with ON DELETE CASCADE should cleanup the rest of the tables. But I still think you should take the clean way: $attributeId = 55; Mage::getModel('catalog/...


11

As @sonassi pointed out, you should really be using Magento models to interact with the data. I would add that regardless of where your code is, this still holds true. If you are writing something completely detached from Magento, then use the Web Services API, it's what it's there for. You can get a collection of customers in Magento with the full name ...


11

If flat catalog is enabled, then in any product list the flat tables will be used. The flat tables are generated one per store view when rebuilding the flat index. They contain all the attributes marked as 'Used in product listing', one column for each attribute. This is a big boost in performance because instead of a lot of joins to get the product ...


11

Part 2. app/code/local/Easylife/News/Model/Attribute.php - the model for the article attributes <?php class Easylife_News_Model_Attribute extends Mage_Eav_Model_Entity_Attribute { const SCOPE_STORE = 0; const SCOPE_GLOBAL = 1; const SCOPE_WEBSITE = 2; const ...


11

You should be able to do something like: $entity = 'catalog_product'; $code = 'status'; $attr = Mage::getResourceModel('catalog/eav_attribute') ->loadByCode($entity,$code); if ($attr->getId()) { // atttribute exists }


11

Only the attributes that are marked to be used in product listing are copyed to the flat tables. Mark it like this and reindex everything.


11

This is untested but should work: $colourId = $product->getResource()->getAttribute("colour")->getSource()->getOptionId("red"); $product->setColour($colourId)->save();


9

My examples are geared towards category image attribute, but the principle is the same for product based. This information should get you going in the right direction (I hope) Attributes have two elements that define their input and backend (processing) behaviour. Below is the base requirements for a new attribute created in a category, which is an image. ...


9

$attribute = Mage::getModel('catalog/resource_eav_attribute') ->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'manufacturer'); $label = $attribute->getFrontendLabel();


9

Part 3. app/code/local/Easylife/News/Block/Adminhtml/Article/Grid.php - the admin grid <?php class Easylife_News_Block_Adminhtml_Article_Grid extends Mage_Adminhtml_Block_Widget_Grid { public function __construct(){ parent::__construct(); $this->setId('articleGrid'); $this->setDefaultSort('entity_id'); $this-&...


9

I found the answer finally. adding: $attributeMyhkt->addData([ 'attribute_set_id' => 1, 'attribute_group_id' => 1 ]); below: $attribute->setData('used_in_forms', ['adminhtml_customer']);


9

Starting from 2.1 Magento uses UI component to build product admin form. Thus, it should be customized as suggested in the manual. In particular, your task could be accomplished with modifier approach. Create DI file under YourVendor/YourModule/etc/adminhtml/di.xml with the content like: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/...


8

This was almost certainly changed in 1.6 part of adding Oracle support - in Oracle, columns can only be 30 characters long, so lots of Magento attributes got shortened, and I imagine this restriction was added at the same time. See http://m-chanaan.hr/wp-content/uploads/2013/04/RDBMS_Guide2.pdf for a lot of discussion on this.


8

Part 4 app/code/local/Easylife/News/Block/Adminhtml/News/Renderer/Fieldset/Element.php - fieldset element renderer. <?php class Easylife_News_Block_Adminhtml_News_Renderer_Fieldset_Element extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element { protected function _construct() { $this->setTemplate('easylife_news/form/...


8

Place InstallData.php file in your module's Setup directory: <?php namespace Training\Product\Setup; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Catalog\Setup\CategorySetupFactory; /** * @codeCoverageIgnore */ class InstallData ...


7

Can you do this in the database? Yes. Should you? No. Rule #1 about Fight Magento Club - Never touch the database directly. So create an install script. There are dozens of tutorials out there for that. Once you have that set up, the process isn't dissimilar from adding options to other EAV option types: <?php $installer = $this; /* @var $installer ...


7

You can try below code Mage::getModel('catalog/product_attribute_set_api')->attributeRemove($attributeId, $attributeSetId); It will remove attribute from attribute set only but I am not sure if it will also remove it permanently. For removing an attribute permanently, you can try below. Mage::getModel('catalog/product_attribute_api')->remove($...


Only top voted, non community-wiki answers of a minimum length are eligible