There is an attribute in the product AllowSameDayDelivery
how can I get it out of the product?
I got the products ids from the cart, But how do I get the attribute now?
<?php
namespace Ronis\SameDayDelivery\Observer;
use Magento\Framework\Event\ObserverInterface;
use \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
class DayDelivery implements ObserverInterface
{
protected $resultPageFactory;
/**
* @var \Magento\Checkout\Model\Cart
*/
protected $_cart;
protected $_productCollectionFactory;
/**
* [__construct description]
* @param \Magento\Framework\App\Action\Context $context [description]
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory [description]
* @param \Magento\Checkout\Model\Cart $cart [description]
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Checkout\Model\Cart $cart,
CollectionFactory $productCollectionFactory
) {
$this->resultPageFactory = $resultPageFactory;
$this->_cart = $cart;
$this->_productCollectionFactory = $productCollectionFactory;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/delivery.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$cartProductIds = $this->_cart->getQuoteProductIds();
$productCollection = $this->_productCollectionFactory->create();
$productCollection->addFieldToFilter('entity_id', ['in' => [$cartProductIds]]);
foreach ($productCollection as $item){
var_dump ($item->getAllowSameDayDelivery());die;
}
}
}
now it always returns null even though it is in this product.