수색…


SKU로 제품 구입

$sku = 'sku-goes-here';
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);

ID로 제품 가져 오기

$id = 1;
$product = Mage::getModel('catalog/product')->load($id);
if($product->getId()){
    //product was found
}

제품 컬렉션 - LIKE 쿼리

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToFilter('sku', array('like' => 'UX%'));

속성 별 제품 컬렉션 가져 오기

$collection = Mage::getModel('catalog/product')->getCollection();
// Using operator
$collection->addAttributeToFilter('status', array('eq' => 1)); 
// Without operator (automatically uses 'equal' operator
$collection->addAttributeToFilter('status', 1); 

제품 오브젝트에서 데이터 가져 오기

// First load a product object

$product->getSku();
$product->getName();

// Alternative method
$product->getData('sku');
$product->getData('name');

데이터 양식 제품 컬렉션 가져 오기

// First load a collection object

foreach($collection as $product) {
    
    $product->getSku();
    $product->getName();

    // Alternative method
    $product->getData('sku');
    $product->getData('name'); 
}    

제품 컬렉션 - 속성 포함

//all attributes
$collection = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('*');
//specific attributes
$collection = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('name');
//certain attributes are special, such as price and images
//for images, then you can use 'getMediaGalleryImages'
$product->load('media_galley');

제품이 올바르게로드되었는지 확인하십시오.

$productFound = ($product->getId() !== null)

SKU 별 제품 ID 가져 오기

$sku = 'some-sku';
$productId = Mage::getModel('catalog/product')->getIdBySku($sku);
if($productId){
   //sku exists
}

SKU 목록에서 제품 컬렉션 가져 오기

$skuList = array('SKU-1', 'SKU-2',...,'SKU-n);

$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToFilter('sku', array('in' => $skuList));

또는

$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('sku', array('in' => $skuList));

제품 컬렉션의 한도 설정

$collection = Mage::getModel('catalog/product')
            ->getCollection()
            ->setPageSize(20)
            ->setCurPage(1);


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow