protected function sendNotification($params)
 {
     $email = Email::create();
     $email->setTemplate('Shop_Inventory_EmailNotification');
     if (isset($params['params'])) {
         foreach ($params['params'] as $paramName => $param) {
             $email->{$paramName} = $param;
         }
     }
     $adminEmail = function () {
         return Config::env('ShopConfig.Inventory.NotifyEmail') ?: Config::env('ShopConfig|SiteConfig.AdminForEmail') ?: Email::config()->admin_email;
     };
     if (!$email->To) {
         $email->To = $adminEmail();
     }
     if (!$email->From) {
         $email->From = $adminEmail instanceof Closure ? $adminEmail() : $adminEmail;
     }
     if (isset($params['buyable'])) {
         $email->Buyable = $params['buyable'];
     }
     if (isset($params['item'])) {
         $email->LastOrderItem = $params['item'];
         $email->LastOrder = $params['item']->Order();
     }
     $email->addCustomHeader('X-Priority', 1);
     $email->addCustomHeader('X-MSMail-Priority', 1);
     return $email->send();
 }
 protected function doFire($event = 'zero')
 {
     if ($event == 'low') {
         return $this->owner->{$this->stockField . '_LastSentOnLow'} ? $this->hoursIsWithin($this->owner->{$this->stockField . '_LastSentOnLow'}, Config::env('ShopConfig.Inventory.LowIndicatorInterval_Hours', 24)) : true;
     }
     return $this->owner->{$this->stockField . '_LastSentOnZero'} ? $this->hoursIsWithin($this->owner->{$this->stockField . '_LastSentOnZero'}, Config::env('ShopConfig.Inventory.ZeroIndicatorInterval_Hours', 1)) : true;
 }
 protected function isAffectedItem($buyable, $during = 'placement')
 {
     return !Config::env('ShopConfig.Inventory.DisableInventory') && (!$during || strtolower(Config::env('ShopConfig.Inventory.AffectStockDuring')) == $during) && $buyable instanceof Object && $buyable->hasExtension('Milkyway\\SS\\Shop\\Inventory\\Extensions\\TrackStockOnBuyable');
 }
 public function updateCMSFields(FieldList $fields)
 {
     $productDefaults = (array) Product::config()->defaults;
     $fields->addFieldsToTab('Root.Shop.ShopTabs.ShopInventory', [CheckboxField::create('Shop_DisableInventory', _t('ShopInventory.DisableInventory', 'Disable inventory management')), NumericField::create('Shop_NotifyWhenStockReaches', _t('ShopInventory.NotifyWhenStockReaches', 'Notify when stock reaches')), NumericField::create('Shop_DefaultStock', _t('ShopInventory.DefaultStock', 'Default stock for new products'))->setAttribute('placeholder', isset($productDefaults['Stock']) ? $productDefaults['Stock'] : 5), TextField::create('Shop_NotifyEmail', _t('ShopInventory.NotifyEmail', 'Email to notify'))->setAttribute('placeholder', Config::env('AdminForEmail') ?: Email::config()->admin_email)]);
 }