-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

也许是这样的?

$collection = Mage::getResourceModel('catalog/product_collection');
foreach ($collection as $product) {

    $data = $product->getData();
    foreach ($data as $d)
        var_dump($d);

}
于 2014-09-23T22:55:01.117 回答
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 回答