magento 1.x 方法总结
来源:互联网 发布:2016软件人均产值 编辑:程序博客网 时间:2024/06/05 04:28
1 collection: 使用count 会使整个纪录load。 使用count后 ,collection 在使用 limit 会失效。获取 collection total 可以使用 方法 getSize()(该方法会使用另一个sql语句,会忽略 limit 的设置)
例:
Mage::getModel('catalog/product')->getCollection ->getSize()
collection 分页方法:
getCollection()->->setCurPage($page)->setPageSize($limit)
2 购物车商品列表问题
有关collectTotals() 方法问题
在调用collectTotals 的时候 ,程序是通过$this->getCheckoutSession()->getQuote() 获取有关购物车的商品,如果此时将购物车中的商品在后台禁用,而前台用户没有退出的情况,购物车列表会无法加载(报出: 嵌套的方法数量已经达到上限)。前台用户退出后,才可以正常访问购物车列表。
建议: 上线的商品,不要禁用,正确的方式是让商品售罄,由用户主动删除。或者将商品设置为过期商品
3 配置magneto 移动端和pc端的不同样式包
在system->general->design->package->增加匹配
匹配表达式:
phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone
value:包名
4 通过 configurable product 获取simple product
$configurableProduct = Mage::getModel('catalog/product')->load(1); $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$configurableProduct); foreach($childProducts as $child) { echo $child->getId();}
如果仅获取 simple product ids
$childProductsId = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($configproductid);
5 magento 各版本下载地址
https://www.magentocommerce.com/download?_ga=1.17642041.1692527827.1477279402
6 获取购物车 详细报错信息的方法
foreach ($quote->getAllItems() as $quoteItem) { if ($errorItems = $quoteItem->getErrorInfos()) { foreach ($errorItems as $errorItem) { if ($errorItem['code'] == Mage_CatalogInventory_Helper_Data::ERROR_QTY) { $quote->addErrorInfo( 'error', 'cataloginventory', Mage_CatalogInventory_Helper_Data::ERROR_QTY, Mage::helper('cataloginventory')->__('Not all products are available in the requested quantity') ); return; } } } }
7 订单save 操作,对sales_flat_order_address 自定义字段的操作
<checkout_submit_all_after> <observers> <auto_set_custom_field> <class>module/observer</class> <method>method</method> </auto_set_custom_field> </observers> </checkout_submit_all_after> public function method($observe){ // 获取保存后的order 信息 $order=$observe->getEvent()->getOrder(); ... }
8 获取configurable product 商品信息形式如下:
"product_options": [ { "product_id": "2154", "attributes": [ { "attribute_id": "92", "attribute_code": "color", "attribute_label": "Color", "option_id": "178", "option_label": "奶油色" }, { "attribute_id": "202", "attribute_code": "size", "attribute_label": "size", "option_id": "132", "option_label": "One size" } ], "price": 1280, "qty": 11111 } ]
代码如下:
function getProductOptions($currentProduct){ $productOptionData = array(); foreach ($this->getAllowProducts($currentProduct) as $product) { $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product); $productOption = array( "product_id" => (int)$product->getId(), "attributes" => array(), "price" => $currentProduct->getFinalPrice(), "qty" => (int)$stock->getQty() ); foreach ($this->getAllowAttributes($currentProduct) as $attribute) { $productAttribute = $attribute->getProductAttribute(); $productAttributeId = $productAttribute->getId(); $attributeValue = $product->getData($productAttribute->getAttributeCode()); $optionPriceData = $attribute->getPrices()[array_search($attributeValue, array_column($attribute->getPrices(), 'value_index'))]; $productOption['attributes'][] = array( "attribute_id" => $productAttributeId, "attribute_code" => $productAttribute->getAttributeCode(), "attribute_label" => $productAttribute->getStoreLabel(), "option_id" => $attributeValue, "option_label" => $optionPriceData['label'] ); if ($optionPriceData['is_percent']) { $productOption['price'] += ($optionPriceData['pricing_value'] * $productOption['price'] / 100); } else { $productOption['price'] += $optionPriceData['pricing_value']; } } $productOptionData[] = $productOption; } return $productOptionData; } function getAllowProducts($product) { $products = array(); $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck(); if ($typeInstance = $product->getTypeInstance(true)) { if ($typeInstance instanceof Mage_Catalog_Model_Product_Type_Configurable) { $allProducts = $product->getTypeInstance(true)->getUsedProducts(null, $product); foreach ($allProducts as $p) { if ($p->isSaleable() || $skipSaleableCheck) { $products[] = $p; } } } } return $products; } function getAllowAttributes($product) { if ($typeInstance = $product->getTypeInstance(true)) { if ($typeInstance instanceof Mage_Catalog_Model_Product_Type_Configurable) { return $typeInstance->getConfigurableAttributes($product); } } return array(); }
- magento 1.x 方法总结
- Magento 1.x 入门之系列教程一
- magento---EAV模型----总结!!
- Magento安装总结
- magento中的attribute 总结
- magento学习总结
- magento 安装问题总结
- magento 事物总结
- magento getUrl 总结列表
- Magento加速的方法
- magento Url重写方法
- magento 常用方法
- MAGENTO 调试方法
- magento 常用方法
- magento 常用方法
- Magento日期相关方法
- magento搬家的方法
- magento常用方法整理
- 加盟申请表
- iOS 异步请求等待传值方法小结
- org.junit 注解
- Redis 简介
- 如何保证http传输安全性
- magento 1.x 方法总结
- 工作流管理系统开发之二 工作流引擎
- 员工团队风采页面
- jsp+jquery+ajax+json 实例
- Mybatis的一对多,多对一以及延迟加载
- android studio在XML预览中出现Rendering Problems问题
- Linux系统文件目录权限详解 - rwx
- mvc框架思想,从混编开始升级(一)
- Android studio用正式签名调试