doubi3996 2013-08-31 14:05
浏览 34
已采纳

Magento - 在下拉列表中显示所有类别

I am creating a simple script for updating all prices to all products within a specific category in Magento. I have the action code working and it updates the prices. Now I am making a form that has a dropdown with all the available categories in it then a text field that a percent is inputted. The problem I am having is I can not get the dropdown to populate the categories and I am going insane. I have tried other similar code and hacked to pieces other code to try to get it to work and it is driving me insane. Below is my current hacked up version - I know it is ugly and wrong but eh what can you do. Thanks for looking.

    <?php
require 'app/Mage.php';
Mage::app();
class Mymodule_Pup_Helper_Data extends Mage_Core_Helper_Abstract {
public function getCategoriesDropdown() {
$categoriesArray = Mage::getModel(‘catalog/category’)
->getCollection()
->addAttributeToSelect(‘name’)
->addAttributeToSort(‘path’, ‘asc’)
->addFieldToFilter(‘is_active’, array(‘eq’=>’1′))
->load()
->toArray();
foreach ($categoriesArray as $categoryId => $category) {
if (isset($category['name'])) {
$categories[] = array(
‘label’ => $category['name'],
‘level’  =>$category['level'],
‘value’ => $categoryId
);
}
}
return $categories;
}
}
?>
<html>
<body>
Update Prices by Category
<form action="pupped.php" method="post">
<select id="category-changer" name="cat" style="width:150px;">
<option value="">--Select Category--</option>
<?php
$_CategoryHelper = Mage::helper("pup")->getCategoriesDropdown();
foreach($_CategoryHelper as $value){
foreach($value as $key => $val){
if($key=='label'){
$catNameIs = $val;
}
if($key=='value'){
$catIdIs = $val;
}
if($key=='level'){
$catLevelIs = $val;
$b ='';
for($i=1;$i<$catLevelIs;$i++){
$b = $b."-";
}
}
}
?>
<option value="<?php echo $catIdIs; ?>"><?php echo $b.$catNameIs ?></option>
<?php
}
?>
</select>
Percent: <input type="text" name="per">
<input type="Submit">
</form>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • dongmou1964 2013-09-01 07:15
    关注

    below are the code get subcategory in drop down

    <select id="category" class="myinput-text required-entry widthinput" name="category">
    <?php
      $parentid=5; // parent id which you want sub category
      $categories=explode(',',Mage::getModel('catalog/category')->load($parentid)->getChildren());
      foreach($categories as $cat){ 
         $category=Mage::getModel('catalog/category')->load($cat);
    ?>
       <option value="<?php echo $category->getId();?>"><?php echo $category->getName();?></option>
    <?php } ?>
    </select>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看