Remove attributes from a configurable product in Magento - magento

Is there any way to remove an attribute from a configurable product once it’s already been created? I tried to remove an attribute from an attribute set but Magento won’t allow you to if it’s already been assigned to a product. The only way I’ve seen to remove attributes from products is directly in the database (catalog_product_super_attribute table).

You can use this model to get a collection of the catalog_product_super_attribute attribute and proceed to delete the record.
Mage::getResourceModel('catalog/product_type_configurable_attribute_collection')
Be ware, there is an _afterSave method that tries to save the label on another table on Mage_Catalog_Model_Product_Type_Configurable_Attribute, which will cause an exception when deleting.

Related

Magento 2.2: Child product of Configurable product missing attributes

When I examine the contents of $product->getData() for a regular product, all the attributes I set in the admin appear to be there. But when I examine the contents of $product->getData() for a child product inside a configurable product, many of the values set in the admin seem to be missing.
Is there something obvious that I'm missing?
For the product class, I'm referring to \Magento\Catalog\Model\Product.
Edit: If I make the child product visible on its own and navigate to its page, I can see that all of its attributes are loaded. By contrast, when I get a list of all child products (classes which don't seem to contain all the attributes I set in the admin), this is the way I'm loading them from within a class that overrides \Magento\Swatches\Block\Product\Renderer\Configurable:
$this->getProduct()->getTypeInstance()->getUsedProducts($this->getProduct())
I'm guessing there's something different that occurs when the product classes get instantiated this way that's causing my issue.
Please forgive my newbness. I'm still very new to Magento and am trying to find my way around. Thanks!
After a lot of digging, I found this function definition in the Configurable Product model:
public function getUsedProducts($product, $requiredAttributeIds = null)
It looks like I have to pass in the desired attribute ids in order to load the data I'm later trying to read in my template.

Is it possible to lock SKU field in Magento 1.4.0.1 to prevent further edditing?

Because our warehouse import script crashes if an existing product has two different sku numbers.
Is it possible to set the SKU field to read-only after inital creation?
Thanks!
You could try to use method "lockAttribute(SattributeCode)" called on product model before rendering admin edit/new view (maybe from some observer).

magento - product model and product_collection items have different properties in flat catalog mode

i just know that if i have a product_collection (for example the collection generated in catalog pages)
//event catalog_product_collecion_after_load
$productCollection = $observer->getEvent()->getCollection();
if i take an item from this collection and i compare it with the relative model
$_product = Mage::getModel('catalog/product')->load($item->getEntityId());
this 2 instace of the same entity have different properties!
I'm working in flat catalog mode.
Why the collection's items are not the same of product models?
I would to know if this is the right behaviour and if is it how to have same properties in both object!
sorry, but magento is very dark :(
Because Mage::getModel('catalog/product')->load($item->getEntityId()); loads all attributes for the product and the collection loads only specified attributes different from situation. You may find (CTRL+F) at app/code/core/Mage/Catalog/etc/config.xml something like attributes then you will see the list of all default loaded attributes for product collection. Also you able to change them in your module or directly in Catalog config.xml. But it's not the best idea to change something at app/code/core/Mage/Catalog/etc/config.xml except for debug
For the catalog_product_collection with flat_mode is more complicated add an attribute to the item's collection.
The attributes that are in product items are the join between catalog_product_flat table and the EAV attribute for product entity.
So, in product model from:
collection we have the attributes joined between catalog_product_flat table and the EAV attribute
getModel('catalog/product') we have all EAV attributes
Over these attributes we will certainly have other attributes, i think added in other point.
Now, which attributes are in catalog_product_flat?
Simple are the attributes you checked as "Used in Product Listing" in magento manage attributes! :)
But in some attributes you can't change this option, depends by kind of type you have select. Atribute type Image hasn't "Used in Product Listing" flag, so you have to modify catalog_eav_attribute if you want the new image in product listing.
Well, i spent 2 days to know this, i hope it will useful for other unlucky magento developer. :)
Magento version 1.5

magento product attributes and removing them from backend

I want a hidden attribute, or completely not there in backend for some attributes im using to tie to a special product type I created.
I believe I need the attribute assigned to the attribute set in order to be able to use it.. but correct me if I am wrong!
Now that I think about this, I am probably doing this wrong. There is probably a way to add an attribute to PRODUCT_TYPE (my custom product type is "voucher") instead of PRODUCT.
Not sure though.. Hints?
I believe I need the attribute assigned to the attribute set in order to be able to use it
Your attribute needs to be assigned to an attribute set if you want to be able to edit/view the attribute in the Magento Admin area. It sounds like you do not want your attribute visible there, so the simple solution is to: create your attribute without assigning it to an attribute set. You can still assign/edit/view your attribute through database manipulation or by loading the product model and using the magic get & set methods.
$product = Mage::getModel('catalog/product')->load($id);
$product->setFoo('hidden attribute value');
echo $product->getFoo();
Another way is to set the visibility of your attributes by database, have a look here:
Magento - Product Attribute which is not visible/editable in administration
You can also lock attributes and make them readonly for your backend users by using a observer:
Magento read-only and hidden product attributes

Mass Update Magento Field to "Use Default Value"

Is there a way that I can reset a bunch of magento products for a particular store view back to "Use Default Value" It seems once you set the store specific data there is no easy way to unset so that it receives the default data. This is causing me to have to do multiple imports.
I know you want to change "a bunch of products" ...
Just for the usecase someone want to get rid of the store-view-specific values for ALL products:
Just cycle the scope of the attribute from 'Store View' to 'Global' an back to 'Store View' again.
Just remove record from product_entity_[attirubte_type] for the product_id, attribute_id and store_id.
You can use:
core_block_abstract_to_html_before adminhtml event to add the required checkboxes for every attribute in admin mass update form;
then catalog_product_attribute_update_before event to delete the values from the EAV tables for a specific store view, only for those attributes that have the checkbox you injected earlier with core_block_abstract_to_html_before set as checked.
Original answer: https://magento.stackexchange.com/a/45229/16724

Resources