从外部访问美德市场产品数据


Access virtuemart product data externally

是否有一种快速的方法可以使用其SKU从外部文件访问产品的所有数据?

我已经查看了如何在外部文件中获取VirtueMart 2产品的产品数据?

并尝试将产品 ID 替换为我想要的 ID,但无济于事:

if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'config.php');
VmConfig::loadConfig();
if (!class_exists( 'VmModel' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'vmmodel.php');
$productModel = VmModel::getModel('Product');
$product = $productModel->getProduct(Product_ID);

简而言之,我正在寻找一种访问产品数据的方法。

产品 SKU 可能不是唯一的。 所以我找到了一个适合我的解决方案。希望这对你有帮助。这是您需要在外部按 SKU 调用产品的完整代码。

<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', 'C:'Server'www'joomla' );//you will have diff location for your site
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
jimport('joomla.application.module.helper');
jimport('joomla.application.component.helper');
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();
function getproductBySKU($sku){
  $db = JFactory::getDbo();
  $db->setQuery(true);
  $db->setQuery("SELECT virtuemart_product_id FROM #__virtuemart_products WHERE product_sku= $sku");
  $productids = $db->loadAssocList();
  return $productids;
}
function getProduct($id)
{
    if (!class_exists('VmConfig')) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php');
    VmConfig::loadConfig();
    if (!class_exists('VmModel')) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'vmmodel.php');
    $productModel = VmModel::getModel('Product');
    $product = $productModel->getProduct($id);
    return $product;
}
$products = getproductBySKU(1);//In this example SKU is 1 having 2 products
var_dump($products);//Gives the product id's in the SKU
foreach($products as $product){
    var_dump(getProduct($product));
}