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

时间:2013-08-31 14:05:06

标签: php magento

我正在创建一个简单的脚本,用于更新Magento中特定类别中所有产品的所有价格。我有行动代码工作,它更新价格。现在我正在创建一个表单,其中包含所有可用类别的下拉列表,然后是一个输入百分比的文本字段。我遇到的问题是我无法获得下拉列表来填充类别,我会疯了。我已经尝试过其他类似的代码并且破解了其他代码,试图让它工作,这让我疯了。下面是我目前的黑客攻击版本 - 我知道这是丑陋和错误但是呃你能做什么。谢谢你的期待。

    <?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 个答案:

答案 0 :(得分:5)

下面的

是下拉列表中的代码获取子类别

<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 :(得分:0)

this.httpClientService.addHeader("Authorization", "Bearer " + this.tok);

You can use the following code to easily display all categories in the dropdown till level 3:
相关问题