- Cty TNHH HAWAII-Mã số doanh nghiệp: 0312949876. Nhận thiết kế website bán hàng chuyên nghiệp dùng Magento
- Tư vấn SEO và SEO trọn gói website Magento
- Nhận quản trị website bán hàng trọn gói, ký hợp đồng năm
- Email: quocduy240@gmail.com. Mobile:(+84)127.867.2707. Skype: quocduy240
- Trụ sở chính: 230/14 Đường Man Thiện, Phường Tăng Nhơn Phú A, Quận 9, TP.Hồ Chí Minh, Việt Nam.
- Chi nhánh: 97A, Đường 19, Xã Bình Hưng, Huyện Bình Chánh, TP.Hồ Chí Minh, Việt Nam.
Showing posts with label Model. Show all posts
Showing posts with label Model. Show all posts
23 August 2014
Model - Tổng quan về Model class trong Mgento
Tất cả model kế thừa Varien-Object từ Zend Framework
$model -> getData() ; // array
$model ->getWhat => $setWhat
$model->setMethod1->setMethod2
Lấy Data từ Model:
- Tổng quát:
$collections = Mage::getModel('catalog/product') // khởi tạo model Mage_Catalog_Model_Product
->getCollection() // lấy tất cả dữ liệu trong model
->addAttributeToSelect(array('name', 'price')) // lọc dữ liệu theo thuộc tính Attribute (cột)
->addAttributeToFilter('price', array('eq' => 10.00)) // lọc dữ liệu theo giá trị thuộc tính (row)
->load(); // nạp data cần lấy
$model -> getData() ; // array
$model ->getWhat => $setWhat
$model->setMethod1->setMethod2
Lấy Data từ Model:
- Tổng quát:
$collections = Mage::getModel('catalog/product') // khởi tạo model Mage_Catalog_Model_Product
->getCollection() // lấy tất cả dữ liệu trong model
->addAttributeToSelect(array('name', 'price')) // lọc dữ liệu theo thuộc tính Attribute (cột)
->addAttributeToFilter('price', array('eq' => 10.00)) // lọc dữ liệu theo giá trị thuộc tính (row)
->load(); // nạp data cần lấy
Giai thích: The below code, in this case is a product collection, we call addAttributeToSelect() to select only “name” and “price” attributes for all products. Then we call addAttributeToFilter() to filter so only products with the price of 10.00 will be selected from the database. Again, even though catalog/product is using EAV model, it’s ok to use addFieldToFilter() if you want to.
->getCollection()
->addAttributeToSelect(array('name', 'price'))
->addAttributeToFilter(
array(
'attribute' => 'name',
'eq' => 'Somename',
),
array(
'attribute' => 'price',
'eq' => 10.00,
),
));
->load();
Đọc thêm => các cách Filter dữ liệu addAttributeToFilter
- Ví dụ cụ thể 1:
$collections = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect(array('name', 'price'))
->addAttributeToFilter(
array(
'attribute' => 'name',
'eq' => 'Somename',
),
array(
'attribute' => 'price',
'eq' => 10.00,
),
));
->load();