根据从Web服务收到的数据显示magento产品

时间:2014-07-23 15:34:17

标签: php web-services magento

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

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

我认为这是你需要什么

  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); 
      }
希望能帮助