magento -- 可配置产品页获得所属简单产品的库存
2010-04-02 20:09
375 查看
想在产品页显示可配置产品所属的简单产品的库存,解决方案如下:
打开文件mage/catalog/block/product/view/type/configurable.php,大概在85行可以找到如下代码:
替换成
然后在大概128行找到如下代码:
替换成
然后前台通过一点JS处理下就可以得到类似淘宝的效果
打开文件mage/catalog/block/product/view/type/configurable.php,大概在85行可以找到如下代码:
foreach ($this->getAllowAttributes() as $attribute) { $productAttribute = $attribute->getProductAttribute(); $attributeValue = $product->getData($productAttribute->getAttributeCode()); if (!isset($options[$productAttribute->getId()])) { $options[$productAttribute->getId()] = array(); } if (!isset($options[$productAttribute->getId()][$attributeValue])) { $options[$productAttribute->getId()][$attributeValue] = array(); } $options[$productAttribute->getId()][$attributeValue][] = $productId; }
替换成
foreach ($this->getAllowAttributes() as $attribute) { $productAttribute = $attribute->getProductAttribute(); $attributeValue = $product->getData($productAttribute->getAttributeCode()); if (!isset($options[$productAttribute->getId()])) { $options[$productAttribute->getId()] = array(); } if (!isset($options[$productAttribute->getId()][$attributeValue])) { $options[$productAttribute->getId()][$attributeValue] = array(); } $options[$productAttribute->getId()][$attributeValue][] = $productId; //Alex $options['qty'][$product -> getAttributeText($productAttribute->getName())] = floor($product->getStockItem()->getQty()); }
然后在大概128行找到如下代码:
$info['options'][] = array( 'id' => $value['value_index'], 'label' => $value['label'] , 'price' => $this->_preparePrice($value['pricing_value'], $value['is_percent']), 'products' => isset($options[$attributeId][$value['value_index']]) ? $options[$attributeId][$value['value_index']] : array(), );
替换成
$info['options'][] = array( 'id' => $value['value_index'], 'label' => ($options['qty'][$value['label']] <= 0) ? $value['label'] . ' * out of stock' : $value['label'] . " * (".$options['qty'][$value['label']]." in stock)", 'price' => $this->_preparePrice($value['pricing_value'], $value['is_percent']), 'products' => isset($options[$attributeId][$value['value_index']]) ? $options[$attributeId][$value['value_index']] : array(), );
然后前台通过一点JS处理下就可以得到类似淘宝的效果
相关文章推荐
- Magento 可配置产品页获得所属简单产品的库存
- magento 获得产品所属分类
- 提供Magento上一个和下一个产品的简单帮助(Helper)类
- Juniper WX/WXC产品简单安装(2)用com口进行初始配置
- 翻翻git之---简单的配置达到产品在应用市场的评价跳转功能
- magento的xml配置文件的简单解析-frontend
- 获得Z-WAVE产品的完整可配置参数列表
- magento -- 判断一个产品是否是一个可配置产品的子产品
- magento -- 获得产品所属于的分类
- 翻翻git之---简单的配置达到产品在应用市场的评价跳转功能
- [置顶]【H3 BPM工作流程管理产品小故事】第一篇 配置简单流程
- [Magento SQL] 返回产品SKU,Stutus(上下架状态)和库存
- magento -- 可配置产品的选项如何默认选中第一项
- magento -- 获得可配置产品的所有子产品
- magento -- 根据属性名获得产品的属性值
- Magento根据产品SKU查询产品库存状态
- Magento -- 可配置产品的选项如何默认选中第一项
- Magento产品详情页获取产品的库存
- Magento获得产品属性集
- Magento获得用户所有的订单、喜欢的产品