我想在magento中添加类别和子类别

我想在magento中添加类别和子类别

本文介绍了我想在magento中添加类别和子类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试使用此代码在magento中添加类别和子类别:



HI all, I'm trying add categories and subcategories in magento with this code:

function stringtourlKey($collectionName, $separator = '-'){
          $accents_regex = '~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i';
          $special_cases = array('&' => 'and');
          $string = mb_strtolower(trim($collectionName), 'UTF-8');
          $string = str_replace(array_keys($special_cases), array_values($special_cases), $string);
          $string = preg_replace($accents_regex, '$1', htmlentities($string, ENT_QUOTES, 'UTF-8'));
          $string = preg_replace("/[^a-z0-9]/u", "$separator", $string);
          $string = preg_replace("/[$separator]+/u", "$separator", $string);
          return trim($string, "-");
        }


        $allGenre = array("Suits & Suit Separates", "Shirts", "Pants", "Sportcoats & Blazers", "Swimwear", "Athletic Clothing", "Loungewear", "Outerwear", "Underwear", "All Clothing");


        foreach($allGenre as $categoryStr) {
        $collectionName = $categoryStr;

        $urlKey = stringtourlKey($collectionName);


        try{
        $category = Mage::getModel('catalog/category');
        $category->setName($collectionName);
        $category->setUrlKey($urlKey);
        $category->setIsActive(1);
        $category->setDisplayMode('PRODUCTS');
        $category->setIsAnchor(1); //for active achor
        $category->setStoreId(Mage::app()->getStore()->getId());
        $parentCategory = Mage::getModel('catalog/category')->load(205);
        $category->setPath($parentCategory->getPath());
        $var = $category->save();
        } catch(Exception $e) {
        var_dump($e);
        }
        }





但是通过这段代码,我逐个添加类别和子类别与父ID。但我想一次添加所有类别。我有一个想法通过数组我们可以管理它,比如





but through this code, I'm adding categories and sub-categories one by one with parent Id. But i want to add all categories at once. I have an idea through array we can manage it, like

$testingFlow = array( "first" => array("Monitors", "Oversized Displays", "Monitor Accessories"));





但不知道如何为类别和子类别管理这个数组,有人帮我吗?



but no idea how to manage this array for category and subcategory, anyone help me?

推荐答案




这篇关于我想在magento中添加类别和子类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 01:39