Php 根据从web服务接收的数据显示magento产品

Php 根据从web服务接收的数据显示magento产品,php,web-services,magento,Php,Web Services,Magento,我是Magento CE 1.9的新手。我们需要显示的产品列表不是来自数据库,而是来自通过SAP web服务接收的XML 有人能帮我做这件事所需要的方法吗?我想这就是你所需要的 public function ws_products($store_id, $service, $categoryid) { $res=array(); Mage::app()->setCurrentStore($store_id); $c_id = $categoryid; $cat

我是Magento CE 1.9的新手。我们需要显示的产品列表不是来自数据库,而是来自通过SAP web服务接收的XML


有人能帮我做这件事所需要的方法吗?

我想这就是你所需要的

  public function ws_products($store_id, $service, $categoryid) 
  {
  $res=array();
  Mage::app()->setCurrentStore($store_id); 
  $c_id = $categoryid;
  $category = new Mage_Catalog_Model_Category();
  $category->load($c_id);
  $collection = $category->getProductCollection()->addStoreFilter($store_id);
  $collection->addAttributeToSelect('*');

  foreach ($collection as $_product) 
  {

$product = Mage::getModel('catalog/product')->load($_product->getId());
$taxClassId = $product->getData("tax_class_id");
$taxClasses = Mage::helper("core")->jsonDecode(Mage::helper("tax")->getAllRatesByProductClass());
$taxRate = $taxClasses["value_".$taxClassId];
$a = (($taxRate)/100) *  ($_product->getPrice());
                  $res[] = array(
                           "id" => $_product->getId(),
                           "name" => $_product->getName(),
                           "imageurl" => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'/media/catalog/product'.$_product->getImage(),
                           "sku" => $_product->getSku(),
                           "spclprice" => number_format($_product->getSpecialprice(),2),
                           "price" => number_format($_product->getPrice(),2),
                           "tax" => number_format($a,2),
                           "created_date" => $_product->getCreatedAt(),
                           "is_in_stock" => $_product->getStockItem()->getIsInStock(),
                           "stock_quantity" => Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product->getId())->getQty()
                           ); 
     } 
     return($res); 
      }
希望这会有所帮助