使用Collection类获取客户的数据
使用Collection类获取客户的数据
customer 集合类 在 MagentoCustomerModelResourceModelCustomerCollection.php
order集合类 在 MagentoSalesModelResourceModelOrderCollection.php
product集合类 在MagentoCatalogModelResourceModelProductCollection.php
获取数据
_objectManager->create('MagentoCustomerModelResourceModelCustomerCollection'); } }
过滤要采集的数据
使用AttributeToFillter()按元素值过滤。
只检索邮件地址为“[email protected]”的客户
$customerCollection = $this->_objectManager->create('MagentoCustomerModelResourceModelCustomerCollection')->addAttributeToFilter('email', '[email protected]');
仅检索产品名称包括“pen”的产品
$productCollection = $this->_objectManager->create('MagentoCatalogModelResourceModelProductCollection')->addAttributeToFilter('name', array('like' => '%pen%'));
订单排序
要按升序降序重新排列数据,使用setOrder()
按Entitiy_id以降序重新排列
$customerCollection = $this->_objectManager->create('MagentoCustomerModelResourceModelCustomerCollection')->setOrder('entity_id', 'DESC');
按updated_at以降序重新排列
$customerCollection = $this->_objectManager->create('MagentoCustomerModelResourceModelCustomerCollection')->setOrder('updated_at', 'ASC');
检索元素
为了得到我们使用每个getter方法的元素
firstName
_objectManager->create('MagentoCustomerModelResourceModelCustomerCollection'); foreach ($customerCollection as $customer) { echo $customer->getFirstname() ."
"; } } }
