示例#1
0
 /**
  * Run test getAllIds method
  *
  * @return void
  */
 public function testGetAllIds()
 {
     $adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['fetchCol'], [], '', false);
     $this->resourceMock->expects($this->once())->method('getIdFieldName')->will($this->returnValue('return-value'));
     $this->selectMock->expects($this->once())->method('getConnection')->will($this->returnValue($adapterMock));
     $adapterMock->expects($this->once())->method('fetchCol')->will($this->returnValue('fetch-result'));
     $this->assertEquals('fetch-result', $this->query->getAllIds());
 }
 protected function setUp()
 {
     $this->select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock();
     $this->connection = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql')->disableOriginalConstructor()->getMock();
     $this->connection->expects($this->any())->method('select')->willReturn($this->select);
     $this->resource = $this->getMockBuilder('Magento\\Framework\\Model\\ModelResource\\Db\\AbstractDb')->disableOriginalConstructor()->setMethods(['getConnection', 'getMainTable', 'getTable'])->getMockForAbstractClass();
     $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection);
     $this->resource->expects($this->any())->method('getMainTable')->willReturn('table_test');
     $this->resource->expects($this->any())->method('getTable')->willReturn('test');
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
 }
示例#3
0
 public function testSetMainTable()
 {
     $setMainTableMethod = new \ReflectionMethod($this->_model, '_setMainTable');
     $setMainTableMethod->setAccessible(true);
     $tableName = $this->_model->getTable('store_website');
     $idFieldName = 'website_id';
     $setMainTableMethod->invoke($this->_model, $tableName);
     $this->assertEquals($tableName, $this->_model->getMainTable());
     $setMainTableMethod->invoke($this->_model, $tableName, $idFieldName);
     $this->assertEquals($tableName, $this->_model->getMainTable());
     $this->assertEquals($idFieldName, $this->_model->getIdFieldName());
 }
 /**
  * Mock class dependencies
  */
 protected function setUp()
 {
     $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false);
     $this->fetchStrategyMock = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface');
     $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $this->selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->connectionMock->expects($this->atLeastOnce())->method('select')->will($this->returnValue($this->selectMock));
     $this->resourceMock = $this->getMock('Magento\\Framework\\Model\\ModelResource\\Db\\AbstractDb', [], [], '', false);
     $this->resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->connectionMock));
     $objectManager = new ObjectManager($this);
     $this->collection = $objectManager->getObject('Magento\\Quote\\Model\\ResourceModel\\Quote\\Item\\Collection', ['entityFactory' => $this->entityFactoryMock, 'fetchStrategy' => $this->fetchStrategyMock, 'eventManager' => $this->eventManagerMock, 'resource' => $this->resourceMock]);
 }
 protected function setUp()
 {
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface');
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where'], [], '', false);
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'prepareSqlCondition', 'quoteIdentifier'], [], '', false);
     $this->resource = $this->getMockForAbstractClass('Magento\\Framework\\Model\\ModelResource\\Db\\AbstractDb', [], '', false, true, true, ['getConnection', '__wakeup', 'getMainTable', 'getTable']);
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->connectionMock->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $this->connectionMock->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0));
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connectionMock));
     $this->resource->expects($this->any())->method('getMainTable')->will($this->returnValue('test_main_table'));
     $this->resource->expects($this->any())->method('getTable')->with('test_main_table')->will($this->returnValue('test_main_table'));
     $this->collection = (new ObjectManager($this))->getObject('Magento\\UrlRewrite\\Model\\ResourceModel\\UrlRewriteCollection', ['storeManager' => $this->storeManager, 'resource' => $this->resource]);
 }
 /**
  * @param mixed $ignoreData
  * @param 'string' $ignoreSql
  * @dataProvider ignoresDataProvider
  * @return void
  */
 public function testAddStoreFilter($ignoreData, $ignoreSql)
 {
     $typeId = 1;
     $subjectId = 2;
     $subtype = 3;
     $limit = 0;
     $stores = [1, 2];
     $this->resourceMock->expects($this->once())->method('getCurrentStoreIds')->willReturn($stores);
     $this->selectMock->expects($this->at(0))->method('where')->with('event_type_id = ?', $typeId);
     $this->selectMock->expects($this->at(1))->method('where')->with('subject_id = ?', $subjectId);
     $this->selectMock->expects($this->at(2))->method('where')->with('subtype = ?', $subtype);
     $this->selectMock->expects($this->at(3))->method('where')->with('store_id IN(?)', $stores);
     $this->selectMock->expects($this->at(4))->method('where')->with($ignoreSql, $ignoreData);
     $this->collection->addRecentlyFiler($typeId, $subjectId, $subtype, $ignoreData, $limit);
 }
 protected function setUp()
 {
     $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategy\\Query', ['fetchAll'], [], '', false);
     $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', ['create'], [], '', false);
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->resourceMock = $this->getMockBuilder('Magento\\Framework\\Model\\ModelResource\\Db\\AbstractDb')->setMethods(['getConnection', 'getMainTable', 'getTable'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->connectionMock = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'query'], [], '', false);
     $this->selectMock = $this->getMock('Magento\\Framework\\DB\\Select', ['from'], ['adapter' => $this->connectionMock]);
     $this->connectionMock->expects($this->once())->method('select')->will($this->returnValue($this->selectMock));
     $this->resourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->connectionMock));
     $this->resourceMock->expects($this->once())->method('getMainTable')->willReturn('main_table_name');
     $this->resourceMock->expects($this->once())->method('getTable')->will($this->returnArgument(0));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->collection = $objectManager->getObject('Magento\\Review\\Model\\ResourceModel\\Review\\Summary\\Collection', ['entityFactory' => $this->entityFactoryMock, 'logger' => $this->loggerMock, 'fetchStrategy' => $this->fetchStrategyMock, 'resource' => $this->resourceMock]);
 }
示例#8
0
 public function testGetFields()
 {
     $entityTable = 'entity_table';
     $expectedDescribedTable = ['field1' => null, 'field2' => null];
     $expectedAttributes = ['attribute1' => 'value1', 'attribute2' => 'value2'];
     $expectedResults = array_merge($expectedDescribedTable, $expectedAttributes);
     $this->resource->expects($this->any())->method('getEntityTable')->willReturn($entityTable);
     $this->connection->expects($this->once())->method('describeTable')->with($entityTable)->willReturn($expectedDescribedTable);
     $this->model->expects($this->any())->method('getAttributes')->willReturn($expectedAttributes);
     //check that fields load with null initial value
     $this->assertEquals(array_fill_keys(array_keys($expectedResults), null), $this->metadata->getFields($this->model));
     // Testing loading data from cache.
     $this->connection->expects($this->never())->method('describeTable');
     $this->assertEquals(array_fill_keys(array_keys($expectedResults), null), $this->metadata->getFields($this->model));
 }
示例#9
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($date = $object->getDateFrom()) {
         $object->setDateFrom($this->dateTime->formatDate($date));
     } else {
         $object->setDateFrom(null);
     }
     if ($date = $object->getDateTo()) {
         $object->setDateTo($this->dateTime->formatDate($date));
     } else {
         $object->setDateTo(null);
     }
     if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) && (new \DateTime($object->getDateFrom()))->getTimestamp() > (new \DateTime($object->getDateTo()))->getTimestamp()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The start date can\'t follow the end date.'));
     }
     $check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId());
     if ($check) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The date range for this design change overlaps another design change for the specified store.'));
     }
     if ($object->getDateFrom() === null) {
         $object->setDateFrom(new \Zend_Db_Expr('null'));
     }
     if ($object->getDateTo() === null) {
         $object->setDateTo(new \Zend_Db_Expr('null'));
     }
     parent::_beforeSave($object);
 }
示例#10
0
 /**
  * @param \Magento\Framework\Model\ModelResource\Db\Context $context
  * @param \Magento\Customer\Model\Session $customerSession
  * @param \Magento\Review\Model\Rating\Option\VoteFactory $ratingOptionVoteF
  * @param \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Model\ModelResource\Db\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Review\Model\Rating\Option\VoteFactory $ratingOptionVoteF, \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress, $connectionName = null)
 {
     $this->_customerSession = $customerSession;
     $this->_ratingOptionVoteF = $ratingOptionVoteF;
     $this->_remoteAddress = $remoteAddress;
     parent::__construct($context, $connectionName);
 }
示例#11
0
 /**
  * @param \Magento\Framework\Model\ModelResource\Db\Context $context
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Store\Model\WebsiteFactory $websiteFactory
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Model\ModelResource\Db\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Store\Model\WebsiteFactory $websiteFactory, \Magento\Eav\Model\Config $eavConfig, $connectionName = null)
 {
     parent::__construct($context, $connectionName);
     $this->_storeManager = $storeManager;
     $this->_websiteFactory = $websiteFactory;
     $this->eavConfig = $eavConfig;
 }
示例#12
0
 public function testPrepareDataForUpdate()
 {
     $connectionMock = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false);
     $context = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Framework\\Model\\Context');
     $registryMock = $this->getMock('\\Magento\\Framework\\Registry', [], [], '', false);
     $resourceMock = $this->getMock('Magento\\Framework\\Model\\ModelResource\\Db\\AbstractDb', ['_construct', 'getConnection', '__wakeup', 'getIdFieldName'], [], '', false);
     $connectionInterfaceMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false);
     $resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionInterfaceMock));
     $resourceCollectionMock = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\AbstractDb')->disableOriginalConstructor()->getMockForAbstractClass();
     $abstractModelMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\AbstractModel', [$context, $registryMock, $resourceMock, $resourceCollectionMock]);
     $data = 'tableName';
     $this->_resourcesMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->_resourcesMock->expects($this->any())->method('getTableName')->with($data)->will($this->returnValue('tableName'));
     $mainTableReflection = new \ReflectionProperty('Magento\\Framework\\Model\\ModelResource\\Db\\AbstractDb', '_mainTable');
     $mainTableReflection->setAccessible(true);
     $mainTableReflection->setValue($this->_model, 'tableName');
     $idFieldNameReflection = new \ReflectionProperty('Magento\\Framework\\Model\\ModelResource\\Db\\AbstractDb', '_idFieldName');
     $idFieldNameReflection->setAccessible(true);
     $idFieldNameReflection->setValue($this->_model, 'idFieldName');
     $connectionMock->expects($this->any())->method('save')->with('tableName', 'idFieldName');
     $connectionMock->expects($this->any())->method('quoteInto')->will($this->returnValue('idFieldName'));
     $abstractModelMock->setIdFieldName('id');
     $abstractModelMock->setData(['id' => 12345, 'name' => 'Test Name', 'value' => 'Test Value']);
     $abstractModelMock->afterLoad();
     $this->assertEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData());
     $newData = ['value' => 'Test Value New'];
     $this->_model->expects($this->once())->method('_prepareDataForTable')->will($this->returnValue($newData));
     $abstractModelMock->addData($newData);
     $this->assertNotEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData());
     $abstractModelMock->isObjectNew(false);
     $connectionMock->expects($this->once())->method('update')->with('tableName', $newData, 'idFieldName');
     $this->_model->save($abstractModelMock);
 }
示例#13
0
 /**
  * @param \Magento\Framework\Model\ModelResource\Db\Context $context
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Catalog\Model\Config $catalogConfig
  * @param \Magento\Catalog\Model\Product\Attribute\DefaultAttributes $defaultAttributes
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Model\ModelResource\Db\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Config $catalogConfig, \Magento\Catalog\Model\Product\Attribute\DefaultAttributes $defaultAttributes, $connectionName = null)
 {
     $this->_storeManager = $storeManager;
     $this->_catalogConfig = $catalogConfig;
     $this->defaultAttributes = $defaultAttributes;
     parent::__construct($context, $connectionName);
 }
示例#14
0
 /**
  * Delete all Nonce entries associated with the consumer
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 public function _afterDelete(\Magento\Framework\Model\AbstractModel $object)
 {
     $connection = $this->getConnection();
     $connection->delete($this->getTable('oauth_nonce'), ['consumer_id' => $object->getId()]);
     $connection->delete($this->getTable('oauth_token'), ['consumer_id' => $object->getId()]);
     return parent::_afterDelete($object);
 }
 protected function _prepareAddFilterStubs()
 {
     $entityInfo = [];
     $entityInfo['entity_id_field'] = 'entity_id';
     $entityInfo['rule_id_field'] = 'rule_id';
     $entityInfo['associations_table'] = 'assoc_table';
     $connection = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $select = $this->getMock('\\Magento\\Framework\\DB\\Select', [], [], '', false);
     $collectionSelect = $this->getMock('\\Magento\\Framework\\DB\\Select', [], [], '', false);
     $connection->expects($this->any())->method('select')->will($this->returnValue($select));
     $select->expects($this->any())->method('from')->will($this->returnSelf());
     $select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->abstractCollection->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $this->_db->expects($this->any())->method('getTable')->will($this->returnArgument(0));
     $this->abstractCollection->expects($this->any())->method('getSelect')->will($this->returnValue($collectionSelect));
     $this->abstractCollection->expects($this->any())->method('_getAssociatedEntityInfo')->will($this->returnValue($entityInfo));
 }
示例#16
0
 /**
  * @param \Magento\Framework\Model\ModelResource\Db\Context $context
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Framework\Stdlib\DateTime $dateTime
  * @param StockConfigurationInterface $stockConfiguration
  * @param StoreManagerInterface $storeManager
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Model\ModelResource\Db\Context $context, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Stdlib\DateTime $dateTime, StockConfigurationInterface $stockConfiguration, StoreManagerInterface $storeManager, $connectionName = null)
 {
     parent::__construct($context, $connectionName);
     $this->_scopeConfig = $scopeConfig;
     $this->dateTime = $dateTime;
     $this->stockConfiguration = $stockConfiguration;
     $this->storeManager = $storeManager;
 }
示例#17
0
 /**
  * @param int $isFilter
  * @param string $useAggregatedData
  * @param string $mainTable
  * @dataProvider salesDataProvider
  * @return void
  */
 public function testCalculateSales($isFilter, $useAggregatedData, $mainTable)
 {
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with('sales/dashboard/use_aggregated_data', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn($useAggregatedData);
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeMock);
     $this->resourceMock->expects($this->at(0))->method('getTable')->with($mainTable);
     $this->collection->calculateSales($isFilter);
 }
示例#18
0
 /**
  * @param \Magento\Framework\Model\ModelResource\Db\Context $context
  * @param \Magento\Catalog\Helper\Data $catalogData
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $configuration
  * @param \Magento\Directory\Model\CurrencyFactory $currencyFactory
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Model\ModelResource\Db\Context $context, \Magento\Catalog\Helper\Data $catalogData, \Magento\Framework\App\Config\ScopeConfigInterface $configuration, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, $connectionName = null)
 {
     $this->_catalogData = $catalogData;
     $this->_configuration = $configuration;
     $this->_currencyFactory = $currencyFactory;
     $this->_storeManager = $storeManager;
     parent::__construct($context, $connectionName);
 }
示例#19
0
 /**
  * @param \Magento\Framework\Model\ModelResource\Db\Context $context
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Config\Model\Config\Structure $structure
  * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
  * @param \Magento\Framework\App\DeploymentConfig\Writer $writer
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Model\ModelResource\Db\Context $context, \Magento\Framework\Filesystem $filesystem, \Magento\Config\Model\Config\Structure $structure, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Framework\App\DeploymentConfig\Writer $writer, $connectionName = null)
 {
     $this->encryptor = clone $encryptor;
     parent::__construct($context, $connectionName);
     $this->directory = $filesystem->getDirectoryWrite(DirectoryList::CONFIG);
     $this->structure = $structure;
     $this->writer = $writer;
 }
示例#20
0
 /**
  * @param \Magento\Framework\Model\ModelResource\Db\Context $context
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
  * @param \Magento\Customer\Model\Session $session
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Model\ModelResource\Db\Context $context, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Catalog\Model\Layer\Resolver $layerResolver, \Magento\Customer\Model\Session $session, \Magento\Store\Model\StoreManagerInterface $storeManager, $connectionName = null)
 {
     $this->layer = $layerResolver->get();
     $this->session = $session;
     $this->storeManager = $storeManager;
     $this->_eventManager = $eventManager;
     parent::__construct($context, $connectionName);
 }
示例#21
0
 /**
  * @param \Magento\Framework\Model\ModelResource\Db\Context $context
  * @param \Magento\Framework\Acl\Builder $aclBuilder
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Acl\RootResource $rootResource
  * @param \Magento\Framework\Acl\CacheInterface $aclCache
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Model\ModelResource\Db\Context $context, \Magento\Framework\Acl\Builder $aclBuilder, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Acl\RootResource $rootResource, \Magento\Framework\Acl\CacheInterface $aclCache, $connectionName = null)
 {
     $this->_aclBuilder = $aclBuilder;
     parent::__construct($context, $connectionName);
     $this->_rootResource = $rootResource;
     $this->_aclCache = $aclCache;
     $this->_logger = $logger;
 }
示例#22
0
 /**
  * Constructor
  *
  * @param \Magento\Framework\Model\ModelResource\Db\Context $context
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  * @param \Magento\Reports\Model\FlagFactory $reportsFlagFactory
  * @param \Magento\Framework\Stdlib\DateTime $dateTime
  * @param \Magento\Framework\Stdlib\DateTime\Timezone\Validator $timezoneValidator
  * @param string $connectionName
  */
 public function __construct(\Magento\Framework\Model\ModelResource\Db\Context $context, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Reports\Model\FlagFactory $reportsFlagFactory, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\Framework\Stdlib\DateTime\Timezone\Validator $timezoneValidator, $connectionName = null)
 {
     parent::__construct($context, $connectionName);
     $this->_logger = $logger;
     $this->_localeDate = $localeDate;
     $this->_reportsFlagFactory = $reportsFlagFactory;
     $this->dateTime = $dateTime;
     $this->timezoneValidator = $timezoneValidator;
 }
示例#23
0
 /**
  * Loading string as a value or regular numeric
  *
  * @param AbstractModel $object
  * @param int|string $value
  * @param null|string $field
  * @return $this|\Magento\Framework\Model\ModelResource\Db\AbstractDb
  * @SuppressWarnings("unused")
  */
 public function load(AbstractModel $object, $value, $field = null)
 {
     if (is_numeric($value)) {
         return parent::load($object, $value);
     } else {
         $this->loadByQuery($object, $value);
     }
     return $this;
 }
示例#24
0
 /**
  * Perform actions after object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object->getIsDefault()) {
         $this->getConnection()->update($this->getMainTable(), ['is_default' => 0]);
         $where = ['website_id = ?' => $object->getId()];
         $this->getConnection()->update($this->getMainTable(), ['is_default' => 1], $where);
     }
     return parent::_afterSave($object);
 }
示例#25
0
 /**
  * Set template type, added at and modified at time
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(AbstractModel $object)
 {
     if ($object->isObjectNew()) {
         $object->setAddedAt($this->dateTime->formatDate(true));
     }
     $object->setModifiedAt($this->dateTime->formatDate(true));
     $object->setTemplateType((int) $object->getTemplateType());
     return parent::_beforeSave($object);
 }
示例#26
0
 /**
  * Add expiration date filter to select
  *
  * @param string $field
  * @param mixed $value
  * @param \Magento\Persistent\Model\Session $object
  * @return \Magento\Framework\DB\Select
  */
 protected function _getLoadSelect($field, $value, $object)
 {
     $select = parent::_getLoadSelect($field, $value, $object);
     if (!$object->getLoadExpired()) {
         $tableName = $this->getMainTable();
         $select->join(['customer' => $this->getTable('customer_entity')], 'customer.entity_id = ' . $tableName . '.customer_id')->where($tableName . '.updated_at >= ?', $object->getExpiredBefore());
     }
     return $select;
 }
示例#27
0
 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Framework\Model\AbstractModel $object)
 {
     $hasDataChanges = $object->hasDataChanges();
     $object->setIsOptionsSaved(false);
     $result = parent::save($object);
     if ($hasDataChanges && !$object->isOptionsSaved()) {
         $object->saveItemOptions();
     }
     return $result;
 }
示例#28
0
 /**
  * Convert array to comma separated value
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if (!$object->getId()) {
         $this->_checkUnique($object);
     }
     if (is_array($object->getValue())) {
         $object->setValue(join(',', $object->getValue()));
     }
     return parent::_beforeSave($object);
 }
示例#29
0
 /**
  * Perform actions after object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return \Magento\Framework\Model\ModelResource\Db\AbstractDb
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object->getAttributes()) {
         foreach ($object->getAttributes() as $attribute) {
             $attribute->setAttributeGroupId($object->getId());
             $attribute->save();
         }
     }
     return parent::_afterSave($object);
 }
示例#30
0
 /**
  * Retrieve select object for load object data
  *
  * @param string $field
  * @param mixed $value
  * @param \Magento\UrlRewrite\Model\UrlRewrite $object
  * @return \Magento\Framework\DB\Select
  */
 protected function _getLoadSelect($field, $value, $object)
 {
     /** @var $select \Magento\Framework\DB\Select */
     $select = parent::_getLoadSelect($field, $value, $object);
     if ($object->getStoreId() !== null) {
         $select->where('store_id IN(?)', [\Magento\Store\Model\Store::DEFAULT_STORE_ID, $object->getStoreId()]);
         $select->order('store_id ' . \Magento\Framework\DB\Select::SQL_DESC);
         $select->limit(1);
     }
     return $select;
 }