I am working on my first magento deployment. Got a pretty customized theme created ... by removing some non-standard settings now:
One of my main types of products is the office chair, which I created as a complete product. There are many options for this type of product (about 100 fabric options, arm style, lumbar, headrest, etc.), and I need to be able to display an image for each of them on the catalog / product / view page.
Being a related product (and I will refrain from any discussion about whether this is a suitable type of product - we went in a circle, discussing between custom and related) - each product is assembled from several simple products (as options). These simple products may have images uploaded, and I did it. Now I want to get the urls for those from the media folder ...
After some hunting, these are, apparently, the essential elements:
theme /../ template / catalog / product / view / options.phtml
<?php $_options = Mage::helper('core')->decorateArray($this->getOptions()) ?>
<dl>
<?php foreach($_options as $_option): ?>
<?php echo $this->getOptionHtml($_option) ?>
<?php endforeach; ?>
</dl>
theme /../ template / package / catalog / product / view / type / bundle / options / select.phtml
<?php ?>
<?php $_option = $this->getOption(); ?>
<?php $_selections = $_option->getSelections(); ?>
I finally found found in: getSelections()
class Mage_Bundle_Model_Resource_Price_Index extends Mage_Core_Model_Resource_Db_Abstract
{ ...
public function getSelections($productId)
{
$options = array();
$read = $this->_getReadAdapter();
$select = $read->select()
->from(
array('option_table' => $this->getTable('bundle/option')),
array('option_id', 'required', 'type')
)
->join(
array('selection_table' => $this->getTable('bundle/selection')),
'selection_table.option_id=option_table.option_id',
array('selection_id', 'product_id', 'selection_price_type',
'selection_price_value', 'selection_qty', 'selection_can_change_qty')
)
->join(
array('e' => $this->getTable('catalog/product')),
'e.entity_id=selection_table.product_id AND e.required_options=0',
array()
)
->where('option_table.parent_id=:product_id');
$query = $read->query($select, array('product_id' => $productId));
while ($row = $query->fetch()) {
if (!isset($options[$row['option_id']])) {
$options[$row['option_id']] = array(
'option_id' => $row['option_id'],
'required' => $row['required'],
'type' => $row['type'],
'selections' => array()
);
}
$options[$row['option_id']]['selections'][$row['selection_id']] = array(
'selection_id' => $row['selection_id'],
'product_id' => $row['product_id'],
'price_type' => $row['selection_price_type'],
'price_value' => $row['selection_price_value'],
'qty' => $row['selection_qty'],
'can_change_qty' => $row['selection_can_change_qty']
);
}
return $options;
}
so we return an array with selection_id, product_id, price_typeetc .... but nothing does not refer to the URL-address of the image for this selection ...
Given that:
class Mage_Catalog_Helper_Product extends Mage_Core_Helper_Url
{ ...
public function getImageUrl($product)
{
$url = false;
if (!$product->getImage()) {
$url = Mage::getDesign()->getSkinUrl('images/no_image.jpg');
}
elseif ($attribute = $product->getResource()->getAttribute('image')) {
$url = $attribute->getFrontend()->getUrl($product);
}
return $url;
}
js refs URL- , , /../template/bundle/catalog/product/view/type/bundle/option/select. PHTML
var option_set_<?php echo $_option->getId() ?> = {};
<?php foreach ($_selections as $_selection): ?>
option_set_<?php echo $_option->getId() ?>._<?php echo $_selection->getSelectionId() ?> = '<?php echo $_selection->getImageUrl(); ?>';
<?php endforeach; ?>
$_selection , .
, ( - selection_id, , - . , , URL-,
, interwebs . -, (, , , ).
?
. ?
:
<?php echo $this->helper('catalog/image')->init($_selection, 'small_image')->resize(40,40); ?>
, , , - .