Get Award winning product where award winning is a custom attribute.
/* Get Award Winning prduct list
* @return $collection
*/
public function getAwardWinningProduct(){
$productcollection = $this->_objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection')
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('eq' => 1))
->addAttributeToFilter('award_winning', array('eq' => 1));
return $productcollection;
}
Full page code of Data helper file
<?php
/**
* Techievolve
*
* NOTICE OF LICENSE
*
* This source file is subject to the marketplace.techievolve.com license that is
* http://marketplace.techievolve.com/license-agreement.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Techievolve
* @package Techievolve_Vgod
* @module vgod
* @author Techievolve Developer* <support@techievolve.com>
* @copyright Copyright (c) 2018 Techievolve (http://marketplace.techievolve.com/)
* @license http://marketplace.techievolve.com/license-agreement.html
*/
namespace Techievolve\Vgod\Helper;
/**
* Techievolve Vgod Helper
*/
Class Data extends \Magento\Framework\App\Helper\AbstractHelper {
protected $_scopeConfig;
protected $_httpFactory;
protected $_storeManager;
protected $_filesystem ;
protected $_imageFactory;
protected $_objectManager;
const XML_PATH_ENABLED = 'techievolve/vgod/enabled';
/**
* @param \Magento\Framework\App\Helper\Context $context
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Filesystem $filesystem,
\Magento\Framework\Image\AdapterFactory $imageFactory,
\Magento\Framework\ObjectManagerInterface $objectManager
) {
$this->_scopeConfig = $scopeConfig;
$this->_httpFactory = $httpFactory;
$this->_storeManager = $storeManager;
$this->_filesystem = $filesystem;
$this->_imageFactory = $imageFactory;
$this->_objectManager = $objectManager;
parent::__construct($context);
}
/**
* Check if extension enabled
* @return string|null
*/
public function isEnabled() {
return $this->scopeConfig->isSetFlag(self::XML_PATH_ENABLED,\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
public function isHomeBottomBannerEnabledForDesktop(){
return $this->scopeConfig->getValue('techievolve_vgod/home_page_banner_bottom_desktop/enabled', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
public function getHomeBottomBannerBlockIdForDesktop(){
return $this->scopeConfig->getValue('techievolve_vgod/home_page_banner_bottom_desktop/cms_block_desktop', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
public function isHomeBottomBannerEnabledForMobile(){
return $this->scopeConfig->getValue('techievolve_vgod/home_page_banner_bottom_mobile/enabled', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
public function getHomeBottomBannerBlockIdForMobile(){
return $this->scopeConfig->getValue('techievolve_vgod/home_page_banner_bottom_mobile/cms_block_mobile', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
/* Get Award Winning prduct list
* @return $collection
*/
public function getAwardWinningProduct(){
$productcollection = $this->_objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection')
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('eq' => 1))
->addAttributeToFilter('award_winning', array('eq' => 1));
return $productcollection;
}
public function getCurrentStoreId(){
$currentStore = $this->_storeManager->getStore();
return $currentStore->getId();
}
/*
* Get Media Url
*/
public function getMediaUrl(){
return $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
}
/*
* Get Media Path
*/
public function getMediaPath(){
return $this->_filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
}
public function getProductAwardWinningImageUrl($_product){
$imagehelper = $this->_objectManager->create('Magento\Catalog\Helper\Image');
return $imagehelper->init($_product,'award_winning_image')->setImageFile($_product->getAwardWinningImage())->getUrl();
}
}
![]()
0 Comments