Magento 2.2: Child product of Configurable product missing attributes - magento

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.

Related

How do I make associated simple products inherit parent product categories?

My problem:
At one point, everything was working fine. Associated simple products for a configurable product inherited the configurable products' categories. Then we reorganized some categories and added a few new ones, and now all existing child products' assigned categories have been wiped out, and when I create a new configurable product and use quick create to associate child products, it no longer passes the parent product's category assignments along.
What I've tried:
I've tried assigning products to categories through Manage Categories > Desired Category > Category Products tab > Reset Filter button > Check off all desired products, but then Magento becomes unhappy with me and won't make the change. Now it looks like I'm also stuck going through all the simple products manually and assigning categories.
Solution I'm looking for:
I do not want an extension as a solution, as we already are using several, and have had issues with them conflicting with each other. Is there a simple way to programmatically assign a parent product's categories to its child product? Or perhaps there's some setting that I'm overlooking?
Any help would be greatly appreciated!
This is a task rather than a specific question.
It is pretty trivial to write an extension whose sole task would be to gather all of the configurable product, then set all of their child product's category_ids attribute to the original configurable's. Then use the cron to run it at certain intervals (like once a day or once a week).
It would be just as easy to make a stand alone script to do it too (though you would have to visit the page to run it).

Magento: Category product design update not applied to search result products

I'm using a design update XML applied to all products under specific categories. The update is applied successfully to those products when browsed to them from those categories, but not when those products are opened from search results. How can I make the design update affect those products when opened from search results?
You need to add a layout handle that you can "grab" for each one of these products and modify the layout through layout xml files.
The key to this process is in the initProductLayout method of Mage_Catalog_Helper_Product_View. This method is where custom layout handles are added based on the product model. You can grab the layout update object from the controller and call addHandle() on it with a string to add that handle. So you'll want to rewrite this method and do something like this:
$update = $controller->getLayout()->getUpdate();
foreach ($product->getCategoryIds() as $categoryId) {
$update->addHandle('PRODUCT_IN_CATEGORY_' . $categoryId);
}
Now, in a layout xml file you can target the <PRODUCT_IN_CATEGORY_##> handle for the ID of your category(ies) and any layout updates you put here will be applied to the product view page no matter how it is accessed.
Depending on the specifics of your installation, it may make more sense to key the handle with some other category identifier, like the name or URL key, instead of the numeric ID. For this, use $product->getCategoryCollection() and iterate through the collection to grab what you need. You may also want to use $product->getAvailableinCategories() if you want to include only category IDs that the product belongs to directly (instead of including categories of higher parentage).

Magento cant associate simple to configurable product

I created a configurable product and went to the associated products tab and used the quick create product feature to create a bunch of products based on my configurations. However non of these products appear in the list of associated products.
I noticed that the attributes I created don't even show up on the edit product page, on either the simple, or the configurable product.
I started first by creating 3 new attributes for a configurable product I want to add, I setup the options for each one and created a new attribute set based on default that included the new attributes I created.
When I create a new simple product or configurable product, you cannot see the attributes I have created. I have tried with the attributes in the general tab as well as on their own tab. But they are never visible when you try to edit the product.
I'm suspecting the reason I can't associate the products is due to this strange problem
I'm using 1.4.2
[edited to add my work flow/screen grabs]
http://www.buggyonpurpose.com/magento/configurable_products/01-attirubte_set.png
http://www.buggyonpurpose.com/magento/configurable_products/02-create_configurable.png
http://www.buggyonpurpose.com/magento/configurable_products/03-setup_configurable.png
http://www.buggyonpurpose.com/magento/configurable_products/04-quick_create.png
http://www.buggyonpurpose.com/magento/configurable_products/05-associate_product.png
http://www.buggyonpurpose.com/magento/configurable_products/06-manage_products.png
http://www.buggyonpurpose.com/magento/configurable_products/07-edit_product.png
It took a while but finally figured it out. When I created my attributes, in Attribute Properties where it says "Apply To:" I had only assigned it to configurable products, but you must also assign to simple products as well. (or just apply to all)
Keep in mind you will have to recreate your original configurable product before it will work.
Assuming you have created attributes with options and attribute set.
Can you please createConfigurable product again
Manage products -> Add Product select your default attribute set and Configurable product option.
The next window will be to choose the attributes that you have have created.
Lets say that there are three attributes color, fragrance, and volume as three different attributes and you pick fragrance here to associate the Configurables to the simples which you will be creating.
After you successfully created the Configurable product.
Create simple products based on the same attribute set default
you must be able to see all the attributes you created(color, fragrance, and volume).
Please pick any option for the Fragrance attribute.
Go to the Manage Products ->select to edit the Configurable product you have just created.
Go to the "Associated Products" tab and select "Any" from the drop down on the extreme left.
You must be able to see the Simple which you have created now
you must also be able to see the parent-child linking attribute "fragrance" present above the grid of products.
Make sure the simple is in "In stock" before you see whether they appear in front end.
Its not necessary for the attribute to appear in the Configurable product edit page.
Follow the above steps, hope it will guide you.
Please let me know if you unable to follow any of the above steps.
You can also read the below link, which is very useful to create a config product.
http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-a-configurable-product/
Cheers
I had the same issue.
A possible workaround is to add the attributes in the single products and after they become available through the configurable product at "Apply To:".

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

how to add default variants to product in magento

I'm very new to Magento.I am having product with some variants like "size" with values "large XX,small XX,medium XX".I want the feature to make any one of this values as default in admin.
my screenshot explanation here
How can i do this
please help me!
When you say you want them to be defaults, you are being a little vague. Are you talking about using configurable products for this? Custom product options? When you say "default in admin", what do you mean? Which page are you referring to? More detail will help us answer the question.
Thanks,
Joe
As far as I know, what you are asking for is not a default functionality of Magento, but it shouldn't be difficult to add some javascript to allow you to force selections at page load time. Ultimately, it's just code, so it's definitely possible to do.
my suggestion would be to add a attribute to all you products called for instance "defaultselect" then you can enter your value easily from the backend to your configurable product.
so now you have a configurable product say a hat which comes in 3 sizes, and has 3 assigned simple products. set the defaultselect value to one of the size values
now some layout xml and javascript is required to get you product attribute to work with the magento selects.
first you want to actually include you js. this is done through the layout xml. you can include update using add js method for PRODUCT_TYPE_configurable handle
now the js. store the js in the skin js folder.
to make this work you would need to know the configurable product defaultselect attribute value we're testing against. this could be retrieved with your own ajax function to a method which checks if the current product has a defaultselect attribute and returns it's value or false.
if you have a value from your ajax function you can work with that ie you have both the returned attributes from the configurable product and magento will return the rest.
however after that it seems to get complicated your going to have to do something with the js magento aready uses to render product options

Resources