在Magneto中使用一个xml文件更新布局
Magento有很多的xml布局文件,我们在修改更新布局文件时,就要去找相对应的.xml文件。我分享下通过一个local.xml文件就可以修改整个Magento网站的布局。
在app/frontend/default/你的主题/layout下新建一个local.xml,在里面写你需要更新的布局就可以了。记得在 头部加入
1 2 | < ?xml version="1.0"?> <layout version="0.1.0"></layout> |
可能一些朋友不懂magento如何布局,我接下来简单的介绍下:
1.更新添加block
1 2 3 | <reference name="left"> <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/> </reference> |
2.删除block
1 | <remove name="catalog.leftnavr" /> |
3.添加删除js
1 2 3 4 5 6 7 | <!-- 删除JS--> <reference name="head"> <action method="removeItem"><type>js</type><name>lib/ds-sleight.js</name></action> </reference> <!-- 添加JS --> <action method="addItem"><type>skin_js</type><name>lib/ds-sleight.js</name></action> |
关于布局更新还有其他问题,可留言联系我。
Magento加速利器——lazyload
Magento的速度是令人头疼的问题,我现在介绍一种前端的加速方法。说到lazyload,相信很多人都不陌生,现在很多网站都已经用到这个技术,他可以延迟加载长页面的图片。对于Magento这样的商城网站的加速就很明显了。我今天说的这个lazyload是经过POPO改造的(强逼我给他加外连……)。下面我放一些测试的数据,我正在做的一个网站的列表页。
![]()
![]()
很明显的就能看出差距。接下来写下用法:
首先加上jQuery,lazyload两段js。
read more
Magento产品直接进入结账页面
Magento在产品页增加个立即购买的按钮,跳过购物车页面直接进入结账页面。这个是今天客户提的需求,用了个简单的jQuery解决了这个问题。当然如果你的网站没有用到jQuery的话,就直接用JS写吧。
一、在addtocart.phtml中加入<a href=”<?php echo $this->getBaseUrl() ?>checkout/onepage/” id=”checknow”>立即购买</a>。
二、给加入购物车的按钮加个id=“addtocart”。
三、加入以下jQuery,
1 2 3 4 5 | <script type="text/javascript"> jQuery("#checknow").click(function(){ jQuery("#addtocart").click(); } ) </script> |
这个方法存在一定的缺陷就是,结账的时候会把所有购物车里的产品一起结了,不过客户就是要这样的结果,
Magento中添加Flash
Magento加Flash这个问题,让我纠结了下今天。一般的Flash是很好加的,我说下带有xml等文件的Flash的加法。
一、在根目录下创建一个文件夹swf,把Flash相关的东西放入。
二、新建一个Static Block加入以下内容(注意把其中的文件夹和文件名改为相对应的内容):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <script type="text/javascript"> AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0', 'width','900', 'height','400', 'src','swf/name_of_your_flash_banner', 'quality','high', 'menu','false','base','.', 'pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','swf/name_of_your_flash_banner' ); //end AC code </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="900" height="400" title="name_of_your_flash_banner"> <param name="movie" value="swf/name_of_your_flash_banner.swf" /> <param name="quality" value="high" /> <param name="menu" value="false"> <param name="wmode" value="transparent"> <param name="base" value="." /> <embed src="swf/name_of_your_flash_banner.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="900" height="400"></embed> </object> </noscript> |
三、在你需要导入flash 的地方,导入这个block。
四、在该页面加入一个JS,AC_RunActiveContent.js
我是通过以上方法在Magento中加入Flash的,如有其他更加的方法,欢迎和我探讨下
Magento批量上传
Magento批量上传在,Magento中是个很重要的功能。介绍下一般的产品批量上传。
一、先在后台添加个产品,然后把这个产品在导出导出那里导出.csv表格。
二、用excel打开就可以看到批量上传需要的格式了。
三、把产品图片上传到/media/upload/创建子目录命名XXX/下。
四、在批量文件里填写图片信息,举例如下:
image /test/test1.jpg
small_image /test/test1.jpg
thumbnail /test/test1.jpg
五、按照导出的格式把其他Magento数据都填写完整之后就批量导入这个批量文件
注意:
1.一定要先上传图片,之后才可以上传批量文件,要不然前台看不到图片。
2.SKU是整个网站唯一的,不可以重复,否则以后上传的同名就会覆盖以前的产品。
以上就是Magento批量上传的简单方法,大家可以尝试下。改自magentochina.org
Magento 1.4.0.1升级到1.4.10报错
Magento1.4.0.1升级到1.4.1.0后会报错Fatal error: Call to a member function toHtml() on a non-object in /home/www/yourMagento/html/gamemore/app/code/core/Mage/Core/Model/Layout.php on line 529。
在magentochina.org找到了答案。
打开layout/page.xml,找到
尝试下吧……
Magento清除缓存
Magento清除缓存有两种方法。
一、打开后台system——>Cache Management,refresh就是清除缓存,Disable是禁用缓存,在上线前,建议禁用缓存,Enable打开缓存。
二、直接删除var中的文件,var就在根目录下。
Magento清除缓存的方法就这两种
Magento开启模板提示
Magneto模板提示对于开发很有用,今天很多人问起,在这里写下。
打开后台system——>Configuration,左边最后的选项 developer。不要忘记选择左上角的商店。
在debug选项中的Template Path Hints选择为yes就可以了。

到magento前台看看效果吧
Magento1.4.1.0出来了
Magento终于更新了,今天惊喜的发现Magento更新到1.4.1.0了。明天会翻译下,更新的相关内容……
Magento产品多图片批量上传
Magento添加产品是件很头疼的事情,因此我们就就需要批量上传。magento默认不支持多图片批量上传,要经过一些修改才可以,我转载了magentochina蟋蟀的文章过来,嘿嘿……
一、到/app/etc/modules/ 目录下创建文件并命名为YDL_ImportMultipleImages.xml 该文件会告诉Magento你有这样的模块,以及它的位置。
1 2 3 4 5 6 7 8 9 | <?xml version="1.0"?> <config> <modules> <YDL_ImportMultipleImages> <active>true</active> <codePool>local</codePool> </YDL_ImportMultipleImages> </modules> </config> |
二、创建文件 /app/code/local/YDL/ImportMultipleImages/etc/config.xml
这个文件是你的模块配置文件。它告诉 Magento哪个阶级我们将重写。详细点就是到你的/app/code/local 先新建YDL文件夹,再进入YDL里面新建 ImportMultipleImages 文件夹,接着再进入里面新建etc文件夹,最后进入新建config.xml 文件.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?xml version="1.0"?> <config> <modules> <YDL_ImportMultipleImages> <version>0.1.0</version> </YDL_ImportMultipleImages> </modules> <global> <models> <catalog> <rewrite> <!-- Override Mage_Catalog_Model_Convert_Adapter_Product --> <convert_adapter_product>YDL_ImportMultipleImages_Model_Convert_Adapter_Product</convert_adapter_product> </rewrite> </catalog> </models> </global> </config> |
三、创建文件 /app/code/local/YDL/ImportMultipleImages/Model/Convert/Adapter/Product.php 此文件中扩大了saveRow() 类方法,这样保证了当你的magento升级后仍然能够使用多图片批量上传功能。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | <?php /** * Import Multiple Images during Product Import * */ class YDL_ImportMultipleImages_Model_Convert_Adapter_Product extends Mage_Catalog_Model_Convert_Adapter_Product { /** * Save product (import) * * @param array $importData * @throws Mage_Core_Exception * @return bool */ public function saveRow(array $importData) { $product = $this->getProductModel() ->reset(); if (empty($importData['store'])) { if (!is_null($this->getBatchParams('store'))) { $store = $this->getStoreById($this->getBatchParams('store')); } else { $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'store'); Mage::throwException($message); } } else { $store = $this->getStoreByCode($importData['store']); } if ($store === false) { $message = Mage::helper('catalog')->__('Skip import row, store "%s" field not exists', $importData['store']); Mage::throwException($message); } if (empty($importData['sku'])) { $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'sku'); Mage::throwException($message); } $product->setStoreId($store->getId()); $productId = $product->getIdBySku($importData['sku']); if ($productId) { $product->load($productId); } else { $productTypes = $this->getProductTypes(); $productAttributeSets = $this->getProductAttributeSets(); /** * Check product define type */ if (empty($importData['type']) || !isset($productTypes[strtolower($importData['type'])])) { $value = isset($importData['type']) ? $importData['type'] : ''; $message = Mage::helper('catalog')->__('Skip import row, is not valid value "%s" for field "%s"', $value, 'type'); Mage::throwException($message); } $product->setTypeId($productTypes[strtolower($importData['type'])]); /** * Check product define attribute set */ if (empty($importData['attribute_set']) || !isset($productAttributeSets[$importData['attribute_set']])) { $value = isset($importData['attribute_set']) ? $importData['attribute_set'] : ''; $message = Mage::helper('catalog')->__('Skip import row, is not valid value "%s" for field "%s"', $value, 'attribute_set'); Mage::throwException($message); } $product->setAttributeSetId($productAttributeSets[$importData['attribute_set']]); foreach ($this->_requiredFields as $field) { $attribute = $this->getAttribute($field); if (!isset($importData[$field]) && $attribute && $attribute->getIsRequired()) { $message = Mage::helper('catalog')->__('Skip import row, required field "%s" for new products not defined', $field); Mage::throwException($message); } } } $this->setProductTypeInstance($product); if (isset($importData['category_ids'])) { $product->setCategoryIds($importData['category_ids']); } foreach ($this->_ignoreFields as $field) { if (isset($importData[$field])) { unset($importData[$field]); } } if ($store->getId() != 0) { $websiteIds = $product->getWebsiteIds(); if (!is_array($websiteIds)) { $websiteIds = array(); } if (!in_array($store->getWebsiteId(), $websiteIds)) { $websiteIds[] = $store->getWebsiteId(); } $product->setWebsiteIds($websiteIds); } if (isset($importData['websites'])) { $websiteIds = $product->getWebsiteIds(); if (!is_array($websiteIds)) { $websiteIds = array(); } $websiteCodes = split(',', $importData['websites']); foreach ($websiteCodes as $websiteCode) { try { $website = Mage::app()->getWebsite(trim($websiteCode)); if (!in_array($website->getId(), $websiteIds)) { $websiteIds[] = $website->getId(); } } catch (Exception $e) {} } $product->setWebsiteIds($websiteIds); unset($websiteIds); } foreach ($importData as $field => $value) { if (in_array($field, $this->_inventoryFields)) { continue; } if (in_array($field, $this->_imageFields)) { continue; } $attribute = $this->getAttribute($field); if (!$attribute) { continue; } $isArray = false; $setValue = $value; if ($attribute->getFrontendInput() == 'multiselect') { $value = split(self::MULTI_DELIMITER, $value); $isArray = true; $setValue = array(); } if ($value && $attribute->getBackendType() == 'decimal') { $setValue = $this->getNumber($value); } if ($attribute->usesSource()) { $options = $attribute->getSource()->getAllOptions(false); if ($isArray) { foreach ($options as $item) { if (in_array($item['label'], $value)) { $setValue[] = $item['value']; } } } else { $setValue = null; foreach ($options as $item) { if ($item['label'] == $value) { $setValue = $item['value']; } } } } $product->setData($field, $setValue); } if (!$product->getVisibility()) { $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE); } $stockData = array(); $inventoryFields = isset($this->_inventoryFieldsProductTypes[$product->getTypeId()]) ? $this->_inventoryFieldsProductTypes[$product->getTypeId()] : array(); foreach ($inventoryFields as $field) { if (isset($importData[$field])) { if (in_array($field, $this->_toNumber)) { $stockData[$field] = $this->getNumber($importData[$field]); } else { $stockData[$field] = $importData[$field]; } } } $product->setStockData($stockData); $imageData = array(); foreach ($this->_imageFields as $field) { if (!empty($importData[$field]) && $importData[$field] != 'no_selection') { if (!isset($imageData[$importData[$field]])) { $imageData[$importData[$field]] = array(); } $imageData[$importData[$field]][] = $field; } } foreach ($imageData as $file => $fields) { try { $product->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . $file, $fields); } catch (Exception $e) {} } /** * Allows you to import multiple images for each product. * Simply add a 'gallery' column to the import file, and separate * each image with a semi-colon. */ try { $galleryData = explode(';',$importData["gallery"]); foreach($galleryData as $gallery_img) /** * @param directory where import image resides * @param leave 'null' so that it isn't imported as thumbnail, base, or small * @param false = the image is copied, not moved from the import directory to it's new location * @param false = not excluded from the front end gallery */ { $product->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . $gallery_img, null, false, false); } } catch (Exception $e) {} /* End Modification */ $product->setIsMassupdate(true); $product->setExcludeUrlRewrite(true); $product->save(); return true; } } |
四、在编写好你的csv文件后,需要在你的csv文件里增加一列并命名为gallery,然后在此列中把你想要上传的产品图片分别用半角英文分号“;” 隔开,举个例子吧:
你的gallery 这一列 必需类似于 / image1.jpg;/ image2.jpg;/ image3.jpg。你可以在后台->系统(System)->设置(Configuration)->高级(Advanced)里面高级选项-“模块输出”里看到你添加的模块 ydl_ImportMultipleImages。只要你csv文件里的其它产品属性字段没有错误,保证你的多个图片能成功的显示在你的 magento网店中。
Magento批量上传图片已经成功了。
转载自:Magnetochina
紫月蓝骋