【发布时间】:2020-01-01 18:07:00
【问题描述】:
我想从 magento 2 中的产品 ID 中获取我们在下面代码中使用但不起作用的所有产品类型的价格和特价
<?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();
}
}
}
【问题讨论】:
标签: magento2