123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- namespace Smartwave\Dailydeals\Helper;
- class Data extends \Magento\Framework\App\Helper\AbstractHelper
- {
- protected $dailydealFactory;
- protected $scopeConfig;
- protected $productFactory;
- protected $loadedTimer;
-
- public function __construct(
- \Smartwave\Dailydeals\Model\DailydealFactory $dailydealFactory,
- \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
- \Magento\Catalog\Model\ProductFactory $productFactory
- ) {
-
- $this->dailydealFactory = $dailydealFactory;
- $this->scopeConfig=$scopeConfig;
- $this->productFactory= $productFactory;
- $this->loadedTimer = 0;
- }
- public function chkEnableDailydeals()
- {
- $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
-
- $configPath = "sw_dailydeal/general/dailydeal_enabled";
-
- $chkEnableDailydeals = $this->scopeConfig->getValue($configPath, $storeScope);
-
- return $chkEnableDailydeals;
- }
- // Get ObjectManager Instance
- public function getObjectManagerInstance()
- {
- $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
- return $objectManager;
- }
-
- //Check Dailydeal Product
- public function isDealProduct($productId)
- {
- if(!$this->chkEnableDailydeals())
- return false;
- $productcollection=$this->productFactory->create()->getCollection();
- $productcollection->addAttributeToSelect('*');
- $productcollection->addAttributeToFilter('entity_id', ['eq'=>$productId]);
- $sku=$productcollection->getFirstItem()->getSku();
-
- $dailydealcollection=$this->getDailydealcollection();
- $dailydealcollection->addFieldToSelect('*');
- $dailydealcollection->addFieldToFilter('sw_product_sku', ['eq'=>$sku]);
-
- if ($dailydealcollection->getSize() ==1) {
- $objDate = $this->getObjectManagerInstance()->create('Magento\Framework\Stdlib\DateTime\DateTime');
-
- $curdate=strtotime($this->getcurrentDate());
- $Todate=strtotime($this->getDailydealToDate($sku));
- $fromdate=strtotime($this->getDailydealFromDate($sku));
-
- if (( $curdate <= $Todate ) && ($curdate >= $fromdate)) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- // Get Product Price
- public function getProductPrice($sku)
- {
- $productcollection=$this->productFactory->create()->getCollection();
- $productcollection->addAttributeToSelect('*');
- $productcollection->addAttributeToFilter('sku', ['eq'=>$sku]);
- $productcollection->addAttributeToFilter('type_id', ['neq'=>'bundle']);
- if ($productcollection->getSize() ==1 && $productcollection->getFirstItem()->getTypeId() !="grouped") {
- return $productcollection->getFirstItem()->getFinalPrice();
- } else {
- return 1;
- }
- }
- // Get Bundle Discount Value
- public function getbundleProductDiscount($sku)
- {
- $dailydealcollection=$this->getDailydealcollection();
- $dailydealcollection->addFieldToSelect('*');
- $dailydealcollection->addFieldToFilter('sw_product_sku', ['eq'=>$sku]);
- if ($dailydealcollection->getFirstItem()->getSwDiscountType() ==1) {
- return '<div style=" margin-top:20px; "><strong>Save:'.$this->getcurrencySymbol().''.number_format($dailydealcollection->getFirstItem()->getSwDiscountAmount(), 2).'</strong></div>';
- } elseif ($dailydealcollection->getFirstItem()->getSwDiscountType() ==2) {
- return '<div style="margin-top:20px;"><strong>OFF:'.number_format($dailydealcollection->getFirstItem()->getSwDiscountAmount(), 2).'%</strong></div>';
- }
- }
- //Get "Product price" by ProductId
- public function getDealproductbyId($productId)
- {
- $productcollection=$this->productFactory->create()->getCollection();
- $productcollection->addAttributeToSelect('*');
- $productcollection->addAttributeToFilter('entity_id', ['eq'=>$productId]);
- $sku=$productcollection->getFirstItem()->getSku();
-
- return $this->getDealProductPrice($sku);
- }
-
- // Get Current Currency Symbol
- public function getcurrencySymbol()
- {
- $currencySymbol=$this->getObjectManagerInstance()->create('Magento\Store\Model\StoreManagerInterface');
- return $currencySymbol->getStore()->getCurrentCurrency()->getCurrencySymbol();
- }
- // Get Current Date
- public function getcurrentDate()
- {
- $objDate = $this->getObjectManagerInstance()->create('Magento\Framework\Stdlib\DateTime\DateTime');
- return $objDate->gmtDate("Y-m-d H:i:s");
- }
- // Get Collection of dailydeal
-
- public function getDailydealcollection()
- {
- $dailydealcollection=$this->dailydealFactory->create()->getCollection();
- return $dailydealcollection;
- }
-
- // Get Discount Value of Dailydeal Product
- public function getDealProductDiscountValue($dealproductsku)
- {
- $dailydealcollection=$this->getDailydealcollection();
- $dailydealcollection->addFieldToSelect('*');
- $dailydealcollection->addFieldToFilter('sw_product_sku', ['eq'=>$dealproductsku]);
-
- return $dailydealcollection->getFirstItem()->getSwDiscountAmount();
- }
-
- // Get Dailydeal Product with Discount Price
- public function getDealProductPrice($dealproductsku)
- {
- $dailydealcollection=$this->getDailydealcollection();
- $dailydealcollection->addFieldToSelect('*');
- $dailydealcollection->addFieldToFilter('sw_product_sku', ['eq'=>$dealproductsku]);
-
- return $dailydealcollection->getFirstItem()->getSwProductPrice();
- }
-
- // Get Dailydeal Product TO date
- public function getDailydealToDate($dealproductsku)
- {
- $dailydealcollection=$this->getDailydealcollection();
- $dailydealcollection->addFieldToSelect('*');
- $dailydealcollection->addFieldToFilter('sw_product_sku', ['eq'=>$dealproductsku]);
-
- return $dailydealcollection->getFirstItem()->getSwDateTo();
- }
- // Get Dailydeal Product FROM Date
- public function getDailydealFromDate($dealproductsku)
- {
- $dailydealcollection=$this->getDailydealcollection();
- $dailydealcollection->addFieldToSelect('*');
- $dailydealcollection->addFieldToFilter('sw_product_sku', ['eq'=>$dealproductsku]);
-
- return $dailydealcollection->getFirstItem()->getSwDateFrom();
- }
-
- // Get "OFF value" (in percentage) of Dailydeal Product
- public function getDealOffValue($dealproductsku)
- {
- $dailydealcollection=$this->getDailydealcollection();
- $dailydealcollection->addFieldToSelect('*');
- $dailydealcollection->addFieldToFilter('sw_product_sku', ['eq'=>$dealproductsku]);
-
- $discountType=$dailydealcollection->getFirstItem()->getSwDiscountType();
- if ($discountType ==1) {
- $off=(($this->getProductPrice($dealproductsku)-$this->getDealProductPrice($dealproductsku))* 100)/ $this->getProductPrice($dealproductsku) ;
- return $off;
- } elseif ($discountType ==2) {
- return $dailydealcollection->getFirstItem()->getSwDiscountAmount();
- }
- }
-
- // Get "Save value" (In price) of dailydeal Product
- public function getDealSaveValue($dealproductsku)
- {
- $dailydealcollection=$this->getDailydealcollection();
- $dailydealcollection->addFieldToSelect('*');
- $dailydealcollection->addFieldToFilter('sw_product_sku', ['eq'=>$dealproductsku]);
-
- $discountType=$dailydealcollection->getFirstItem()->getSwDiscountType();
- if ($discountType ==1) {
- return $dailydealcollection->getFirstItem()->getSwDiscountAmount();
- } elseif ($discountType ==2) {
- $save=$this->getProductPrice($dealproductsku) - $this->getDealProductPrice($dealproductsku);
- return $save;
- }
- }
- public function isLoadedTimer() {
- return $this->loadedTimer;
- }
- public function setLoadedTimer() {
- $this->loadedTimer = 1;
- }
- }
|