ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* @author 18th DigiTech Team
|
||||
* @copyright Copyright (c) 2020 18th DigiTech (https://www.18thdigitech.com)
|
||||
* @package Caratlane_NetSuite
|
||||
*/
|
||||
namespace Caratlane\NetSuite\Model\Config\Attribute\Source;
|
||||
|
||||
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
|
||||
use Magento\Eav\Model\Entity\Attribute\Source\SourceInterface;
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
|
||||
/**
|
||||
* Product status functionality model
|
||||
*
|
||||
* @api
|
||||
* @since 100.0.2
|
||||
*/
|
||||
class Status extends AbstractSource implements SourceInterface, OptionSourceInterface
|
||||
{
|
||||
/**#@+
|
||||
* Product Status values
|
||||
*/
|
||||
const STATUS_SUCCESS = 1;
|
||||
|
||||
const STATUS_FAILED = 0;
|
||||
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Retrieve Visible Status Ids
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function getVisibleStatusIds()
|
||||
{
|
||||
return [self::STATUS_SUCCESS];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Saleable Status Ids
|
||||
* Default Product Enable status
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function getSaleableStatusIds()
|
||||
{
|
||||
return [self::STATUS_SUCCESS];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve option array
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getOptionArray()
|
||||
{
|
||||
return [self::STATUS_SUCCESS => __('Success'), self::STATUS_FAILED => __('Failed')];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve option array with empty value
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAllOptions()
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach (self::getOptionArray() as $index => $value) {
|
||||
$result[] = ['value' => $index, 'label' => $value];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* @author 18th DigiTech Team
|
||||
* @copyright Copyright (c) 2020 18th DigiTech (https://www.18thdigitech.com)
|
||||
* @package Caratlane_NetSuite
|
||||
*/
|
||||
namespace Caratlane\NetSuite\Model\Config;
|
||||
|
||||
class CronConfig extends \Magento\Framework\App\Config\Value
|
||||
{
|
||||
const CRON_STRING_PATH = 'crontab/default/jobs/caratlane_netsuite_cron_job/schedule/cron_expr';
|
||||
|
||||
const CRON_MODEL_PATH = 'crontab/default/jobs/caratlane_netsuite_cron_job/run/model';
|
||||
|
||||
protected $_configValueFactory;
|
||||
|
||||
protected $_runModelPath = '';
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\Model\Context $context,
|
||||
\Magento\Framework\Registry $registry,
|
||||
\Magento\Framework\App\Config\ScopeConfigInterface $config,
|
||||
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
|
||||
\Magento\Framework\App\Config\ValueFactory $configValueFactory,
|
||||
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
|
||||
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
|
||||
$runModelPath = '',
|
||||
array $data = []
|
||||
) {
|
||||
$this->_runModelPath = $runModelPath;
|
||||
$this->_configValueFactory = $configValueFactory;
|
||||
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
|
||||
}
|
||||
|
||||
public function afterSave()
|
||||
{
|
||||
$time = $this->getData('netsuite/cronScheduled/fields/time/value');
|
||||
$frequency = $this->getData('netsuite/cronScheduled/fields/frequency/value');
|
||||
$t1 = isset($time[1])?$time[1]:0;
|
||||
$t2 = isset($time[0])?$time[0]:0;
|
||||
$cronExprArray = [
|
||||
(int)($t1),
|
||||
(int)($t2),
|
||||
$frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY ? '1' : '*',
|
||||
'*',
|
||||
$frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY ? '1' : '*',
|
||||
];
|
||||
|
||||
$cronExprString = join(' ', $cronExprArray);
|
||||
|
||||
try {
|
||||
$this->_configValueFactory->create()->load(
|
||||
self::CRON_STRING_PATH,
|
||||
'path'
|
||||
)->setValue(
|
||||
$cronExprString
|
||||
)->setPath(
|
||||
self::CRON_STRING_PATH
|
||||
)->save();
|
||||
$this->_configValueFactory->create()->load(
|
||||
self::CRON_MODEL_PATH,
|
||||
'path'
|
||||
)->setValue(
|
||||
$this->_runModelPath
|
||||
)->setPath(
|
||||
self::CRON_MODEL_PATH
|
||||
)->save();
|
||||
} catch (\Exception $e) {
|
||||
//throw new \Exception(__('We can\'t save the cron expression.'));
|
||||
$e->getMessage();
|
||||
}
|
||||
|
||||
return parent::afterSave();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user