我的主要产品类型之一是办公椅,我将其设置为捆绑产品.此产品类型有多种选择(约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;
}
我正在尝试构建一个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获取简单的产品,看起来像这样的东西可以工作.我不确定这是否正是我想要管理这个功能,但如果我可以得到一堆网址 – 然后我会做生意
奇怪的是,这个主题的互联网基本上是无声的.显然,没有人需要为他们的产品选项显示图像(或者更确切地说,唯一的解决方案是付费扩展 – 这将是最后的手段).
我该如何解决这个问题呢?
耶稣带领基督.法师会变得更复杂吗?
更新
这样做是这样的:
<?php echo $this->helper('catalog/image')->init($_selection, 'small_image')->resize(40,40); ?>
如果有人需要这个修复,我选择的答案也可以正常工作.
$_selections中的product_id表示所选简单产品的ID.所以要做的就是:
>获取$_selections的product_id,>通过此product_id加载产品>将生成的产品对象提供给Mage_Catalog_Helper_Product :: getImageUrl.
