예제 #1
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);
 }
 /**
  * Get current store id or setted store id
  *
  * @return int
  */
 public function getStoreId()
 {
     if ($storeId = parent::getStoreId()) {
         return $storeId;
     }
     return $this->storeManager->getStore()->getId();
 }
예제 #3
0
 /**
  * Remove configuration data after delete store
  *
  * @param \Magento\Framework\Model\AbstractModel $model
  * @return $this
  */
 protected function _afterDelete(\Magento\Framework\Model\AbstractModel $model)
 {
     $where = ['scope = ?' => \Magento\Store\Model\ScopeInterface::SCOPE_STORES, 'scope_id = ?' => $model->getStoreId()];
     $this->getConnection()->delete($this->getTable('core_config_data'), $where);
     $this->configCache->clean();
     return $this;
 }
예제 #4
0
파일: Design.php 프로젝트: aiesh/magento2
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 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()) && $this->dateTime->toTimestamp($object->getDateFrom()) > $this->dateTime->toTimestamp($object->getDateTo())) {
         throw new \Magento\Framework\Model\Exception(__('Start date cannot be greater than end date.'));
     }
     $check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId());
     if ($check) {
         throw new \Magento\Framework\Model\Exception(__('Your design change for the specified store intersects with another one, please specify another date range.'));
     }
     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);
 }
예제 #5
0
 /**
  * Save relations for Customer
  *
  * @param \Magento\Framework\Model\AbstractModel $customer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function processRelation(\Magento\Framework\Model\AbstractModel $customer)
 {
     $defaultBillingId = $customer->getData('default_billing');
     $defaultShippingId = $customer->getData('default_shipping');
     /** @var \Magento\Customer\Model\Address $address */
     foreach ($customer->getAddresses() as $address) {
         if ($address->getData('_deleted')) {
             if ($address->getId() == $defaultBillingId) {
                 $customer->setData('default_billing', null);
             }
             if ($address->getId() == $defaultShippingId) {
                 $customer->setData('default_shipping', null);
             }
             $removedAddressId = $address->getId();
             $address->delete();
             // Remove deleted address from customer address collection
             $customer->getAddressesCollection()->removeItemByKey($removedAddressId);
         } else {
             $address->setParentId($customer->getId())->setStoreId($customer->getStoreId())->setIsCustomerSaveTransaction(true)->save();
             if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling()) && $address->getId() != $defaultBillingId) {
                 $customer->setData('default_billing', $address->getId());
             }
             if (($address->getIsPrimaryShipping() || $address->getIsDefaultShipping()) && $address->getId() != $defaultShippingId) {
                 $customer->setData('default_shipping', $address->getId());
             }
         }
     }
     $changedAddresses = [];
     $changedAddresses['default_billing'] = $customer->getData('default_billing');
     $changedAddresses['default_shipping'] = $customer->getData('default_shipping');
     $customer->getResource()->getConnection()->update($customer->getResource()->getTable('customer_entity'), $changedAddresses, $customer->getResource()->getConnection()->quoteInto('entity_id = ?', $customer->getId()));
 }
예제 #6
0
 /**
  * Custom load model only by query text (skip synonym for)
  *
  * @param AbstractModel $object
  * @param string $value
  * @return $this
  */
 public function loadByQueryText(AbstractModel $object, $value)
 {
     $select = $this->getConnection()->select()->from($this->getMainTable())->where('query_text = ?', $value)->where('store_id = ?', $object->getStoreId())->limit(1);
     $data = $this->getConnection()->fetchRow($select);
     if ($data) {
         $object->setData($data);
         $this->_afterLoad($object);
     }
     return $this;
 }
예제 #7
0
 /**
  * Get loaded Code object by Entity
  *
  * @param \Magento\Framework\Model\AbstractModel $entity
  * @return \Magento\GoogleOptimizer\Model\Code
  */
 public function getCodeObjectByEntity(\Magento\Framework\Model\AbstractModel $entity)
 {
     $this->_entity = $entity;
     $this->_checkEntityIsEmpty();
     if ($entity instanceof \Magento\Cms\Model\Page) {
         $this->_codeModel->loadByEntityIdAndType($entity->getId(), $this->_getEntityType());
     } else {
         $this->_codeModel->loadByEntityIdAndType($entity->getId(), $this->_getEntityType(), $entity->getStoreId());
     }
     return $this->_codeModel;
 }
 public function generate(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object->getData('identifier')) {
         return;
     }
     $identifier = trim($object->getData('title'));
     if (!$identifier) {
         return;
     }
     $from = ['Á', 'À', 'Â', 'Ä', 'Ă', 'Ā', 'Ã', 'Å', 'Ą', 'Æ', 'Ć', 'Ċ', 'Ĉ', 'Č', 'Ç', 'Ď', 'Đ', 'Ð', 'É', 'È', 'Ė', 'Ê', 'Ë', 'Ě', 'Ē', 'Ę', 'Ə', 'Ġ', 'Ĝ', 'Ğ', 'Ģ', 'á', 'à', 'â', 'ä', 'ă', 'ā', 'ã', 'å', 'ą', 'æ', 'ć', 'ċ', 'ĉ', 'č', 'ç', 'ď', 'đ', 'ð', 'é', 'è', 'ė', 'ê', 'ë', 'ě', 'ē', 'ę', 'ə', 'ġ', 'ĝ', 'ğ', 'ģ', 'Ĥ', 'Ħ', 'I', 'Í', 'Ì', 'İ', 'Î', 'Ï', 'Ī', 'Į', 'IJ', 'Ĵ', 'Ķ', 'Ļ', 'Ł', 'Ń', 'Ň', 'Ñ', 'Ņ', 'Ó', 'Ò', 'Ô', 'Ö', 'Õ', 'Ő', 'Ø', 'Ơ', 'Œ', 'ĥ', 'ħ', 'ı', 'í', 'ì', 'i', 'î', 'ï', 'ī', 'į', 'ij', 'ĵ', 'ķ', 'ļ', 'ł', 'ń', 'ň', 'ñ', 'ņ', 'ó', 'ò', 'ô', 'ö', 'õ', 'ő', 'ø', 'ơ', 'œ', 'Ŕ', 'Ř', 'Ś', 'Ŝ', 'Š', 'Ş', 'Ť', 'Ţ', 'Þ', 'Ú', 'Ù', 'Û', 'Ü', 'Ŭ', 'Ū', 'Ů', 'Ų', 'Ű', 'Ư', 'Ŵ', 'Ý', 'Ŷ', 'Ÿ', 'Ź', 'Ż', 'Ž', 'ŕ', 'ř', 'ś', 'ŝ', 'š', 'ş', 'ß', 'ť', 'ţ', 'þ', 'ú', 'ù', 'û', 'ü', 'ŭ', 'ū', 'ů', 'ų', 'ű', 'ư', 'ŵ', 'ý', 'ŷ', 'ÿ', 'ź', 'ż', 'ž', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я', 'І', 'і', 'Ї', 'ї', 'Є', 'є', ' & ', '&'];
     $to = ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'C', 'C', 'C', 'C', 'D', 'D', 'D', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'G', 'G', 'G', 'G', 'G', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'g', 'g', 'g', 'g', 'g', 'H', 'H', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'IJ', 'J', 'K', 'L', 'L', 'N', 'N', 'N', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'CE', 'h', 'h', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'ij', 'j', 'k', 'l', 'l', 'n', 'n', 'n', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'R', 'R', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'W', 'Y', 'Y', 'Y', 'Z', 'Z', 'Z', 'r', 'r', 's', 's', 's', 's', 'B', 't', 't', 'b', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'w', 'y', 'y', 'y', 'z', 'z', 'z', 'A', 'B', 'V', 'H', 'D', 'e', 'Io', 'Z', 'Z', 'Y', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'Ch', 'C', 'Ch', 'Sh', 'Shtch', '', 'Y', '', 'E', 'Iu', 'Ia', 'a', 'b', 'v', 'h', 'd', 'e', 'io', 'z', 'z', 'y', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'ch', 'c', 'ch', 'sh', 'shtch', '', 'y', '', 'e', 'iu', 'ia', 'I', 'i', 'Ji', 'ji', 'Je', 'je', '-and-', '-and-'];
     $identifier = str_replace($from, $to, $identifier);
     $identifier = mb_strtolower($identifier);
     $identifier = preg_replace('/[^A-Za-z0-9-]+/', '-', $identifier);
     $identifier = preg_replace('/[--]+/', '-', $identifier);
     $identifier = trim($identifier, '-');
     $post = $this->_postFactory->create();
     $category = $this->_categoryFactory->create();
     $number = 1;
     while (true) {
         $finalIdentifier = $identifier . ($number > 1 ? '-' . $number : '');
         $postId = $post->checkIdentifier($finalIdentifier, $object->getStoreId());
         $categoryId = $category->checkIdentifier($finalIdentifier, $object->getStoreId());
         if (!$postId && !$categoryId) {
             break;
         } else {
             if ($postId && $postId == $object->getId() && $object instanceof \Magefan\Blog\Model\Post) {
                 break;
             }
             if ($categoryId && $categoryId == $object->getId() && $object instanceof \Magefan\Blog\Model\Category) {
                 break;
             }
         }
         $number++;
     }
     $object->setData('identifier', $finalIdentifier);
 }
예제 #9
0
 /**
  * Set attribute value
  *
  * @param \Magento\Framework\Model\AbstractModel $model
  * @return $this
  */
 protected function _setAttributeValue(\Magento\Framework\Model\AbstractModel $model)
 {
     $storeId = $model->getStoreId();
     $defaultStoreId = \Magento\Store\Model\Store::DEFAULT_STORE_ID;
     if (!isset($this->_entityAttributeValues[$model->getId()])) {
         return $this;
     }
     $productValues = $this->_entityAttributeValues[$model->getId()];
     if (!isset($productValues[$storeId]) && !isset($productValues[$defaultStoreId])) {
         return $this;
     }
     $value = isset($productValues[$storeId]) ? $productValues[$storeId] : $productValues[$defaultStoreId];
     $value = $this->_prepareDatetimeValue($value, $model);
     $value = $this->_prepareMultiselectValue($value, $model);
     $model->setData($this->getAttribute(), $value);
     return $this;
 }
 /**
  * @param \Magento\Sales\Model\Spi\InvoiceResourceInterface $subject
  * @param \Closure $proceed
  *
  *        I include both the extended AbstractModel and implemented Interface here for the IDE's benefit
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Sales\Api\Data\InvoiceInterface $entity
  * @return \Magento\Sales\Model\Spi\InvoiceResourceInterface
  * @throws \Magento\Framework\Exception\CouldNotSaveException
  */
 public function aroundSave(InvoiceResourceInterface $subject, \Closure $proceed, AbstractModel $entity)
 {
     // Check to see if this is a newly created entity and store the determination for later evaluation after
     // the entity is saved via plugin closure. After the entity is saved it will not be listed as new any longer.
     $isObjectNew = $entity->isObjectNew();
     // Save AvaTax extension attributes
     if ($this->avaTaxConfig->isModuleEnabled($entity->getStoreId())) {
         // check to see if any extension attributes exist and set them on the model for saving to the db
         $extensionAttributes = $entity->getExtensionAttributes();
         if ($extensionAttributes && $extensionAttributes->getAvataxIsUnbalanced() !== null) {
             $entity->setData('avatax_is_unbalanced', $extensionAttributes->getAvataxIsUnbalanced());
         }
         if ($extensionAttributes && $extensionAttributes->getBaseAvataxTaxAmount() !== null) {
             $entity->setData('base_avatax_tax_amount', $extensionAttributes->getBaseAvataxTaxAmount());
         }
         // Updating a field to trigger a change to the record when avatax_is_unbalanced and base_avatax_tax_amount
         // are both false or 0 which evaluate the same as null in the isModified check
         if ($extensionAttributes && ($extensionAttributes->getAvataxIsUnbalanced() !== null && ($entity->getOrigData('avatax_is_unbalanced') === null || $extensionAttributes->getAvataxIsUnbalanced() != $entity->getOrigData('avatax_is_unbalanced')) || $extensionAttributes->getBaseAvataxTaxAmount() !== null && ($entity->getOrigData('base_avatax_tax_amount') === null || $extensionAttributes->getBaseAvataxTaxAmount() != $entity->getOrigData('base_avatax_tax_amount')))) {
             $entity->setUpdatedAt($this->dateTime->gmtDate());
         }
     }
     /** @var \Magento\Sales\Model\Spi\InvoiceResourceInterface $resultEntity */
     $resultEntity = $proceed($entity);
     /** @var \Magento\Sales\Model\Order $order */
     $order = $entity->getOrder();
     $isVirtual = $order->getIsVirtual();
     $address = $isVirtual ? $entity->getBillingAddress() : $entity->getShippingAddress();
     $storeId = $entity->getStoreId();
     // Queue the entity to be sent to AvaTax
     if ($this->avaTaxConfig->isModuleEnabled($entity->getStoreId()) && $this->avaTaxConfig->getTaxMode($entity->getStoreId()) == Config::TAX_MODE_ESTIMATE_AND_SUBMIT && $this->avaTaxConfig->isAddressTaxable($address, $storeId)) {
         // Add this entity to the avatax processing queue if this is a new entity
         if ($isObjectNew) {
             /** @var Queue $queue */
             $queue = $this->queueFactory->create();
             $queue->build($entity->getStoreId(), Queue::ENTITY_TYPE_CODE_INVOICE, $entity->getEntityId(), $entity->getIncrementId(), Queue::QUEUE_STATUS_PENDING);
             $queue->save();
             $this->avaTaxLogger->debug(__('Added entity to the queue'), ['queue_id' => $queue->getId(), 'entity_type_code' => Queue::ENTITY_TYPE_CODE_INVOICE, 'entity_id' => $entity->getEntityId()]);
         }
     }
     return $resultEntity;
 }
 /**
  * Assign category to store views
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $oldStores = $this->lookupStoreIds($object->getId());
     $newStores = (array) $object->getStores();
     if (empty($newStores)) {
         $newStores = (array) $object->getStoreId();
     }
     $table = $this->getTable('magefan_blog_category_store');
     $insert = array_diff($newStores, $oldStores);
     $delete = array_diff($oldStores, $newStores);
     if ($delete) {
         $where = ['category_id = ?' => (int) $object->getId(), 'store_id IN (?)' => $delete];
         $this->getConnection()->delete($table, $where);
     }
     if ($insert) {
         $data = [];
         foreach ($insert as $storeId) {
             $data[] = ['category_id' => (int) $object->getId(), 'store_id' => (int) $storeId];
         }
         $this->getConnection()->insertMultiple($table, $data);
     }
     return parent::_afterSave($object);
 }
예제 #12
0
 /**
  * Assign page to store views
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $oldStores = $this->lookupStoreIds($object->getId());
     $newStores = (array) $object->getStores();
     if (empty($newStores)) {
         $newStores = (array) $object->getStoreId();
     }
     $table = $this->getTable('cms_page_store');
     $insert = array_diff($newStores, $oldStores);
     $delete = array_diff($oldStores, $newStores);
     if ($delete) {
         $where = array('page_id = ?' => (int) $object->getId(), 'store_id IN (?)' => $delete);
         $this->_getWriteAdapter()->delete($table, $where);
     }
     if ($insert) {
         $data = array();
         foreach ($insert as $storeId) {
             $data[] = array('page_id' => (int) $object->getId(), 'store_id' => (int) $storeId);
         }
         $this->_getWriteAdapter()->insertMultiple($table, $data);
     }
     return parent::_afterSave($object);
 }
예제 #13
0
 /**
  * Save titles
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $object)
 {
     $connection = $this->getConnection();
     $titleTableName = $this->getTable('catalog_product_option_title');
     foreach ([\Magento\Store\Model\Store::DEFAULT_STORE_ID, $object->getStoreId()] as $storeId) {
         $existInCurrentStore = $this->getColFromOptionTable($titleTableName, (int) $object->getId(), (int) $storeId);
         $existInDefaultStore = $this->getColFromOptionTable($titleTableName, (int) $object->getId(), \Magento\Store\Model\Store::DEFAULT_STORE_ID);
         if ($object->getTitle()) {
             if ($existInCurrentStore) {
                 if ($object->getStoreId() == $storeId) {
                     $data = $this->_prepareDataForTable(new \Magento\Framework\DataObject(['title' => $object->getTitle()]), $titleTableName);
                     $connection->update($titleTableName, $data, ['option_id = ?' => $object->getId(), 'store_id  = ?' => $storeId]);
                 }
             } else {
                 // we should insert record into not default store only of if it does not exist in default store
                 if ($storeId == \Magento\Store\Model\Store::DEFAULT_STORE_ID && !$existInDefaultStore || $storeId != \Magento\Store\Model\Store::DEFAULT_STORE_ID && !$existInCurrentStore) {
                     $data = $this->_prepareDataForTable(new \Magento\Framework\DataObject(['option_id' => $object->getId(), 'store_id' => $storeId, 'title' => $object->getTitle()]), $titleTableName);
                     $connection->insert($titleTableName, $data);
                 }
             }
         } else {
             if ($object->getId() && $object->getStoreId() > \Magento\Store\Model\Store::DEFAULT_STORE_ID && $storeId) {
                 $connection->delete($titleTableName, ['option_id = ?' => $object->getId(), 'store_id  = ?' => $object->getStoreId()]);
             }
         }
     }
 }
예제 #14
0
 /**
  * Save option value title data
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $object)
 {
     foreach ([\Magento\Store\Model\Store::DEFAULT_STORE_ID, $object->getStoreId()] as $storeId) {
         $titleTable = $this->getTable('catalog_product_option_type_title');
         $select = $this->_getReadAdapter()->select()->from($titleTable, ['option_type_id'])->where('option_type_id = ?', (int) $object->getId())->where('store_id = ?', (int) $storeId);
         $optionTypeId = $this->_getReadAdapter()->fetchOne($select);
         $existInCurrentStore = $this->getOptionIdFromOptionTable($titleTable, (int) $object->getId(), (int) $storeId);
         if ($object->getTitle()) {
             if ($existInCurrentStore) {
                 if ($storeId == $object->getStoreId()) {
                     $where = ['option_type_id = ?' => (int) $optionTypeId, 'store_id = ?' => $storeId];
                     $bind = ['title' => $object->getTitle()];
                     $this->_getWriteAdapter()->update($titleTable, $bind, $where);
                 }
             } else {
                 $existInDefaultStore = $this->getOptionIdFromOptionTable($titleTable, (int) $object->getId(), \Magento\Store\Model\Store::DEFAULT_STORE_ID);
                 // we should insert record into not default store only of if it does not exist in default store
                 if ($storeId == \Magento\Store\Model\Store::DEFAULT_STORE_ID && !$existInDefaultStore || $storeId != \Magento\Store\Model\Store::DEFAULT_STORE_ID && !$existInCurrentStore) {
                     $bind = ['option_type_id' => (int) $object->getId(), 'store_id' => $storeId, 'title' => $object->getTitle()];
                     $this->_getWriteAdapter()->insert($titleTable, $bind);
                 }
             }
         } else {
             if ($storeId && $optionTypeId && $object->getStoreId() > \Magento\Store\Model\Store::DEFAULT_STORE_ID) {
                 $where = ['option_type_id = ?' => (int) $optionTypeId, 'store_id = ?' => $storeId];
                 $this->_getWriteAdapter()->delete($titleTable, $where);
             }
         }
     }
 }
예제 #15
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\Object $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($this->_useIncrementId && !$object->getIncrementId()) {
         /* @var $entityType \Magento\Eav\Model\Entity\Type */
         $entityType = $this->_eavEntityTypeFactory->create()->loadByCode($this->_entityTypeForIncrementId);
         $object->setIncrementId($entityType->fetchNewIncrementId($object->getStoreId()));
     }
     parent::_beforeSave($object);
     return $this;
 }
예제 #16
0
 /**
  * Assign page to store views
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \AddictedToMagento\DynamicForms\Model\Form $object */
     $oldStores = $this->lookupStoreIds($object->getId());
     $newStores = (array) $object->getStores();
     if (empty($newStores)) {
         $newStores = (array) $object->getStoreId();
     }
     $table = $this->getTable(self::STORE_TABLE_NAME);
     $insert = array_diff($newStores, $oldStores);
     $delete = array_diff($oldStores, $newStores);
     if ($delete) {
         $where = ['form_id = ?' => (int) $object->getId(), 'store_id IN (?)' => $delete];
         $this->getConnection()->delete($table, $where);
     }
     if ($insert) {
         $data = [];
         foreach ($insert as $storeId) {
             $data[] = ['form_id' => (int) $object->getId(), 'store_id' => (int) $storeId];
         }
         $this->getConnection()->insertMultiple($table, $data);
     }
     return parent::_afterSave($object);
 }
예제 #17
0
 /**
  * Perform actions after object save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(AbstractModel $object)
 {
     $adapter = $this->_getWriteAdapter();
     /**
      * save detail
      */
     $detail = ['title' => $object->getTitle(), 'detail' => $object->getDetail(), 'nickname' => $object->getNickname()];
     $select = $adapter->select()->from($this->_reviewDetailTable, 'detail_id')->where('review_id = :review_id');
     $detailId = $adapter->fetchOne($select, [':review_id' => $object->getId()]);
     if ($detailId) {
         $condition = ["detail_id = ?" => $detailId];
         $adapter->update($this->_reviewDetailTable, $detail, $condition);
     } else {
         $detail['store_id'] = $object->getStoreId();
         $detail['customer_id'] = $object->getCustomerId();
         $detail['review_id'] = $object->getId();
         $adapter->insert($this->_reviewDetailTable, $detail);
     }
     /**
      * save stores
      */
     $stores = $object->getStores();
     if (!empty($stores)) {
         $condition = ['review_id = ?' => $object->getId()];
         $adapter->delete($this->_reviewStoreTable, $condition);
         $insertedStoreIds = [];
         foreach ($stores as $storeId) {
             if (in_array($storeId, $insertedStoreIds)) {
                 continue;
             }
             $insertedStoreIds[] = $storeId;
             $storeInsert = ['store_id' => $storeId, 'review_id' => $object->getId()];
             $adapter->insert($this->_reviewStoreTable, $storeInsert);
         }
     }
     // reaggregate ratings, that depend on this review
     $this->_aggregateRatings($this->_loadVotedRatingIds($object->getId()), $object->getEntityPkValue());
     return $this;
 }
예제 #18
0
 /**
  * Save option value title data
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return void
  */
 protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $object)
 {
     $titleTable = $this->getTable('catalog_product_option_type_title');
     if (!$object->getData('scope', 'title')) {
         $select = $this->_getReadAdapter()->select()->from($titleTable, array('option_type_id'))->where('option_type_id = ?', (int) $object->getId())->where('store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID);
         $optionTypeId = $this->_getReadAdapter()->fetchOne($select);
         if ($optionTypeId) {
             if ($object->getStoreId() == '0') {
                 $where = array('option_type_id = ?' => (int) $optionTypeId, 'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID);
                 $bind = array('title' => $object->getTitle());
                 $bind = array('title' => $object->getTitle());
                 $this->_getWriteAdapter()->update($titleTable, $bind, $where);
             }
         } else {
             $bind = array('option_type_id' => (int) $object->getId(), 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, 'title' => $object->getTitle());
             $this->_getWriteAdapter()->insert($titleTable, $bind);
         }
     }
     if ($object->getStoreId() != '0' && !$object->getData('scope', 'title')) {
         $select = $this->_getReadAdapter()->select()->from($titleTable, array('option_type_id'))->where('option_type_id = ?', (int) $object->getId())->where('store_id = ?', (int) $object->getStoreId());
         $optionTypeId = $this->_getReadAdapter()->fetchOne($select);
         if ($optionTypeId) {
             $bind = array('title' => $object->getTitle());
             $where = array('option_type_id = ?' => (int) $optionTypeId, 'store_id = ?' => (int) $object->getStoreId());
             $this->_getWriteAdapter()->update($titleTable, $bind, $where);
         } else {
             $bind = array('option_type_id' => (int) $object->getId(), 'store_id' => (int) $object->getStoreId(), 'title' => $object->getTitle());
             $this->_getWriteAdapter()->insert($titleTable, $bind);
         }
     } else {
         if ($object->getData('scope', 'title')) {
             $where = array('option_type_id = ?' => (int) $object->getId(), 'store_id = ?' => (int) $object->getStoreId());
             $this->_getWriteAdapter()->delete($titleTable, $where);
         }
     }
 }
예제 #19
0
 /**
  * @param AbstractModel $object
  * @param mixed $value
  * @param null $field
  * @return bool|int|string
  * @throws LocalizedException
  * @throws \Exception
  */
 private function getBlockId(AbstractModel $object, $value, $field = null)
 {
     $entityMetadata = $this->metadataPool->getMetadata(BlockInterface::class);
     if (!is_numeric($value) && $field === null) {
         $field = 'identifier';
     } elseif (!$field) {
         $field = $entityMetadata->getIdentifierField();
     }
     $entityId = $value;
     if ($field != $entityMetadata->getIdentifierField() || $object->getStoreId()) {
         $select = $this->_getLoadSelect($field, $value, $object);
         $select->reset(Select::COLUMNS)->columns($this->getMainTable() . '.' . $entityMetadata->getIdentifierField())->limit(1);
         $result = $this->getConnection()->fetchCol($select);
         $entityId = count($result) ? $result[0] : false;
     }
     return $entityId;
 }
예제 #20
0
 /**
  * @param AbstractModel $object
  * @param string $field
  * @param string $value
  * @return Select
  */
 private function getQuerySelect(AbstractModel $object, $field, $value)
 {
     $select = $this->getConnection()->select();
     $select->from($this->getMainTable())->where($field . ' = ?', $value)->where('store_id = ?', $object->getStoreId())->limit(1);
     return $select;
 }
예제 #21
0
 /**
  * Perform actions before object save
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\Object $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object instanceof EntityInterface && $object->getIncrementId() == null) {
         $object->setIncrementId($this->salesIncrement->getNextValue($object->getStoreId()));
     }
     parent::_beforeSave($object);
     return $this;
 }
예제 #22
0
파일: Page.php 프로젝트: rafaelstz/magento2
 /**
  * Load an object
  *
  * @param CmsPage|AbstractModel $object
  * @param mixed $value
  * @param string $field field to load by (defaults to model id)
  * @return $this
  */
 public function load(AbstractModel $object, $value, $field = null)
 {
     $entityMetadata = $this->metadataPool->getMetadata(PageInterface::class);
     if (!is_numeric($value) && $field === null) {
         $field = 'identifier';
     } elseif (!$field) {
         $field = $entityMetadata->getIdentifierField();
     }
     $isId = true;
     if ($field != $entityMetadata->getIdentifierField() || $object->getStoreId()) {
         $select = $this->_getLoadSelect($field, $value, $object);
         $select->reset(Select::COLUMNS)->columns($this->getMainTable() . '.' . $entityMetadata->getIdentifierField())->limit(1);
         $result = $this->getConnection()->fetchCol($select);
         $value = count($result) ? $result[0] : $value;
         $isId = count($result);
     }
     if ($isId) {
         $this->entityManager->load($object, $value, PageInterface::class);
     }
     return $this;
 }
 /**
  * Assign post to store views, categories, related posts, etc.
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $oldIds = $this->lookupStoreIds($object->getId());
     $newIds = (array) $object->getStores();
     if (empty($newIds)) {
         $newIds = (array) $object->getStoreId();
     }
     $this->_updateLinks($object, $newIds, $oldIds, 'magefan_blog_post_store', 'store_id');
     $newIds = (array) $object->getCategories();
     if (is_array($newIds)) {
         $oldIds = $this->lookupCategoryIds($object->getId());
         $this->_updateLinks($object, $newIds, $oldIds, 'magefan_blog_post_category', 'category_id');
     }
     $newIds = $object->getRelatedPostIds();
     if (is_array($newIds)) {
         $oldIds = $this->lookupRelatedPostIds($object->getId());
         $this->_updateLinks($object, $newIds, $oldIds, 'magefan_blog_post_relatedpost', 'related_id');
     }
     $newIds = $object->getRelatedProductIds();
     if (is_array($newIds)) {
         $oldIds = $this->lookupRelatedProductIds($object->getId());
         $this->_updateLinks($object, $newIds, $oldIds, 'magefan_blog_post_relatedproduct', 'related_id');
     }
     return parent::_afterSave($object);
 }
예제 #24
0
 /**
  * Save titles
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return void
  */
 protected function _saveValueTitles(\Magento\Framework\Model\AbstractModel $object)
 {
     $readAdapter = $this->_getReadAdapter();
     $writeAdapter = $this->_getWriteAdapter();
     $titleTable = $this->getTable('catalog_product_option_title');
     //title
     if (!$object->getData('scope', 'title')) {
         $statement = $readAdapter->select()->from($titleTable)->where('option_id = ?', $object->getId())->where('store_id  = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID);
         if ($readAdapter->fetchOne($statement)) {
             if ($object->getStoreId() == '0') {
                 $data = $this->_prepareDataForTable(new \Magento\Framework\Object(array('title' => $object->getTitle())), $titleTable);
                 $writeAdapter->update($titleTable, $data, array('option_id = ?' => $object->getId(), 'store_id  = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID));
             }
         } else {
             $data = $this->_prepareDataForTable(new \Magento\Framework\Object(array('option_id' => $object->getId(), 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, 'title' => $object->getTitle())), $titleTable);
             $writeAdapter->insert($titleTable, $data);
         }
     }
     if ($object->getStoreId() != '0' && !$object->getData('scope', 'title')) {
         $statement = $readAdapter->select()->from($titleTable)->where('option_id = ?', $object->getId())->where('store_id  = ?', $object->getStoreId());
         if ($readAdapter->fetchOne($statement)) {
             $data = $this->_prepareDataForTable(new \Magento\Framework\Object(array('title' => $object->getTitle())), $titleTable);
             $writeAdapter->update($titleTable, $data, array('option_id = ?' => $object->getId(), 'store_id  = ?' => $object->getStoreId()));
         } else {
             $data = $this->_prepareDataForTable(new \Magento\Framework\Object(array('option_id' => $object->getId(), 'store_id' => $object->getStoreId(), 'title' => $object->getTitle())), $titleTable);
             $writeAdapter->insert($titleTable, $data);
         }
     } elseif ($object->getData('scope', 'title')) {
         $writeAdapter->delete($titleTable, array('option_id = ?' => $object->getId(), 'store_id  = ?' => $object->getStoreId()));
     }
 }
예제 #25
0
파일: Store.php 프로젝트: aiesh/magento2
 /**
  * Remove configuration data after delete store
  *
  * @param \Magento\Framework\Model\AbstractModel $model
  * @return $this
  */
 protected function _afterDelete(\Magento\Framework\Model\AbstractModel $model)
 {
     $where = array('scope = ?' => \Magento\Store\Model\ScopeInterface::SCOPE_STORES, 'scope_id = ?' => $model->getStoreId());
     $this->_getWriteAdapter()->delete($this->getTable('core_config_data'), $where);
     return $this;
 }