What I'm trying to accomplish:
I have 2 types of products.
- Rental cars
- Rental companies (of those cars)
When comparing rental cars I want to show the rental cars attributes but also the attributes of its rental company.
So what I did was:
I added a dropdown attribute in rental cars with the rental companies so that I can make a connection between the two.
In logical terms it should be something like this: When rental car attribute X = 'Rent-A-Car', then display attributes of rental company 'Rent-A-Car'.
To be exact: The rental cars and the rental companies both have different attribute sets.
I believe this is doable but after days of trying I'm stuck. Anybody?
EDIT
What I have pulled of myself so far is this:
<?php
$product = Mage::getModel('catalog/product')->load($provider_id);
$attributes = $product->getAttributes();
foreach ($attributes as $attribute)
{
if ($attribute->getIsVisibleOnFront())
{
$attributeCode = $attribute->getAttributeCode();
$label = $attribute->getFrontend()->getLabel($product);
$value = $attribute->getFrontend()->getValue($product);
echo '<tr class="product-shop-row">';
echo '<th>' . $label . '</th>';
foreach ($items as $_item)
{
echo '<td>' . $value . '</td>';
}
echo '</tr>';
}
}
?>
I get the right attributes and the right attribute values but only from the first product in the list. The other compare products always have exactly the same values.
I believe I nead a sort of 'foreach product' but I don't know how :(
-
Create Separate attribute and then assign what attribute you need particular attribute setMagento 2– Magento 22015年10月27日 19:05:33 +00:00Commented Oct 27, 2015 at 19:05
2 Answers 2
It seems like you are on the right path. Where are you getting stuck?
Be sure to use ids instead of names. You can write an observer to add a "rental company" attribute each time one of those product types is added, but to start I would manually create one of these entries for each company.
Attribute "Rental Company" ("Name" => "Entity Id") "Hertz" => "1", "XYZ" => "23", "Enterprise" => "12"
The id should be the id of your rental car company product. Once you have that id, then you can load the company product and access it's attributes.
I think this is bad scheme, u should use category for rental cars company, but if u want make link u can use magento link like related products. After that u should change code compare page. U should add method which load product by link in block and after it add in template.
Explore related questions
See similar questions with these tags.