magento中目录url多层变成单层的方法

magento中目录url多层变成单成的方法,app/code/core/Mage/Catalog/Model/Url.php这个php文件,找到

if (null === $parentPath) {

$parentPath = $this->getResource()->getCategoryParentPath($category);

}

elseif ($parentPath == ‘/’) {

$parentPath = ”;

}

把上面的代码修改为:

//if (null === $parentPath) {
//$parentPath = $this->getResource()->getCategoryParentPath($category);
//}
//elseif ($parentPath == ’/') {
$parentPath = ”;
//}

magento中删除清空指定目录或属性集下产品的自定义选项的sql脚本

magento的批量上传,可以给产品的增加自定义选项,但修改不了已存在的自定义选项内容,这时清空,并将完成的自定义选项重新上传,是一个比较好的实现方式!
以下是magento中删除指定目录下产品的自定义选项的sql脚本,其中182是指定的目录id,大家在用时做一个替换。

delete from catalog_product_option_type_price where option_type_id in  (select option_type_id from  catalog_product_option_type_value  where option_id in (select option_id  from catalog_product_option where product_id   in (SELECT product_id FROM `catalog_category_product` WHERE category_id =182)));
delete from catalog_product_option_type_title  where option_type_id in  (select option_type_id from  catalog_product_option_type_value   where option_id in (select option_id  from catalog_product_option where product_id   in (SELECT product_id FROM `catalog_category_product`  WHERE category_id =182)));
delete from  catalog_product_option_type_value  where option_id in (select option_id  from catalog_product_option where product_id   in  (SELECT product_id FROM `catalog_category_product` WHERE category_id =182));
delete from catalog_product_option_price  where  option_id in (select option_id  from catalog_product_option where product_id   in (SELECT product_id FROM `catalog_category_product` WHERE category_id =182));
delete  from catalog_product_option_title  where  option_id in (select option_id  from catalog_product_option where product_id   in (SELECT product_id FROM `catalog_category_product` WHERE category_id =182));
delete  from catalog_product_option where product_id   in (SELECT product_id FROM `catalog_category_product` WHERE category_id =182);

删除指定属性集的产品自定义选项的sql脚本,其中11是属性集id,用时做个替换

delete from catalog_product_option_type_price where option_type_id in  (select option_type_id from  catalog_product_option_type_value  where option_id in (select option_id  from  catalog_product_option where product_id   in (SELECT entity_id FROM `catalog_product_entity` WHERE attribute_set_id =11)));
delete from catalog_product_option_type_title  where option_type_id in  (select option_type_id from  catalog_product_option_type_value  where option_id in (select option_id  from catalog_product_option where product_id   in (SELECT entity_id FROM `catalog_product_entity` WHERE attribute_set_id =11)));
delete from  catalog_product_option_type_value  where option_id in (select option_id  from catalog_product_option where product_id   in (SELECT entity_id FROM `catalog_product_entity` WHERE attribute_set_id =11));
delete from catalog_product_option_price  where  option_id in (select option_id  from catalog_product_option where product_id   in (SELECT entity_id FROM `catalog_product_entity` WHERE attribute_set_id =11));
delete  from catalog_product_option_title  where  option_id in (select option_id  from catalog_product_option where product_id   in (SELECT entity_id FROM `catalog_product_entity` WHERE attribute_set_id =11));
delete  from catalog_product_option where product_id   in (SELECT entity_id FROM `catalog_product_entity` WHERE attribute_set_id =11);

magento如何调用Category目录中Thumbnail Image略缩图

在magento新版中,给目录新增了一个Thumbnail Image略缩图功能,这样就有两个图设定,这样就可以灵活的应用目录的图片功能
原先一个图的调用就是

$this->getCurrentCategory()->getImageUrl()

那 Thumbnail Image略缩图如何调用?
以下是调用语法

<img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'.$_category->getThumbnail()  ?>" />

如何在magento中获取当前产品目录中随机产品?

magento有cross sell和up sell还有相关产品,但是都是需要手动设置的。所以如何在产品详细页随机显示一下产品同分类下 的其它产品,就成为了一个省事的方法了

如下代码可以放在产品详细页的任何位置,如view.phtml或者media.phtml中。改一改就可以改成随机显示某一个分类下的产品,显示的数量,图片的大小在本代码中都是很容易改的。

<!--for show other product-->
< ?php $categories = $_product->getCategoryIds(); ?>
    < ?php
        $result = array();
        foreach($categories as $cat_id) {
            $category = Mage::getModel('catalog/category');
            $category->load($cat_id);
            $collection = $category->getProductCollection();
            foreach ($collection as $product) {
                $result[] = $product->getId();
            }

        }
    ?>
    <div class="box-others-also-like">
        <ul>
        < ?php
        if(sizeof($result) >= 5)
        {
           $ourneed = array_rand($result,5);
           foreach($ourneed as $cc)
            {
             $thisproduct= Mage::getModel('catalog/product')->load($result[$cc]);
             ?>
             <li>
            <a href="<?php echo $thisproduct->getProductUrl(); ?>" title="< ?php echo $thisproduct->getName(); ?>" ><img src="<?php echo $this-/>helper('catalog/image')->init($thisproduct, 'small_image')->resize(200) ?>" width="200" height="200" alt="< ?php echo $thisproduct->getName(); ?>" /></a>
            </li>
            < ?php } ?>
        < ?php
        }else
        {
           foreach($result as $cc)
            {
             $thisproduct= Mage::getModel('catalog/product')->load($cc);
             ?>

                <li>
                <a href="<?php echo $thisproduct->getProductUrl(); ?>" title="< ?php echo $thisproduct->getName(); ?>" ><img src="<?php echo $this-/>helper('catalog/image')->init($thisproduct, 'small_image')->resize(200) ?>" width="200" height="200" alt="< ?php echo $thisproduct->getName(); ?>" /></a>
                </li>
            < ?php
            }
            }
            ?>
        </ul>
    </div>
    <!--for show other product-->


上述代码中array_rand($result,5); ,这个代码是最关键的,是随机从数组中取5个产品,其它都是正常的magento代码组织.

Upsell products with scroller插件改成当前产品目录所有清单

Upsell products with scroller 插件是将magento中的up sell product中按卷动的方式进行左右点击显示,由于个人原因,准备将其改成当前产品目录中所有产品。原先效果如下:

改动后的效果如下:

核心代码,是在app/code/community/My/Iupsell/Block/Catalog/Product/List/Upsell.php增加一个代码,即可替换原有功能,当然你也可以重新写一个块,在保留up sell原有显示的基础上,增加一个左右卷动的功能。

protected function _prepareData()
    {
        $getcategory_product = Mage::getModel('catalog/category')->load(Mage::registry('product')->getCategoryId());
         /* @var $product Mage_Catalog_Model_Product */
        $this->_itemCollection =  $getcategory_product->getProductCollection () ;
//		$_category_name=$getcategory_product.getName();
        Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection,
            Mage::getSingleton('checkout/session')->getQuoteId()
        );

		$this->_addProductAttributesAndPrices($this->_itemCollection);
	    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection);

        if ($this->getItemLimit('listscoll') > 0) {
            $this->_itemCollection->setPageSize($this->getItemLimit('listscoll'));
        }

        $this->_itemCollection->load();

        foreach ($this->_itemCollection as $product) {
            $product->setDoNotUseCategoryId(true);
        }

        return $this;
    }