Example #1
0
 /**
  * Load active profile
  *
  * @param int $metadataId
  * @return \Magento\SalesSequence\Model\Profile
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function loadActiveProfile($metadataId)
 {
     $profile = $this->profileFactory->create();
     $connection = $this->getConnection();
     $bind = ['meta_id' => $metadataId];
     $select = $connection->select()->from($this->getMainTable(), ['profile_id'])->where('meta_id = :meta_id')->where('is_active = 1');
     $profileId = $connection->fetchOne($select, $bind);
     if ($profileId) {
         $this->load($profile, $profileId);
     }
     return $profile;
 }
Example #2
0
 /**
  * Create sequence with metadata and profile
  *
  * @throws \Exception
  * @throws \Magento\Framework\Exception\AlreadyExistsException
  * @return void
  */
 public function create()
 {
     $metadata = $this->resourceMetadata->loadByEntityTypeAndStore($this->data['entity_type'], $this->data['store_id']);
     if ($metadata->getSequenceTable() == $this->getSequenceName()) {
         return;
     }
     $this->data['sequence_table'] = $this->getSequenceName();
     $this->data['is_active'] = 1;
     $profile = $this->profileFactory->create(['data' => array_intersect_key($this->data, array_flip(['prefix', 'suffix', 'start_value', 'step', 'max_value', 'warning_value', 'is_active', 'active_profile']))]);
     $profile->setHasDataChanges(true);
     $this->data['active_profile'] = $profile;
     $metadata = $this->metaFactory->create(['data' => array_intersect_key($this->data, array_flip(['entity_type', 'store_id', 'sequence_table', 'active_profile']))]);
     $metadata->setHasDataChanges(true);
     try {
         $this->resourceMetadata->save($metadata);
         $adapter = $this->appResource->getConnection('write');
         if (!$adapter->isTableExists($this->data['sequence_table'])) {
             $adapter->query($this->ddlSequence->getCreateSequenceDdl($this->data['sequence_table'], $this->data['start_value']));
         }
     } catch (Exception $e) {
         $this->resourceMetadata->delete($metadata);
         $this->logger->critical($e);
         throw $e;
     }
     $this->data = array_flip($this->pattern);
 }