Category: WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra

Magento: addAttributeToFilter 和 addFieldToFilter 的区别 Difference between addAttributeToFilter and addFieldToFilter

addAttributeToFilter is used to filter EAV collections and will filter the products based on the attributes that you’ve included in your collection. EAV-models: product, customer, sales, etc. addFieldToFilter is used to filter Non-EAV collections and will filter the products based… Read More

Magento: 后台获取menu链接 Getting the admin panel urls

The url for customer page in the admin panel. index.php/admin/customer/edit/id/7 echo Mage::helper('adminhtml')->getUrl('adminhtml/customer/edit/index/id',array('id'=>7)); The url for catalog product page in the admin panel. index.php/admin/catalog_product/edit/id/166 echo Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit/index/id',array('id'=>166)); The url for sales order in the admin panel. index.php/admin/sales_order/view/order_id/8 echo Mage::helper('adminhtml')->getUrl('adminhtml/sales_order/view/order_id/',array('order_id'=>8)); The url for… Read More

Magento: 在客户账户中添加自定义链接 My Account Add Link

This extension add new link and a page to that link and enable/disable links in my account left Nav section. 页面: https://www.magentocommerce.com/magento-connect/my-account-add-link.html Magento Connect 2.0 : http://connect20.magentocommerce.com/community/ng_customer 下载:  ng_customer-1.0.2—-customer-account-page   本文: Magento: 在客户账户中添加自定义链接 My Account Add Link… Read More

Magento: 根据产品属性加载产品信息 Load A Category or Product by an Attribute

Load a Product by ID <?php // get product model by product id, assuming you have known product id, $productId $_product = Mage::getModel('catalog/product')->load($productId) Load a Product by SKU <?php $sku = 'my-product-sku'; $product = Mage::getModel('catalog/product')->load($sku, 'sku'); if ($product->getId()) { echo… Read More

Magento模块开发之数据库SQL操作方法说明

今天主要来看Magento中的Mysql4/Resource(资源) 如何对数据库进行操作, 来执行更为复杂的 sql 语句。 在Magento中Model 通常都会继承 Mage_Core_Model_Abstract, 而这个 Abstract 又继承了Varien_Object, 在 Abstract 类中包含许多常用的方法,例如: getId(), load(), save(), delete() 等等…而 Mysql4/Resource Model 则继承 Mage_Core_Model_Mysql4_Abstract, 而这个 Abstract 又继承了 Mage_Core_Model_Resource_Abstract SQL 和 Mysql4 Resource 文件 Mysql4/Resource(资源) 文件, 用来和数据库中的表打交道,执行各类的数据库查询,在下面我会展示如何在 Resource(资源) 文件中进行 SQL 语句操作。 SELECT… Read More

Magento: 通过id获取类别名字等信息 get category by id

<?php // get category model by category id, assume you have known category id, $categoryId $_category = Mage::getModel('catalog/category')->load($categoryId); // category name $categoryName = $_category->getName(); // category description $categoryDescription = $_category->getDescription(); // category url $categoryUrl = $_category->getUrl(); // category url key… Read More

Magento事件与事件监听

事件和事件监听也许是magento中最有趣的功能之一,因为它允许开发者来扩展magento应用程序中的关键部分。 为了为不同模块之间提供更多的灵活性和便利,magento使用了一种事件/监听模式,这种模式允许模块之间进行松散耦合。 在这个系统中有两部分,一部分是事件分发对象和事件信息,另一部分是监听特定的事件。 一、事件分发 事件的创建和分 发使用Mage::dispatchEvent() 函数。核心团队已经在一些核心关键部分创建了一些事件,例如,模型抽象类Mage_Core_Model_Abstract 在一个模型每次保存的时候调用了两个protected函数—— _beforeSave() 和_afterSave() ;在这些方法中有两个事件被触发。 protected function _beforeSave() { if (!$this->getId()) { $this->isObjectNew(true); } Mage::dispatchEvent('model_save_before', array('object'=>$this)); Mage::dispatchEvent($this->_eventPrefix.'_save_before', $this->_getEventData()); return $this; } protected function _afterSave() { $this->cleanModelCache(); Mage::dispatchEvent('model_save_after', array('object'=>$this)); Mage::dispatchEvent($this->_eventPrefix.'_save_after', $this->_getEventData()); return $this; } Mage::dispatchEvent()… Read More

Magento: 获取类别所有子类别 (无限级别-目录树) Get All Sub Categories

生成分类目录树(Category Tree) $rootcatId = Mage::app()->getStore()->getRootCategoryId(); $categories = Mage::getModel('catalog/category')->getCategories($rootcatId); function get_categories($categories) { $array = '<ul>'; foreach ($categories as $category) { $cat = Mage::getModel('catalog/category')->load($category->getId()); $count = $cat->getProductCount();

Magento: 获取产品评论 get all reviews with review summary

1. 根据产品id获取该产品评论 $productId = 1234; $product = Mage::getModel('catalog/product')->load($productId); $storeId = Mage::app()->getStore()->getId(); Mage::getModel('review/review')->getEntitySummary($product, $storeId); $ratingSummary = $product->getRatingSummary(); print_r($ratingSummary->getData()); 结果是: Array ( [primary_id] => 27 [entity_pk_value] => 16 [entity_type] => 1 [reviews_count] => 3 [rating_summary] => 51 [store_id] => 1 ) 结果解释如下:… Read More

解决WP表前缀更换后出现的You do not have sufficient permission

将安装的wordpress表前缀由默认的 wp_修改为其它了,再次登陆后台后出现 You do not have sufficient permissions to access this page. 网上搜索了一下,说是修改检查 wp_usermeta 表中的 wp_capabilities, wp_user_level 数值,但是无效,再搜索发现如下方法解决问题 步骤1. 将wp_usermeta 表中对应wp_前缀设置的 wp_capabilities, wp_user_level,wp_autosave_draft_ids 的前缀 wp_ 修改为新的前缀 步骤2. 将wp_options 中wp_user_roles 前缀 wp_ 修改为新的前缀 或者在phpmyadmin中执行如下语句: UPDATE `{%TABLE_PREFIX%}usermeta` SET `meta_key` = replace(`meta_key`, '{%OLD_TABLE_PREFIX%}',… Read More