ããã©ãŒãã³ã¹ã®åé¡ããã£ãã»ãšãã©ãã¹ãŠã®Magentoãããžã§ã¯ãã§èŠããšã©ãŒã«ã€ããŠã話ããããšæããŸãã Magentoã䜿çšããå Žåãä»äººã®ã³ãŒããç£æ»ããå¿ èŠãããå ŽåããããŸãã ãããã£ãŠãããªãã®ãµã€ãã®ããã©ãŒãã³ã¹ãæ¹åããå°æ¥ã®ééããé¿ããã®ã«åœ¹ç«ã€çµéšãããªããšå ±æããããšæããŸãã
ãã®èšäºã§ã¯ãMagento 1ã«ã€ããŠèª¬æããŠããŸãã*ãã ãã説æãããŠããããšã¯Magento 2ã«ãåœãŠã¯ãŸããŸãã
ããã©ãŒãã³ã¹ã®åé¡ãããã»ãšãã©ãã¹ãŠã®ãããžã§ã¯ãã§ã次ã®ãããªãã®ãèŠã€ããããšãã§ããŸãã
$temp = array(); $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*'); foreach ($collection as $product) { $product = $product->load($product->getId()); $temp[] = $product->getSku(); }
ééã£ã
ã®ä»£ããã«
$temp = array(); $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('sku'); foreach ($collection as $product) { $temp[] = $product->getSku(); }
ããã ã
ãã®çç±ã¯éåžžã«ç°¡åã§ãã
- ããŒãåŸãå¿ èŠãªå±æ§ã¯ãããŸãã
- ã€ã³ã¿ãŒãããã®ãããã°ã©ããŒããããã§ã
- ãæªåããªãããšããååã«åŸã£ãŠãäœåãªå±æ§ãããŒããã
äœãééã£ãŠããã®ããããã©ãŒãã³ã¹ã§äœãã§ããã®ããç解ããã«ã¯ãã³ã¬ã¯ã·ã§ã³ã®æäœã«éäžããããšããå§ãããŸãã
ãããŠãã¡ããçµè«ã
EAV /ãã©ããããŒãã«
EAVã¯ãå±æ§ãå±ãããšã³ãã£ãã£ãå±æ§èªäœãããã³ãã®å€ãç°ãªãããŒãã«ã«é 眮ãããŠããå Žåã®ããŒã¿ã¹ãã¬ãŒãžã¢ãããŒãã§ãã
Magentoã®EAVãšã³ãã£ãã£ã«ã¯ã補åãã«ããŽãªãã«ã¹ã¿ã ã¡ãŒã¿ãŒãäœæã®ã«ã¹ã¿ã ã¢ãã¬ã¹ãå«ãŸããŸãã å±æ§èªäœã¯eav_attributeããŒãã«ã«ä¿åãããŸãã
Magento 5ã®åèšå±æ§å€ã¿ã€ãã¯ãtextãvarcharãintãdecimalãããã³datetimeã§ãã ãã1ã€ã®ã¿ã€ãããããŸããéçã§ãããšã³ãã£ãã£ãå«ãããŒãã«ã«ãããšããç¹ã§ä»ã®5ã€ã®ã¿ã€ããšç°ãªããŸãã
å±æ§ããŒãã«ã¯ããã®ããŒãã«ãŸãã¯ãã®å±æ§ãã©ã®ããŒãã«ãŸãã¯ã©ã®ã¿ã€ãã§ãããã瀺ããMagentoã¯ãã§ã«ã©ãã«æžã蟌ãããã©ãããèªã¿åãããç¥ã£ãŠããŸãã
ãã®ãããªå€ã®æ ŒçŽã«ãããã»ããã®å±æ§ãéåžžã«ç°¡åã«å®è£ ã§ããŸãïŒåãšã³ãã£ãã£ãç¬èªã®å±æ§ãæã€ããšãã§ããå ŽåããŸãã¯ãŸã£ããæããªãå ŽåïŒãæ°ããå±æ§ã®è¿œå ã¯ããŒã¿ããŒã¹å ã®ãã1è¡ã§ãã å¥ã®ã¹ãã¢ã®1ã€ã®å±æ§ã«æ°ããå€ãè¿œå ããŸãã-ãã®å±æ§ã®å€ã®è¡šã®æ°ããè¡ã
ããŒã¿ããŒã¹ã«ä¿åãããæ¹æ³
ãšã³ãã£ãã£ïŒ
補å-catalog_product_entityã
ã«ããŽãª-catalog_category_entityã
顧客-customer_entityã
顧客ã®äœæ-customer_address_entity
å±æ§ïŒ
eav_attribute
catalog_eav_attribute
customer_eav_attribute
å€ïŒ
* _text
* _varchar
* _int
* _decimal
* _datetime
補å-catalog_product_entityã
ã«ããŽãª-catalog_category_entityã
顧客-customer_entityã
顧客ã®äœæ-customer_address_entity
å±æ§ïŒ
eav_attribute
catalog_eav_attribute
customer_eav_attribute
å€ïŒ
* _text
* _varchar
* _int
* _decimal
* _datetime
ãã©ããã¯ããã¹ãŠã1ãæã«ãããäžå¿ èŠãªäœæ¥ãªãã§è£œåãšãã®ãã¹ãŠã®å±æ§ãååŸããããã«è¿œå ã®ããŒãã«ãå¿ èŠãšããªããç§ãã¡å šå¡ã«éŠŽæã¿ã®ããã¢ãããŒãã§ã-SELECT * FROM plate WHERE id = some kind of id and that'sã
EAVãšã³ãã£ãã£ããããã©ãã衚瀺ã¯ã«ããŽãªãšååã«ã®ã¿äœ¿çšã§ããŸãã
ããŒã¿ããŒã¹ã«ä¿åãããæ¹æ³
補åïŒ
catalog_product_flat_1 // * _N store_view
ã«ããŽãªãŒïŒ
catalog_category_flat_1 // * _N store_view
catalog_product_flat_1 // * _N store_view
ã«ããŽãªãŒïŒ
catalog_category_flat_1 // * _N store_view
ãã©ããããŒãã«ã«å±æ§ãå«ããäžè¬ã«ãã©ããããŒãã«ã®äœ¿çšãæå¹ã«ããã«ã¯ã次ã®æé ãå®è¡ããŸãã
管çããã«ã®[ã«ã¿ãã°]> [å±æ§]> [å±æ§ã®ç®¡ç]
å±æ§ã«æ¬¡ã®å€ã®ãããããããå ŽåãMagentoã¯å±æ§ããã©ããããŒãã«ã«è¿œå ããŸãã
管çããã«ã®[ã·ã¹ãã ]> [æ§æ]> [ã«ã¿ãã°]
Magentoã¯ã以äžã«ãªã¹ããããŠãããšã³ãã£ãã£ã«å¯ŸããŠãã©ããããŒãã«ã䜿çšããŸãã
å±æ§ã«æ¬¡ã®å€ã®ãããããããå ŽåãMagentoã¯å±æ§ããã©ããããŒãã«ã«è¿œå ããŸãã
管çããã«ã®[ã·ã¹ãã ]> [æ§æ]> [ã«ã¿ãã°]
Magentoã¯ã以äžã«ãªã¹ããããŠãããšã³ãã£ãã£ã«å¯ŸããŠãã©ããããŒãã«ã䜿çšããŸãã
次ã®äºå®ã«æ³šæããŠãã ããã
- ãã©ããããŒãã«ã¯ãã«ããŽãªããŒãžãã°ã«ãŒã補åã®è£œåãªã¹ããããã³å®éã«ã³ã¬ã¯ã·ã§ã³ã䜿çšãããŠããå Žæã§ã®ã¿äœ¿çšãããŸãã ã¢ãã«ã§loadã¡ãœããã䜿çšããå Žåã管çããã«ã®è£œåããŒãžã§ã¯äœ¿çšãããŸããã
- ãã©ããããŒãã«ãæå¹ã«ããåŸãã€ã³ããã¯ã¹ãåäœæããå¿ èŠããããŸããããããªããšãMagentoã¯åŒãç¶ãEAVããŒãã«ã®ã¿ã䜿çšããŸã
- ãã©ããããŒãã«ãæå¹ã«ããåŸãMagentoã¯åŒãç¶ãEAVã䜿çšããŸãããå€æŽãä¿åãããšãã«ãã©ããããŒãã«ãžã®å€æŽã®ã³ããŒãéå§ããŸã
ãªãããããã¹ãŠå¿
èŠãªã®ãããªããã©ããã¢ãããŒããã©ãã§ã䜿çšããªãã®ãïŒ é·æãšçæã®ããããããŒãã«ãèŠãŠãã ãã
EAVïŒ
+ Flatãããæè»ãªã·ã¹ãã
+æ°ããå±æ§ãè¿œå ãããšãã«ããŒã¿ã®ã€ã³ããã¯ã¹ãåäœæããå¿ èŠã¯ãããŸãã
+ã»ãŒç¡å¶éã®æ°ã®å±æ§
+ãã¹ãŠã®å±æ§ã¯åžžã«å©çšå¯èœã§ãã
+æ瀺çã«æå®ãããŠããªããŠããéçå±æ§ïŒskuãcreated_atãupdated_atïŒã¯åžžã«éžæç¯å²ã«ååšããŸã
-èŽåœçãšã©ãŒïŒååšããªãå±æ§ã®ååŸ/ãã£ã«ã¿ãªã³ã°æã«ã¡ã³ããŒé¢æ°getBackendïŒïŒãåŒã³åºã
-ããã©ãŒãã³ã¹
ãã©ããïŒ
+ããã©ãŒãã³ã¹
+ãã©ããããŒãã«ã«è¿œå ãããæ¢åã®å±æ§ã®ã¿ãéžæ/ãã£ã«ã¿ãªã³ã°ã«é©çšã§ããŸã
-è¡ãµã€ãºïŒæ倧65,535ãã€ããã€ãŸã85 varchar 255ïŒããã³åæ°ïŒInnoDBã¯æ倧1000ãäžéšã¯æ倧4096ïŒã®å¶é
-ã³ã¬ã¯ã·ã§ã³ã䜿çšããå Žåã«ã®ã¿äœ¿çšãããŸãïŒããŒãæã«ã¯åžžã«EAVã䜿çšãããŸãïŒ
-çµæã¯ãEAVã䜿çšãããªã¯ãšã¹ãã®çºè¡ãšã¯ç°ãªããŸãïŒéçå±æ§ãªãïŒ
-ã€ã³ã¯ã«ãŒãã®åã€ã³ããã¯ã¹ãå¿ èŠãªå Žåãããã§ãªãå Žåã¯EAVããŒãã«ã䜿çšãããŸã
-æ°ããå±æ§ãè¿œå ããå Žåããã©ããããŒãã«ã®ã€ã³ããã¯ã¹ãåäœæããå¿ èŠããããŸã
+ Flatãããæè»ãªã·ã¹ãã
+æ°ããå±æ§ãè¿œå ãããšãã«ããŒã¿ã®ã€ã³ããã¯ã¹ãåäœæããå¿ èŠã¯ãããŸãã
+ã»ãŒç¡å¶éã®æ°ã®å±æ§
+ãã¹ãŠã®å±æ§ã¯åžžã«å©çšå¯èœã§ãã
+æ瀺çã«æå®ãããŠããªããŠããéçå±æ§ïŒskuãcreated_atãupdated_atïŒã¯åžžã«éžæç¯å²ã«ååšããŸã
-èŽåœçãšã©ãŒïŒååšããªãå±æ§ã®ååŸ/ãã£ã«ã¿ãªã³ã°æã«ã¡ã³ããŒé¢æ°getBackendïŒïŒãåŒã³åºã
-ããã©ãŒãã³ã¹
ãã©ããïŒ
+ããã©ãŒãã³ã¹
+ãã©ããããŒãã«ã«è¿œå ãããæ¢åã®å±æ§ã®ã¿ãéžæ/ãã£ã«ã¿ãªã³ã°ã«é©çšã§ããŸã
-è¡ãµã€ãºïŒæ倧65,535ãã€ããã€ãŸã85 varchar 255ïŒããã³åæ°ïŒInnoDBã¯æ倧1000ãäžéšã¯æ倧4096ïŒã®å¶é
-ã³ã¬ã¯ã·ã§ã³ã䜿çšããå Žåã«ã®ã¿äœ¿çšãããŸãïŒããŒãæã«ã¯åžžã«EAVã䜿çšãããŸãïŒ
-çµæã¯ãEAVã䜿çšãããªã¯ãšã¹ãã®çºè¡ãšã¯ç°ãªããŸãïŒéçå±æ§ãªãïŒ
-ã€ã³ã¯ã«ãŒãã®åã€ã³ããã¯ã¹ãå¿ èŠãªå Žåãããã§ãªãå Žåã¯EAVããŒãã«ã䜿çšãããŸã
-æ°ããå±æ§ãè¿œå ããå Žåããã©ããããŒãã«ã®ã€ã³ããã¯ã¹ãåäœæããå¿ èŠããããŸã
ãã£ãã·ã¥
ãã¡ãããããŒã¿ããŒã¹å ã®ã¯ãšãªãé«éåããæ¹æ³ãšããã£ãã·ã¥ãç§ãã¡ãä¿åãããã¹ãŠããã£ãã·ã¥ãããŠããå Žåãäžè¬ã«ã³ã¬ã¯ã·ã§ã³ãã©ã®ããã«åäœããããç解ããå¿ èŠãããã®ã¯ããªãããããã§ãã ç°¡åã«çããŸã-ãã£ãã·ã¥ã¯ããªããæããŸããã Magentoã«è¡šç€ºããããã£ãã·ã¥ã¯ãã³ã¬ã¯ã·ã§ã³ãèªåçã«ãã£ãã·ã¥ããããããŒã¿ã®ã€ã³ããŒãæãäœãã®ã«ãŠã³ãæãªã©ã«äœ¿çšããã«ã¹ã¿ã ã³ã³ãããŒã©ãŒãã¢ãã«ã§åäœããŸããã ããã«ããã£ãã·ã¥ã«å ¥ããåã«ããªãããã®æ¹æ³ã§ãã£ãã·ã¥ã«å ¥ããŠããã«ãŠãŒã¶ãŒã«è¡šç€ºããå¿ èŠãããããã§ãã
Magento 1ã®ãã£ãã·ã¥ã®çš®é¡ã*ïŒ
- æ§æ -æ§æãã¡ã€ã«ããã£ãã·ã¥ããŸã
- ã¬ã€ã¢ãŠã -ã¬ã€ã¢ãŠããã¡ã€ã«ããã£ãã·ã¥ããŸã
- HTMLåºåãããã㯠-phtmlãã³ãã¬ãŒãããã£ãã·ã¥ããŸã ã ããã©ã«ãã§ã¯ããããã¡ãã¥ãŒãšããã¿ãŒã®ããã³ããšã³ãã§ã®ã¿äœ¿çšãããŸãã
- 翻蚳 -CSV CSVãã¡ã€ã«ã®ãã£ãã·ã¥
- ã³ã¬ã¯ã·ã§ã³ããŒã¿ --> initCacheïŒ...ïŒã¡ãœããã䜿çšããã³ã¬ã¯ã·ã§ã³ããã£ãã·ã¥ããŸãã ããã©ã«ãã§ã¯ãcore_storeãcore_store_groupãcore_websiteã³ã¬ã¯ã·ã§ã³ã®ã¿ãåæåäžã«ãã£ãã·ã¥ãããŸãã
- EAVã¿ã€ããšå±æ§ -eavå±æ§ããã£ãã·ã¥ããå¿ èŠããããŸããããã£ãã·ã¥ã¯ããŸããã Magneto CE 1.4以éã¯åŒã³åºãããªã1ã€ã®ã¡ãœããã§äœ¿çšãããŸã
- WebãµãŒãã¹ãã£ãã·ã¥-api.xmlãã¡ã€ã«ããã£ãã·ã¥ããŸã
- ããŒãžãã£ãã·ã¥ ïŒFPCïŒ-ãã¹ãŠã®HTMLããã£ãã·ã¥ããCMSãã«ããŽãªã補åããŒãžã®ã¿ããã£ãã·ã¥ããŸãã httpsãããã³ã«ã®å Žåããã©ã¡ãŒã¿ãŒãååŸããŠãç¡èŠãããŸããïŒNo_cache = 1ãCookie NO_CACHE
- DDLãã£ãã·ã¥ ïŒé衚瀺ïŒ-ããŒã¿ããŒã¹ãžã®DESCRIBEåŒã³åºãããã£ãã·ã¥ããŸããæžã蟌ã¿æäœã§äœ¿çšãããŸã
...ãããŠã³ã¬ã¯ã·ã§ã³ãèªåçã«ãã£ãã·ã¥ãããã®ã¯ãããŸããã
ã³ã¬ã¯ã·ã§ã³ã®é©åãªäœæ¥
å€ãã®äººã以åãšã¯ç°ãªãæ¹æ³ã§äœããè¡ãå¿ èŠãããçç±ãããæ確ã«ç€ºãããã«ãããŸããŸãªã¢ãããŒãã®ããã©ãŒãã³ã¹ãã¹ããè¡ãããšã«ããŸããã ãã¹ããã³ãããå§ããŸãããã ãã¹ãã«ã¯ã次ã®ãã®ã䜿çšããŸããã
ãã¹ãã¹ã¿ã³ãïŒ
OS X 10.10
3.1 GHz Intel Core i5ïŒ4ã³ã¢ïŒ
8GB
Magentoã®æ§æïŒ
Magento EE 1.14.0
MySQL 5.5.38
PHP 5.6.2
å 容ïŒ
3ã€ã®ã«ããŽãªãŒ
2000補å
2000 CMSããŒãž
ããã»ã¹ïŒ
ãã¹ãã§ã¯ã1ã€ã®ã³ã³ãããŒã©ãŒãš1ã€ã®ã¢ã¯ã·ã§ã³ã§æ¡åŒµæ©èœãäœæãããåãã¹ãã5åå®è¡ãããåŸãå¹³åæéãèšç®ãããŸããã ãã¹ãŠã®çµæã¯ç§åäœã§ãã
class Test_Test_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { $temp = array(); $start = microtime(true); Init values Loop start $temp[] = $product->getSku(); Loop end Or Some code snippet $stop = microtime(true); echo $stop - $start; } }
æ¬äŒŒã³ãŒã
ãã¹ã
- ã¢ãã«ããªããŒãããå Žåãšããªãå Žåã®EAV /ãã©ãã
- ã³ã¬ã¯ã·ã§ã³ã®ãã£ãã·ã¥
- countïŒïŒããã³getSizeïŒïŒã®é©åãªäœ¿çš
- getFirstItemããã³setPageïŒ1,1ïŒã®é©åãªäœ¿çš
ã¢ãã«ããªããŒãããå Žåãšããªãå Žåã®EAV /ãã©ãã
åéãµã€ã¯ã«ã ã«ãŒãå ã«ããŒãïŒãªããŒãïŒã¢ãã«ãããå ŽåïŒ
$temp = array(); $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect(...); foreach ($collection as $product) { $product = $product->load($product->getId()); $temp[] = $product->getSku(); }
åéãµã€ã¯ã«ã å éšã«è² è·ã¢ãã«ããªãå ŽåïŒ
$temp = array(); $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect(...); foreach ($collection as $product) { $temp[] = $product->getSku(); }
3çš®é¡ã®ããŒã¿ãµã³ããªã³ã°ïŒ
- addAttributeToSelectïŒ '*'ïŒ; //ãã¹ãŠã®å±æ§
- addAttributeToSelectïŒ 'sku'ïŒ; // 1ã€ã®éçå±æ§
- addAttributeToSelectïŒ 'name'ïŒ; // 1ã€ã®æšæºå±æ§
çµæ
ãæ°ã¥ããããããŸããããã¢ãã«ããªããŒãããªãå Žåã®æéã¯ãã¢ãã«ããªããŒãããå Žåãããçãæéã§ãã ãŸãããã©ããããŒãã«ãæå¹ã«ãªã£ãŠããå ŽåïŒã€ãŸããäœåãªçµåãçµåããªãå ŽåïŒã«ã¯æéãããã«çããªããå¿ èŠãªå±æ§ã®ã¿ãéžæããŸãã
æåã®ã±ãŒã¹ã§ã¯ãå€ãã®çµåã§èµ·åããŸã...ãããŠããããå床è¡ããŸãããã¢ãã«ã®å Žåã¯2000åã§ãã
2åç®ã¯ãå±æ§éçïŒè£œåèªäœãšåãã©ãã«ã«ãããŸãïŒã«å¯ŸããŠãããè¡ããMagentoã¯çµåãè¡ãå¿ èŠããããŸããã ãããã£ãŠãæéãçããªããŸãã
3床ç®ã«ãMagentoã¯ãã®å±æ§ãä¿åãããŠããå¥ã®ãã¬ãŒããã¢ã¿ããããå¿ èŠããããŸãã
ãã©ããããŒãã«ã§ã¯ãã¹ãŠã䌌ãŠããŸããã2ã€ã®å Žåã¯ãã¹ãŠåãã§ããããã¯ãäž¡æ¹ã®å±æ§ã1ã€ã®ããŒãã«ã«ãããããæéãåãã§ããããã§ãã
æ°åã¯ãããç©èªã£ãŠãããšæããŸãã
ãæ°ã¥ããããããŸããããã¢ãã«ããªããŒãããªãå Žåã®æéã¯ãã¢ãã«ããªããŒãããå Žåãããçãæéã§ãã ãŸãããã©ããããŒãã«ãæå¹ã«ãªã£ãŠããå ŽåïŒã€ãŸããäœåãªçµåãçµåããªãå ŽåïŒã«ã¯æéãããã«çããªããå¿ èŠãªå±æ§ã®ã¿ãéžæããŸãã
æåã®ã±ãŒã¹ã§ã¯ãå€ãã®çµåã§èµ·åããŸã...ãããŠããããå床è¡ããŸãããã¢ãã«ã®å Žåã¯2000åã§ãã
2åç®ã¯ãå±æ§éçïŒè£œåèªäœãšåãã©ãã«ã«ãããŸãïŒã«å¯ŸããŠãããè¡ããMagentoã¯çµåãè¡ãå¿ èŠããããŸããã ãããã£ãŠãæéãçããªããŸãã
3床ç®ã«ãMagentoã¯ãã®å±æ§ãä¿åãããŠããå¥ã®ãã¬ãŒããã¢ã¿ããããå¿ èŠããããŸãã
ãã©ããããŒãã«ã§ã¯ãã¹ãŠã䌌ãŠããŸããã2ã€ã®å Žåã¯ãã¹ãŠåãã§ããããã¯ãäž¡æ¹ã®å±æ§ã1ã€ã®ããŒãã«ã«ãããããæéãåãã§ããããã§ãã
æ°åã¯ãããç©èªã£ãŠãããšæããŸãã
ã³ã¬ã¯ã·ã§ã³ã®ãã£ãã·ã¥
ãã£ãã·ã¥ãªãïŒ
$collection = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*');
initCacheã¡ãœããã®äœ¿çšïŒ
$collection = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*') ->initCache(Mage::app()->getCache(),'our_data',array('SOME_TAGS'));
ã«ã¹ã¿ã ãã£ãã·ã¥ã®å®è£ ïŒ
$cache = Mage::app()->getCache(); $collection = $cache->load('our_data'); if(!collection) { $collection = Mage::getModel('collection/product')->getCollection()->addAttributeToSelect('*')->getItems(); $cache->save(serialize($collection),'our_data',array(Mage_Core_Model_Resource_Db_Collection_Abstract::CACHE_TAG)); } else { $collection = unserialize($collection); }
ãã£ãã·ã¥ã䜿çšããã«ãMagentoãæäŸããæ¹æ³ã䜿çšãããã£ãã·ã¥ã¢ãã«ã®æ¹æ³ã«åºã¥ããŠãã©ãã«ãèŠãããšããªãæŸèæã䜿çšãããµã³ãã«ãèããŠã¿ãŸãããã ãã¹ãŠã®ãã¹ãã§ããªã¯ãšã¹ããã³ã³ãã€ã«ããåŸãããŒã¿ãããŒãããã³ã¬ã¯ã·ã§ã³ããªããžã§ã¯ãã®é åã«å€æããããšã«æ³šæããŠãã ããã
çµæ
ãã£ãã·ã¥ããªããã°ãå®éã«ã¯é©ãã¹ãããšã¯äœããããŸãã...ãã¹ãŠãéåžžéãã§ãã
ããããããŒã³ã¿ã®ãã£ãã·ã¥ã䜿çšããŠãæéãé·ããªã£ãã®ãèŠãŠé©ããã EAVã³ã¬ã¯ã·ã§ã³ã¯æåã«ååããŒãã«ãããšã³ãã£ãã£ãèªã¿èŸŒãããïŒããã¯ãŸãã«ãã£ãã·ã¥ãããŠãããã®ã§ãïŒãããããå¥ã®ãªã¯ãšã¹ãã§å±æ§å€ãéžæãããªããžã§ã¯ããåãããããäžè¬çã«EAVãã£ãã·ã³ã°ã¯æããªä»äºã§ãã ããã®ãã©ããã§ã¯ã1ã€ã®ããŒãã«ã®ãã¹ãŠã远跡ãããŸãã ããããããã§ããããŒã¿ããŒã¹ã䜿çšããããããã£ãã·ã¥ã䜿çšããæ¹ãæéãããããŸãïŒãã¡ã€ã«ã·ã¹ãã ãšredisã®äž¡æ¹ã§ãã¹ãããŸãã-ã«ã³ãã®åŸã®4æ¡ç®ãç°ãªããŸã...ã€ãŸãã2kãšã³ãã£ãã£ã«ã¯ååšããŸããïŒã InitCacheã¡ãœããã®æ¬è³ªã¯ãæåã«ã³ã¬ã¯ã·ã§ã³èªäœã®ãã¹ãŠã®ããŒã¿ïŒããŒãžããŒã·ã§ã³ããã£ã«ã¿ãŒãã€ãã³ããªã©ïŒãåéããsqlèŠæ±ããããã·ã¥ãäœæããŠãã£ãã·ã¥å ã§æ€çŽ¢ããããã«äœããããå Žåã anserlsizesããã¹ãŠã®ã€ãã³ããšåŸç¶ã®ã¡ãœãããèµ·åãããŸãã ããã¯ããã»ã¹å šäœã§æãé ãæé ã§ããããŒã¿ããŒã¹å ã®åçŽãªã¯ãšãªããããã£ãã·ã¥ãé ãã®ã¯ããã§ãã ãããããã®åŸãããŒã¿ããŒã¹ã«ãªã¯ãšã¹ããéä¿¡ããŸãã...ãã§ã«ããã»ã©æãã¯ãããŸããã
ç§ãã²ãã®äžã«æžãããã£ãã·ã¥ã䜿çšããå¥ã®äŸããããŸããããã§ãã³ã¬ã¯ã·ã§ã³ã®æçµçµæããã£ãã·ã¥ãããã¹ãŠã®ã€ãã³ãããã€ãã¹ããŠå±æ§ãããŒãããŸãã ããã¯ãEAVããã³ãã©ããã³ã¬ã¯ã·ã§ã³ã§æ©èœããŸãã
ãã£ãã·ã¥ããªããã°ãå®éã«ã¯é©ãã¹ãããšã¯äœããããŸãã...ãã¹ãŠãéåžžéãã§ãã
ããããããŒã³ã¿ã®ãã£ãã·ã¥ã䜿çšããŠãæéãé·ããªã£ãã®ãèŠãŠé©ããã EAVã³ã¬ã¯ã·ã§ã³ã¯æåã«ååããŒãã«ãããšã³ãã£ãã£ãèªã¿èŸŒãããïŒããã¯ãŸãã«ãã£ãã·ã¥ãããŠãããã®ã§ãïŒãããããå¥ã®ãªã¯ãšã¹ãã§å±æ§å€ãéžæãããªããžã§ã¯ããåãããããäžè¬çã«EAVãã£ãã·ã³ã°ã¯æããªä»äºã§ãã ããã®ãã©ããã§ã¯ã1ã€ã®ããŒãã«ã®ãã¹ãŠã远跡ãããŸãã ããããããã§ããããŒã¿ããŒã¹ã䜿çšããããããã£ãã·ã¥ã䜿çšããæ¹ãæéãããããŸãïŒãã¡ã€ã«ã·ã¹ãã ãšredisã®äž¡æ¹ã§ãã¹ãããŸãã-ã«ã³ãã®åŸã®4æ¡ç®ãç°ãªããŸã...ã€ãŸãã2kãšã³ãã£ãã£ã«ã¯ååšããŸããïŒã InitCacheã¡ãœããã®æ¬è³ªã¯ãæåã«ã³ã¬ã¯ã·ã§ã³èªäœã®ãã¹ãŠã®ããŒã¿ïŒããŒãžããŒã·ã§ã³ããã£ã«ã¿ãŒãã€ãã³ããªã©ïŒãåéããsqlèŠæ±ããããã·ã¥ãäœæããŠãã£ãã·ã¥å ã§æ€çŽ¢ããããã«äœããããå Žåã anserlsizesããã¹ãŠã®ã€ãã³ããšåŸç¶ã®ã¡ãœãããèµ·åãããŸãã ããã¯ããã»ã¹å šäœã§æãé ãæé ã§ããããŒã¿ããŒã¹å ã®åçŽãªã¯ãšãªããããã£ãã·ã¥ãé ãã®ã¯ããã§ãã ãããããã®åŸãããŒã¿ããŒã¹ã«ãªã¯ãšã¹ããéä¿¡ããŸãã...ãã§ã«ããã»ã©æãã¯ãããŸããã
ç§ãã²ãã®äžã«æžãããã£ãã·ã¥ã䜿çšããå¥ã®äŸããããŸããããã§ãã³ã¬ã¯ã·ã§ã³ã®æçµçµæããã£ãã·ã¥ãããã¹ãŠã®ã€ãã³ãããã€ãã¹ããŠå±æ§ãããŒãããŸãã ããã¯ãEAVããã³ãã©ããã³ã¬ã¯ã·ã§ã³ã§æ©èœããŸãã
countïŒïŒããã³getSizeïŒïŒã®é©åãªäœ¿çš
getSizeïŒïŒ
$size = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*') ->getSize();
ã«ãŠã³ãïŒïŒ
$size = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*') ->count();
çµæ
ã¡ãœããã®éãã¯ã countïŒïŒãã³ã¬ã¯ã·ã§ã³å ã®ãã¹ãŠã®ãªããžã§ã¯ããããŒãããéåžžã®phpã«ãŠã³ãã§ãªããžã§ã¯ãã®æ°ãã«ãŠã³ãããæ°ãè¿ãããšã§ãã getSizeã¯ã³ã¬ã¯ã·ã§ã³ãããŒãããŸããããå¶éã泚æãéžæå¯èœãªå±æ§ã®ãªã¹ãããªããCOUNTïŒ*ïŒã®ã¿ãååšããããŒã¿ããŒã¹ãžã®èŠæ±ãããã«1ã€çæããŸãã
äž¡æ¹ã®æ¹æ³ã®äœ¿çšäŸã¯æ¬¡ã®ãšããã§ãã
ããŒã¿ããŒã¹ã«å€ããããã©ããããŸãã¯ãã®æ°ãç¥ãå¿ èŠãããå Žåã¯ãgetSizeã䜿çšããŸããã³ã¬ã¯ã·ã§ã³ãããŒãããå¿ èŠãããå ŽåããŸãã¯æ¢ã«ããŒããããŠããå Žåã¯countïŒïŒã䜿çšããŸããã³ã¬ã¯ã·ã§ã³ã«ããŒããããèŠçŽ ã®æ°ãè¿ããŸãã
ã¡ãœããã®éãã¯ã countïŒïŒãã³ã¬ã¯ã·ã§ã³å ã®ãã¹ãŠã®ãªããžã§ã¯ããããŒãããéåžžã®phpã«ãŠã³ãã§ãªããžã§ã¯ãã®æ°ãã«ãŠã³ãããæ°ãè¿ãããšã§ãã getSizeã¯ã³ã¬ã¯ã·ã§ã³ãããŒãããŸããããå¶éã泚æãéžæå¯èœãªå±æ§ã®ãªã¹ãããªããCOUNTïŒ*ïŒã®ã¿ãååšããããŒã¿ããŒã¹ãžã®èŠæ±ãããã«1ã€çæããŸãã
äž¡æ¹ã®æ¹æ³ã®äœ¿çšäŸã¯æ¬¡ã®ãšããã§ãã
ããŒã¿ããŒã¹ã«å€ããããã©ããããŸãã¯ãã®æ°ãç¥ãå¿ èŠãããå Žåã¯ãgetSizeã䜿çšããŸããã³ã¬ã¯ã·ã§ã³ãããŒãããå¿ èŠãããå ŽåããŸãã¯æ¢ã«ããŒããããŠããå Žåã¯countïŒïŒã䜿çšããŸããã³ã¬ã¯ã·ã§ã³ã«ããŒããããèŠçŽ ã®æ°ãè¿ããŸãã
getFirstItemããã³setPageïŒ1,1ïŒã®é©åãªäœ¿çš
getFirstItemïŒïŒ
$product = Mage::getModel('catalog/product')->getCollection() ->getFirstItem();
setPageïŒ1,1ïŒ
$product = Mage::getModel('catalog/product')->getCollection() ->setPage(1,1) ->getFirstItem();
è² è·ïŒïŒ
$product = Mage::getModel('catalog/product')->load(22);
çµæ
getFirstItemã®åé¡ã¯ãã³ã¬ã¯ã·ã§ã³å šäœãããŒãããŠãããforeachã®æåã®èŠçŽ ãè¿ãã ãã§ãããã§ãªãå Žåã¯ç©ºã®ãªããžã§ã¯ããè¿ãããšã§ãã
setPageïŒå¥å$ this-> setCurPageïŒ$ pageNumïŒ-> setPageSizeïŒ$ pageSizeïŒïŒã¯ãéžæç¯å²ãå³å¯ã«1ã¬ã³ãŒãã«å¶éããŸããããã«ãããçµæã®ããŒããå€§å¹ ã«é«éåãããŸãã
èªã¿èŸŒã¿ã§ãgetFirstItemããé«éã§ããã1ã€ã®èŠçŽ ã®ã³ã¬ã¯ã·ã§ã³ããååŸãããããèªã¿èŸŒã¿ãé ããªãããšã«æ³šæããŠãã ããã ããã¯ãããŒããåžžã«EAVããŒãã«ã§æ©èœããããã§ãã
getFirstItemã®åé¡ã¯ãã³ã¬ã¯ã·ã§ã³å šäœãããŒãããŠãããforeachã®æåã®èŠçŽ ãè¿ãã ãã§ãããã§ãªãå Žåã¯ç©ºã®ãªããžã§ã¯ããè¿ãããšã§ãã
setPageïŒå¥å$ this-> setCurPageïŒ$ pageNumïŒ-> setPageSizeïŒ$ pageSizeïŒïŒã¯ãéžæç¯å²ãå³å¯ã«1ã¬ã³ãŒãã«å¶éããŸããããã«ãããçµæã®ããŒããå€§å¹ ã«é«éåãããŸãã
èªã¿èŸŒã¿ã§ãgetFirstItemããé«éã§ããã1ã€ã®èŠçŽ ã®ã³ã¬ã¯ã·ã§ã³ããååŸãããããèªã¿èŸŒã¿ãé ããªãããšã«æ³šæããŠãã ããã ããã¯ãããŒããåžžã«EAVããŒãã«ã§æ©èœããããã§ãã
çµè«
äžèšã®ãã¹ãŠãèŠçŽããããã«ãMagentoã§äœæ¥ãããã¹ãŠã®äººã«ã¢ããã€ã¹ããããšæããŸãã
- ã³ã¬ã¯ã·ã§ã³ããååŸãããªããžã§ã¯ãã«å¯ŸããŠloadã¡ãœãããå床åŒã³åºããªãã§ãã ããã
- å¿ èŠãªå±æ§ã®ã¿ãããŠã³ããŒããã
- ãããžã§ã¯ãã«è©²åœããå Žåã¯ããã©ããããŒãã«ã䜿çšããŸãã
- countã䜿çšããŠããŒããããã³ã¬ã¯ã·ã§ã³ã®çµæãã«ãŠã³ãããgetSizeã䜿çšããŠãã¹ãŠã®ã¬ã³ãŒãã®æ°ãååŸããŸã
- setPageïŒ1,1ïŒãŸãã¯åæ§ã®ã¡ãœãããªãã§getFirstItemã¡ãœããã䜿çšããªãã§ãã ãã