我想获得原价,特价,从产品ID在Magento 2,我们使用下面的代码全部产品类型,但不工作如何从产品ID获得产品信息在Magento 2
<?php
namespace Namespace\Module\Model;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\Context;
use Magento\Store\Model\ScopeInterface;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Namespace\Module\Model\ResourceModel\Subscription\CollectionFactory as SubscriptionCollectionFactory;
class Observer extends AbstractModel{
protected $_storeManager;
protected $_productCollectionFactory;
protected $_objectManager;
protected $_currency;
public function __construct(
Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\ObjectManagerInterface $objectManager,
ProductCollectionFactory $productCollectionFactory,
SubscriptionCollectionFactory $subscriptionCollectionFactory,
\Magento\Directory\Model\Currency $currency
)
{
$this->_scopeConfig = $scopeConfig;
$this->_storeManager = $storeManager;
$this->_objectManager = $objectManager;
$this->_productCollectionFactory = $productCollectionFactory;
$this->subscriptionCollectionFactory = $subscriptionCollectionFactory;
$this->_currency = $currency;
}
public function sendalert() {
$data = $this->subscriptionCollectionFactory->create()
->addFieldToSelect('*')
->addFieldToFilter('subscription_status', 0);
$collection = $this->_productCollectionFactory->create()
->addAttributeToFilter('status', 1)
->addAttributeToFilter('visibility', 4)
->addAttributeToSelect('*');
$prodIds = $collection->getAllIds();
foreach($prodIds as $productId)
{
$om = \Magento\Framework\App\ObjectManager::getInstance();
$pdata = $this->_objectManager()->create('Magento\Catalog\Model\Product')->load($productId);
echo '>>'.$pdata->getPrice();
}
}
}
的可能的复制[如何通过ID magento2加载产品?](http://stackoverflow.com/questions/34894534/how-to-load-product-by-id- magento2) –
可以帮助我吗? – MagikVishal