magento目录产品数据1001条的限制解决

magento目录产品数据可以批量导入超入1001条的产品,但如果对产品目录进行保存,就会发现只有1001条的产品了,
解决这个有两种思路,
一种是改服务器配置,但这个改动可能会引发ddos的风险,所以弃之
第二是改magento的核心代码,改动如下:
app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php文件中

parse_str($data['category_products'], $products);
改成
$cat_products_split = explode('&', $data['category_products']);
foreach($cat_products_split as $row) {
    $arr = array();
    parse_str($row, $arr); //This will always work
    list($k, $v) = each($arr);
    if (!empty($k) && !empty($v)) {
        $products[$k] = $v;
    }
}
即可解决后台保存超过1001个产品的问题

if (isset($data['category_products']) &&
                !
$category->getProductsReadonly()) {
                $products 
= array();
                
parse_str($data['category_products']$products);
                
$category->setPostedProducts($products);
            
}

换成

if (isset($data['category_products']) &&
            !
$category->getProductsReadonly()) {
            $products 
= array();
            
$records preg_split('/&/',$data['category_products'],-1,PREG_SPLIT_NO_EMPTY);
            if(
count($records) > 0){
                
foreach($records as $record){
                    $record 
trim($record);
                    if(
preg_match('/([0-9]*)=([0-9]*)/',$record,$matches)){
                        $products[$matches[1]] 
$matches[2];
                    
}
                }
            }
            $category
->setPostedProducts($products);
        
}
可以解决之一个方案在某些情况下,产品变0的问题

 

 

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后台删除产品时同时删除产品图片

原本的magento程序在删除一个产品的时候是不会把产品相关的图片也删除。这样造成两个问题

一是:这样长时间下来,会导致空间里有太多的没用的产品图片,占用太多资源。
二是:在批量倒入时,如果产品图片库有有新倒入的产品图片,造成新倒入的产品图片会更名,造成一个产品多个一样的图片

解决办法(代码是别人写的):

将app/code/core/Mage/Catalog/Model/Product.php
拷到
app/code/local/Mage/Catalog/Model/Product.php
然后在delete函数中的第一行加入以下代码:

foreach ($this->getMediaGallery(‘images’) as $image){

$image_path = $this->getMediaConfig()->getMediaPath($image[‘file’]);
if(file_exists($image_path)){
@unlink($image_path);
}
}
问题即可解决

magento 兰亭模板中首页标签切换三种主要类别的产品图示及代码

买了magento 兰亭模板,将其中自己感觉有用的插件,抽取出来,供大家下载,
以下是首页标签切换三种主要类别的产品图示及代码

附加一个侧边栏中显示卖得最好的商品

代码打包如下:
magento首页标签切换三种主要类型产品代码.zip

调用的语法如下:

<div class="home-bottom">
 <div id="mainmenu">
	<ul id="home-tabs">
	<li><a class="home-active-tab" href="#tab1">Bestsellers</a></li>
	<li><a href="#tab2">Featured Products</a></li>
	<li><a class="last" href="#tab3">Promotion Products</a></li>
	</ul>
 <div>
  <div id="tab1" class="panel">
	<fieldset> <legend>Tab 1 Body</legend> 
    {{block type="bestsellers/list" name="home.bestsellers.list" alias="product_homepage" template="catalog/product/listhome.phtml" }} 
    </fieldset>
  </div>
  <div id="tab2" class="panel">
	<fieldset> <legend>Tab 2 Body</legend> 
    {{block type="catalog/product_list" category_id="34" template="catalog/product/listhome.phtml"}} 
    </fieldset>
  </div>
  <div id="tab3" class="panel">
	<fieldset> <legend>Tab 3 Body</legend>
    {{block type="catalog/product_list" category_id="23" template="catalog/product/listhome.phtml"}} 
    </fieldset>
  </div>
 </div>
</div>

category_id中的目录id,是指将一些特殊的商品放在指定的目录中做作为关注商品和推广商品,如34和23

侧边栏中显示卖得最好的商品的调用语法
<block type="bestsellers/list" name="home.bestsellers.list" alias="product_homepage" template="catalog/product/topdeal.phtml" />

在指定的cms中设置js的引用
  <reference name="head">
        <action method="addItem" ><type>skin_js</type><name>js/scripts.js</name></action>
       <action method="addJs"><script>scriptaculous/slider.js</script></action>
  </reference>

css语法如下:

/* Home Page Tabs */

.home-bottom{width:100%;}

#mainmenu{width:755px; margin-top:8px; float:left}


legend {
	color: #F2F2F2;
}
#banner {


}

.panel {
	clear: both;
	display: none;
    border:1px solid #ddd;
	border-top:none;

}

.panel.active-tab-body {
	display: block;
}
.bar {
	padding: 5px;
	background-color: #3e3e3e;
}

#home-tabs {
	height: 30px;
	list-style: none;
    border:1px solid #ddd;
	border-bottom:none;
}

#home-tabs li {
	float: left;
}

#home-tabs a {
	float: left;
	padding: 2px 8px;
	text-decoration: none;
	color: #000;
	width:234px;
	background:url(../images/sprite_repeat.gif) repeat-x left top; 
	border-bottom:1px solid #ddd;
	border-right:1px solid #ddd;
	height:22px;
	line-height:22px;
	text-align:center;
	font-weight:bold;
	font-size:14px;
}

#home-tabs a:hover{color:#a72d2c; text-decoration:underline;}

#home-tabs a.last{border-right:none;width:235px;}

#home-tabs a.home-active-tab {
	
	background:none;
	border-bottom:none;

}

.products-tab .tab-product-img{float:left; width:90px; }
.products-tab .tab-other-info{float:right; width:150px;}

.cms-home .category-products{padding:10px 0 0 0; }
.cms-home  .products-tab {width:746px; height:106px; margin:5px 0; padding-left:8px; overflow:hidden; border-bottom:1px solid #efefef;}
.cms-home  .products-tab.last{border-bottom:0;}
.cms-home  .products-tab li.item{width:242px; margin:8px 4px 0 0; float:left;}

/* End of Home Page Tabs */

css中涉及的sprite_repeat.gif图片,我就不上传了,哈哈,给大家设置一个小障碍!

几种在magento的cms中显示产品的方法

magento有很多种方法在cms显示产品,下面举些例子说明:

1.显示新产品

进入后台->Page->CMS->home page ,content(内容选项)加入:

{{block type=”catalog/product_new” name=”home.catalog.product.new” alias=”product_homepage” template=”catalog/product/new.phtml”}}

(请注意,您必须要确保你的站点有新的产品,要不然首页就没法显示。所谓的新产品不是传统意义上的你最近添加的产品,而是你在发布产品时指定的某个产品在某个时间段内为新产品。)

2.显示全部产品

同理在content里加入:

{{block type=”catalog/product_list” name=”home.catalog.product.list” alias=”products_homepage” template=”catalog/product/list.phtml”}}

3.一个分类的全部产品

同理在content里加入:

{{block type=”catalog/product_list” name=”home.catalog.product.list” alias=”products_homepage” category_id=”4″ template=”catalog/product/list.phtml”}}

category_id为分类的ID,可以在分类列表中查看。

Magento EasyTabs插件升级成产品说明内定义标签

Magento EasyTabs是一个将magento产品页内几个要素用标签页tabs的形式进行展示.
主要是产品说明,产品附加说明,评论,推荐商品等,用tabs的形式进行组织,
但是zen-cart的一个与些类似的插件,可以在产品说明内容中定义标签,这样比较容易扩展,而magento EasyTabs却没这功能,与是我升级了这个插件,核心代码就是一段,我把全部代码贴出来.
app/design/frontend/default/default/template/easytabs/tabs.phtml

$_temp_products_description_class=Mage::getBlockSingleton('catalog/product_view_description')->getProduct();
$_description_text=$_temp_products_description_class->getDescription();	

	$FindEnd 	= explode("<!--@EndTabs@-->", $_description_text); 	// Find where the EndTabs override is reached
		$CstmTags 	= explode("<!--%", $FindEnd[0]);			// Parse Custom Tags up to the EndTabs tag
        $ZenTags     = explode("<!--#", $FindEnd[0]);            // Parse Zen Tags up to the EndTabs tag

			$sName[0]='Description';
			$sText[0] = '';
			if (count($CstmTags) >= 1) {
			if ($CstmTags[0] != "") { // check for text before the tabs
				$sName[0]='Description';
				$sText[0] = $CstmTags[0];
			}
			//Create a tab for each custom tag
			for ($g = 1; $g < count($CstmTags); $g++) {
				$sTmp = explode("%-->", $CstmTags[$g]);
				$sName[$g] = $sTmp[0];
				$sText[$g] = $sTmp[1];

            	}
		}

?>

<ul class="tabs">
    <?php

		 foreach ($this->getTabs() as $_index => $_tab): ?>
        <?php if($this->getChildHtml($_tab['alias']) && strlen(strip_tags(trim($this->getChildHtml($_tab['alias']))))>0): ?>
        	<?php
				$tab_title = $_tab['title'];
        		$tab_is_custom = strpos($_tab['alias'], 'custom');
				$tab_is_cms= strpos($_tab['alias'], 'cms');
				if($tab_is_custom === 0){
        			$tab_is_tmp_id =  substr($_tab['alias'], 6);
        			$tab_is_custom_id = (!empty($tab_is_tmp_id)) ? $tab_is_tmp_id : '';
					$tab_title = Mage::getStoreConfig('easy_tabs/custom/customtabname'.$tab_is_custom_id);
        		} elseif($tab_is_cms === 0) {
					$tab_is_tmp_id =  substr($_tab['alias'], 3);
        			$tab_is_custom_id = (!empty($tab_is_tmp_id)) ? $tab_is_tmp_id : '';
					$tab_title = Mage::getStoreConfig('easy_tabs/customcms/tabnamecms'.$tab_is_custom_id);
        		} 

				if('description_tabbed'==$_tab['alias']) {
					for ($a = 0; $a < count($sName); $a++) {   ?>
					<li id="product_tabs_<?php echo $sName[$a].'_tabbed'; ?>" <?php echo (!$_index && $a==0) ? 'class="active first"' : '' ?>><a href="#"><?php echo $this->__($sName[$a]); ?></a></li>
		<?php 		}
				}
				else {  ?>
				<li id="product_tabs_<?php echo $_tab['alias'] ?>" <?php echo !$_index ? 'class="active first"' : '' ?>><a href="#"><?php echo $tab_title; ?></a></li>
	   <?php 	}     	?>

        <?php endif; ?>
    <?php endforeach; ?>
</ul>
<div class="padder">
    <?php foreach ($this->getTabs() as $_index => $_tab): ?>
        <?php if($this->getChildHtml($_tab['alias'])):
			if('description_tabbed'==$_tab['alias']) {
					for ($a = 0; $a < count($sText); $a++) {   ?>
          		  <div id="product_tabs_<?php echo $sName[$a].'_tabbed'; ?>_contents"><?php echo $this->helper('catalog/output')->productAttribute($_temp_products_description_class, $sText[$a], 'description'); ?></div>
			<?php 	 }
				} else {  ?>
				<div id="product_tabs_<?php echo $_tab['alias'] ?>_contents"><?php echo $this->getChildHtml($_tab['alias']); ?></div>
		   <?php 	} 	?>
        <?php endif; ?>
    <?php endforeach; ?>
</div>

将这段代码放到文件对应的部分就可以了,然后在产品说明中定义大致如下的:
The Nokia 2610 is an easy to use device that combines multiple messaging options including email, instant messaging, and more. You can even download MP3 ringtones, graphics, and games straight to the phone, or surf the Internet with Cingular's MEdia Net service.
<!–%begin%–>
It's the perfect complement to Cingular service for those even remotely interested in mobile Web capabilities in an affordable handset.<br><br>

<!–%Design%–>
<b>Design</b><br>
Compact and stylish, the 2610 features a candybar design sporting a bright 128 x 128 pixel display capable of displaying over 65,000 colors. Most of the phone's features and on-screen menus are controlled by a center toggle on the control pad. A standard hands-free headphone jack is provided, as are volume control keys, and there's even a "Go-To" button that can be assigned by the user for quick access to favorite applications. Lastly, the included speakerphone allows you to talk handsfree, and because the phone sports an internal antenna, there's nothing to snag or break off.

其中<!–%begin%–>和<!–%Design%–>是标签头的语法,效果图如下:

当然,还可以像zen-cart那个tabs插件那样,功能更强点,但相想实际运行中,上述的功能就够了,大家可以试试.
以下是下载地址和magento-connect.
http://www.magentocommerce.com/magento-connect/TemplatesMaster/extension/1725/magento-easytabs
magento-community/magento_easy_tabs

如何在magento首页显示指定目录的产品

1.首先现在magento后台创建一个新的分类,记下这个分类的 ID 号码。使用这个新建的分类来管理你的首页产品,这个分类设置为前台不可见。这样就不会显示在你的分类菜单中了,但使用代码调用的时候却会显示出来。

2.在cms–>manage page–>home 适当位置添加如下代码(例如代码的最后)

在magento1.3以及之前的版本请使用如下代码

{{block type=”catalog/product_list” category_id=”3” template=”catalog/product/list.phtml“}}

在magento1.4的版本中请使用如下的XML代码

<reference name="content">
   <block type="catalog/product_list" name="featured" template="catalog/product/list.phtml">
       <action method="setCategoryId"><category_id>[category id here]</category_id></action>
   </block>
 </reference>

代码解释如下:
我们在magento后台新建一个分类,向这个分类中添加的产品会在首页显示。在magneto成功添加一个分类后,会给这个分类分配一个ID。红色部分“category_id”的值“3”既是此分类ID。“list.phtml”既是此产品列表的模板样式文件。

XML中的template是指模板路径,[category id here],包括中括号都删掉换成你的分类的ID号。如果想在首页显示产品,这段xml加在 后台CMS homepage这个page的layout update中。如下图