検索
ホームページphp教程php手册magento でよく使われる関数、magento でよく使われる関数

magento 常用的函数,magento常用函数

1.Magento eav_attribute表中source如何指定自定义数据来源
  如果你引用的类名为yebihai_usermanage_model_entity_school你必须完整的给出地址,不能usermanage/entity_school,这样默认是在Mage下面去找的。
  如:

$setup->addAttribute('customer', 'school', array( 'type' => 'int', 'input' => 'select', 'label' => 'School', 'global' => 1, 'visible' => 1, 'required' => 0, 'user_defined' => 1, 'default' => '0', 'visible_on_front' => 1, 'source'=> 'yebihai_usermanage_model_entity_school', //数据来源,text留空即可 ));


2.Magento getPrice()的结果小数点位数的处理
echo Mage::helper('core')->currency($_product->getPrice()); 
输出格式:888.673 => 888.67

3.Magento config.xml中global节点中的block重写与blocks下面的命名标签必须小写,如:


                                                Yebihai_CategoryList_Block_Category_View                                                                              Yebihai_CategoryList_Block                            


4.Magento获取列表当前排序方式ASC or DESC?
获取当前排序:$this->getAvailableOrders()
获取当前分页:$this->getCurrentPage()
列表页的各种内容获取都在:Mage_Catalog_Block_Product_List_Toolbar这个类里面,有需要直接去这里面找。

5.Magento Collection添加排序?

$subCategories = Mage::getModel('catalog/category')->getCollection(); $subCategories->setOrder('position', 'ASC');


6.Magento Collection where里面的或条件如何实现?

$result = $selfread->select()->from( $table, array('id'))  ->where( 'reid = '.$reid,'topid ='.$reid);//reid=$reid 或 topid=$reid


7.Magento操作某条数据下面的多个字段,使用场景如下:
本 人在做订单备注的时候在监听类里面通过Magento系统的addStatusHistoryComment方法把订单内容能成功写入 sales_flat_order_status_history表,但是我的需求是还要修改is_visible_on_front此字段的值,让内容 在前台可见。头痛的问题来了,想了各种方法最后按下面的方式解决了。
监听类全部源码:

class Yebihai_CustomerOrderComments_Model_Observer   { public function setCustomerOrderComments(Varien_Event_Observer $observer) { $_order = $observer->getEvent()->getOrder(); $_request = Mage::app()->getRequest(); $_comments = strip_tags($_request->getParam('customerOrderComments')); if(!empty($_comments)){ $_order->setCustomerNote('
订单备注: ' .$_comments); $_order->addStatusHistoryComment('订单备注: ' .$_comments)->setIsVisibleOnFront(1); } return $this; } }

8.Magento个人中心左侧菜单控制
关于个人中心的主要功能都是在customer这个模块进行,需要修改相应的功能,直接去你的模板customer文件夹去修改。
左侧菜单模板路径:customer/account/navigation.phtml
9.Magento把html转换为转义字符,用什么方法?
core助手里面有一个escapeHtml方法,使用如下:
Mage::helper('core')->escapeHtml("yebihai 加油

go
");
メソッドの実際の場所: Mage_Core_Helper_Abstract クラス内。
ps: いくつかの一般的な操作メソッドはコア モジュールにカプセル化されています。必要に応じて、ソース コードを分析できます。

10. Magento は動的にブロックを作成しますアクションを参照しますか?

以下は、Ajax を介して checkoutcart を動的に呼び出す必要がある場合、どうすれば解決できますか? simplecheckout/cart_item_renderer                             ステップ 1: ajax を介してカスタム コントローラーを呼び出します。例:
jQuery.post('getUrl('gou​​wuche/cart/updateQuickShoppingCar') ?>', function(data){ jQuery('#shopping-cart-table thead').after(data); }); ステップ 2: コントローラー メソッドで次のようなブロックを動的に作成します。 パブリック関数 updateQuickShoppingCarAction(){ $block = $this->getLayout()->createBlock('checkoutrewrite/quickcart')->setTemplate('quickbuy/cart/cart.phtml'); echo $block->toHtml(); }
ステップ 3: 新しいブロック ファイル (クイックカート) を作成し、このファイルの構築メソッドで構成ファイル内のアクション コンテンツを次のように初期化します。 パブリック関数 __construct() { 親::__construct(); $this->addItemRender('simple', 'checkout/cart_item_renderer', 'quickbuy/cart/item/item_view.phtml'); }
追記: 2 番目のステップに進むと、cart.phtml テンプレートが読み込まれています。3 番目のステップは、カート ブロックの下にアクションを読み込むだけです。


11. MagentoのgetTableメソッドのパラメータで注意すべきことは何ですか?
例、データベース内の指定したテーブルと条件をクエリする方法は次のとおりです。 パブリック関数 getExcelKucunJiage($id,$status){ $selfread = $this->_getConnection('excelmanage_read'); $table = $this->getTable('excelmanage/excelkucunjiage'); $result = $selfread->select() ->from( $table ) ->where( 'excel_id=?', $id) ->where( 'is_active=?', $status); return $selfread->fetchRow($result); }
getTable メソッドのパラメータ設定は次のように注意する必要があります。excelmanage はモジュールの名前であり、excelkukunjiage は操作するエンティティ ノードの名前です。私のエンティティ構成は次のとおりです。 Yebihai_ExcelManage_Model_Resource_Mysql4

excelkucunjiage

「/」の後のパラメータは、テーブルの前にあるエンティティ名から派生します。


12. データテーブル内の指定されたID情報を更新するにはどうすればよいですか?

$excelModel = Mage::getModel('excelmanage/excelkucunjiage')->load(1); $excelModel->setExcelAdddate(Mage::getModel('core/date')->timestamp(time( ))); $excelModel->setIsActive(0);
$excelModel->save();
上記のコードは、ID 1 のデータ テーブル情報を変更するものです。
拡張: Magento で指定されたテーブル情報を追加および変更するにはどうすればよいですか?


13. 商品リストのデフォルトの並べ替えフィールドを変更するにはどうすればよいですか?

次の場所にパスを設定します: システム -> カタログ -> 高度な製品管理 -> デフォルト リスト ステータス
14. データ セット内の項目の数を取得します。

_productCollection データセット内のアイテムの数を取得します。ケースは次のとおりです。 $this->setStoreId($storeId);

$this->_productCollection = Mage::getResourceModel('catalog/product_collection') //データセットを取得します

$this->_productCollection = $this->_productCollection->addAttributeToSelect('*')

->addAttributeToSelect('manufacturer') //クエリ属性を追加します

->setStoreId($storeId) //ストアを設定します

->addAttributeToFilter('cuxiaobiaoqian',array('eq'=>39)) //属性フィルタリング仕様

->addStoreFilter($storeId) //店舗フィルター条件を追加します

->setPageSize(6) //アイテム数を取得します

;

15. select() メソッドを通じて指定されたデータテーブルをクエリする方法、読み取られる項目の数を制御する方法

コードアプリケーションの背景は次のとおりです:

$selfread = $this->_getConnection('yafo_bbs_setup'); //データベース接続オブジェクト

$table = $this->zixunTablePrefix."forum_post" //クエリ対象のテーブル

$result = $selfread->select()->from( array('a'=>$table), array('tid','subject')) //テーブルとフィールドを指定します質問されました

->limit($size) //指定された数のアイテムを読み込みます

->order("a.dateline DESC") //ソート条件を指定

->where( $selfwhere ) //フィルター条件を追加します

Return $selfread->fetchAll($result) //クエリ結果を返す

16. 指定した商品価格とグループ価格を変更しますか(コード操作)?

$selfPrc = Mage::getModel('カタログ/製品')->load(614); $selfData = $selfPrc->getData(); $selfData['価格'] = 25; $selfData['group_price'] = array( 0 =>配列(                                                        "website_id" => 0、                            "すべてのグループ" => 0、                            "cust_group" => 0、                            「価格」=> 97.0000、                            "website_price" => 97.0000                        )、                      1=>配列                        (                            "website_id" => 0、                            "すべてのグループ" => 0、                            "cust_group" => 1、                            「価格」=> 27.0000、                            "website_price" => 27.0000                        )、                      2=>配列                        (                            "website_id" => 0、                            "すべてのグループ" => 0、                            "cust_group" => 2、                            「価格」=> 17.0000、                            "website_price" => 17.0000                        )、                      3=>配列                        (                           "website_id" => 0、                            "すべてのグループ" => 0、                            "cust_group" => 3、                            「価格」=> 67.0000、                            "website_price" => 67.0000                        )、                      4=>配列                        (                            "website_id" => 0、                            "すべてのグループ" => 0、                            "cust_group" => 4、                            「価格」=> 66.0000、                            "website_price" => 66.0000                        )); $selfPrc->setData($selfData); $selfPrc->save();


17.修正指定品库存(代码操作)?

$selfPrc = Mage::getModel('カタログ/製品')->load(614); $aa = Mage::getModel("cataloginventory/stock_item")->loadByProduct($selfPrc); $selfaa = $aa->getData(); $selfaa['数量'] = 23; $aa->setData($selfaa); $aa->save();


18.SQL 语をどのように出力するか
$result = $selfread->select()->from(array('ft'=>$ flatTable),array())

->join(array('pc'=>$prcCategory),'ft.entity_id=pc.entity_id',array('pc.value')) ->where( 'ft.attribute_set_id=?', $attsetid) ->where( 'pc.attribute_id=?', $attid) ->group("pc.value"); // $result をエコーし​​ます。 exit;//出句sql语


19.后台表单配置、代网里面追加备注?

$fieldset->addField('dict_grade', 'select', array( '名前' => 'dict_grade', 'ラベル' => Mage::helper('catalogsearchrewrite')->__('高度な検索 Ciku グレード管理'), 'タイトル' => Mage::helper('catalogsearchrewrite')->__('高度な検索 Ciku グレード管理'), 「タイプ」 => 「オプション」、 'オプション' => Mage::getSingleton('catalogsearchrewrite/cikumanage')->getCikuGradeOptionArray(), 'after_element_html' => Mage::helper('catalogsearchrewrite')->__('キーワード グレード 説明。')、//after_element_htmlこのプロパティは用来追加备注 '必須' =>真実、 ) );


20.实例化モデル、load メソッドを介して指定されたフィールドをどのように取得しますか?
$dictModel=Mage::getModel('catalogsearchrewrite/cikumanage')->load($dictname,'dict_name');  //パラメータ1:指定值、パラメータ2:指定文字段

$dictModel->getDictName(); //取得して返される指定されたフィールド值

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

SublimeText3 英語版

SublimeText3 英語版

推奨: Win バージョン、コードプロンプトをサポート!

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)