Magento - 如何检索捆绑的选项图像 [英] Magento - how to retrieve bundled option images
问题描述
我一直致力于我的第一次magento部署。建立了一个非常自定义的主题...现在处理一些非标准的自定义:
I've been working on my first magento deploy. Got a pretty customized theme built up... tackling some of the non-standard customizations now:
我的主要产品类型之一是我设置的办公椅作为捆绑产品。此产品类型有多种选择(约100种面料选项,手臂式,腰部,头枕等),我需要能够在目录/产品/视图页面上显示每种产品的图像。
One of my primary product types is an office chair which I have set up as a bundled product. There are many options available for this product type (about 100 fabric options, arm style, lumbar, headrest etc) and I need to be able to show an image for each of these on the catalog/product/view page.
作为捆绑产品(我将不再讨论这是否是正确的产品类型 - 我们在可配置和捆绑之间进行辩论) - 每种产品都由许多简单的产品(作为选项)组装而成。这些简单的产品可以上传图像,我已经这样做了。 我现在想要检索媒体文件夹中的网址...
Being a bundled product (and I'll refrain from any discussion about whether this was the right product type - we went around in circles debating between a configurable and a bundled) - each product is assembled from a number of simple products (as options). These simple products can have images uploaded to them, and I've done so. I now want to retrieve the urls to those from the media folder...
经过一些狩猎 - 这些似乎是必不可少的元素:
After some hunting - these seem to be the essential elements:
主题/../ 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>
主题/../ template / bundle / catalog / product / view / type / bundle /option/select.phtml
<?php /* @var $this Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option_Select */ ?>
<?php $_option = $this->getOption(); ?>
<?php $_selections = $_option->getSelections(); ?>
我发现终于找到 getSelections()
in:
I found finally found getSelections()
in:
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
等...但没有提及该选择的图片网址。 ..
so we get back an array with selection_id
, product_id
, price_type
etc... but nothing referring to the image url for that selection...
鉴于:
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;
}
我正在尝试使用refs为每个选择的图像网址构建一个js对象在主题/../ template / bundle / catalog / product / view / type / bundle / option / select.phtml
I'm trying to build a js object with refs to each selection's image url kind of like so in theme/../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
显然未输入正确,因为它只是弹回我占位符图形。
But $_selection
obviously isn't typed correctly because it just bounces me to the placeholder graphic.
假设这些选项可以作为产品输入(或以某种方式从 selection_id 获取简单产品,看起来像这样的东西可以工作我不确定这是不是我想要管理这个功能,但是如果我能得到一堆网址 - 那么我将会开展业务
Assuming these options can be typed as a Product (or somehow obtain the simple product from the selection_id, it seems like something like that can work. I'm not sure if that's exactly how I want to manage this feature, but if I can just get a stack of urls - then I'll be in business
奇怪的是,互联网基本上对这个问题保持沉默。显然没有人需要为他们的产品选择显示图像(或者更确切地说,唯一的解决方案是付费扩展 - 这将是最后的手段)。
Weirdly, the interwebs is basically silent on this subject. Apparently nobody needs to show images for their product options (or, rather, the only solutions are paid extensions - which will be a last resort).
我怎么能搞清楚这一点?
How I can go about figuring this out?
耶稣带领基督.Mage会变得更复杂吗?
Jesus tapdancing christ. Could Mage be any more complicated?
更新
让这个工作原样:
<?php echo $this->helper('catalog/image')->init($_selection, 'small_image')->resize(40,40); ?>
我选择的答案是al所以工作正常,如果有人需要这个修复。
The answer I selected will also work fine, if anybody needs this fix.
推荐答案
$ _selections中的product_id表示所选简单产品的ID。
所以要做的就是:
The product_id in the $_selections represents the id of the selected simple product. So all to do is:
- 获取$ _selections的product_id,
- 按此product_id加载产品
- 将生成的产品对象提供给Mage_Catalog_Helper_Product :: getImageUrl。
这篇关于Magento - 如何检索捆绑的选项图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!