-2

こんにちは、特定の製品 IDのコードから特定の*製品* 配列を取得しました。すべての*製品配列を取得したい*..... 私のコードは

**<?php
@ob_start();
@session_start();
ini_set('display_errors', 1);
//for order update
include '../../../../app/Mage.php';
Mage::app('default');
echo '<pre>';
if(isset($_REQUEST['productid'])){
$productId = $_REQUEST['productid'];
}else{
$productId = '12402'; // product ID 10 is an actual product, and used here for a test
}
$product = Mage::getModel('catalog/product')->load($productId);  //load the product     
echo 'product_id '.'=>'.$product->getId().'<br/>';                                        
?>**
4

5 に答える 5

3

あなたは何をしたいですか?$product は配列ではなく、オブジェクトです。すべての製品が必要な場合は、次のコードを使用できます。

$collection = Mage::getResourceModel('catalog/product_collection');
foreach($collection as $product) {
    echo $product->getId();
}
于 2013-01-08T10:13:05.450 に答える
2

ここでは、すべての製品の名前を取得する方法を配置しました。同様に、目的の属性を取得できます。

$collection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSelect('*');

foreach ($collection as $product) {


    echo $product->getName() . "<br />";

    }
于 2013-05-08T13:14:18.280 に答える
2
function products($category_id){
    $json = array('success' => true, 'products' => array());
    $category = Mage::getModel ('catalog/category')->load($category_id);
    $products = Mage::getResourceModel('catalog/product_collection')
                  // ->addAttributeToSelect('*')
                  ->AddAttributeToSelect('name')
                  ->addAttributeToSelect('price')
                  ->addFinalPrice()
                  ->addAttributeToSelect('small_image')
                  ->addAttributeToSelect('image')
                  ->addAttributeToSelect('thumbnail')
                  ->addAttributeToSelect('short_description')
                  ->addUrlRewrite()
                  ->AddCategoryFilter($category);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
    $currencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
    foreach($products as $product){ 
        $json['products'][] = array(
                'id'                    => $product->getId(),
                'name'                  => $product->getName(),
                'description'           => $product->getShortDescription(),
                'pirce'                 => Mage::helper('core')->currency($product->getPrice(), true, false), //." ".$currencyCode,
                'href'                  => $product->getProductUrl(),
                'thumb'                 => (string)Mage::helper('catalog/image')->init($product, 'thumbnail')
            );
    }
    return $json;
}

完全なプラグイン REST API を参照してください https://github.com/app-z/magento-android-web-api/blob/master/web-api.php

于 2015-01-06T16:22:19.433 に答える
0
$term = Mage::helper('catalogsearch')->getQueryText();
    $query = Mage::getModel('catalogsearch/query')->setQueryText($term)->prepare();
    $fulltextResource = Mage::getResourceModel('catalogsearch/fulltext')->prepareResult(
        Mage::getModel('catalogsearch/fulltext'),
        $term,
        $query
    );

    $collection = Mage::getResourceModel('catalog/product_collection');
    $collection->getSelect()->joinInner(
        array('search_result' => $collection->getTable('catalogsearch/result')),
        $collection->getConnection()->quoteInto(
            'search_result.product_id=e.entity_id AND search_result.query_id=?',
            $query->getId()
        ),
        array('relevance' => 'relevance')
    );

    $productIds = array();
    $productIds = $collection->getAllIds(); // as per Amit Bera s' comment
Zend_Debug::dump($productIds);
于 2016-03-22T10:32:37.827 に答える