我一直在研究我的第一个magento部署。建立了一个非常定制的主题......现在解决一些非标准定制:Magento - 如何检索捆绑的选项图像
我的一个主要产品类型是我设置为捆绑产品的办公椅。这种产品类型有许多选择(约100种布料选择,手臂样式,腰部,头枕等),我需要能够在目录/产品/视图页面上显示每种图像。
作为一个捆绑产品(我不会讨论这是否是正确的产品类型 - 我们围绕可配置和捆绑进行辩论) - 每个产品都由许多简单产品组装而成(作为选项)。这些简单的产品可以将图像上传到他们,我已经这样做了。 我现在要检索的网址,这些从媒体文件夹...
一些狩猎之后 - 这似乎是必不可少的要素:
主题/../模板/目录/产品/视图/ options.phtml
<?php $_options = Mage::helper('core')->decorateArray($this->getOptions()) ?>
<dl>
<?php foreach($_options as $_option): ?>
<?php echo $this->getOptionHtml($_option) ?>
<?php endforeach; ?>
</dl>
主题/../模板/束/目录/产品/视图/类型/捆/选项/ select.phtml
<?php /* @var $this Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option_Select */ ?>
<?php $_option = $this->getOption(); ?>
<?php $_selections = $_option->getSelections(); ?>
我发现终于找到getSelections()
在:
class Mage_Bundle_Model_Resource_Price_Index extends Mage_Core_Model_Resource_Db_Abstract
{ ...
/**
* Retrieve bundle options with selections and prices by product
*
* @param int $productId
* @return array
*/
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;
}
,所以我们回来与selection_id
数组,product_id
,price_type
等...但没有提及到图片网址为选择...
鉴于:
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;
}
我想卜ILD与裁判到每个选择的图像的URL有点像所以在主题/../模板/包/目录/产品/视图/类型/包/选项/ select.phtml一个js对象
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单纯的产品,它似乎像这样的事情能正常工作。我不知道如果这正是我想如何管理此功能,但如果我可以只是得到一堆网址 - 那么我将在商业上
奇怪的是,interwebs在这个问题上基本上是沉默的。显然没有人需要为他们的产品选项显示图像(或者更确切地说,只有解决方案是付费扩展 - 这将是最后的手段)。
我怎么可以去弄清楚这一点?
耶稣tapdancing基督。法师会更复杂吗?
更新
得到这个这样的工作:
<?php echo $this->helper('catalog/image')->init($_selection, 'small_image')->resize(40,40); ?>
我选择也会答案做工精细,如果有人需要此修复程序。
我在发布这个数据后几个小时就想到了这个(请参阅更新)。它非常接近你的答案 - 但放弃获得product_id。这也会起作用。干杯 – Bosworth99