Esempio n. 1
0
 /**
  * Before save
  *
  * @param \Magento\Framework\DataObject $object
  * @return $this
  */
 public function beforeSave($object)
 {
     if ($object->getId()) {
         return $this;
     }
     if (!$object->hasStoreId()) {
         $object->setStoreId($this->_storeManager->getStore()->getId());
     }
     if (!$object->hasData('created_in')) {
         $object->setData('created_in', $this->_storeManager->getStore($object->getStoreId())->getName());
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * Check customer scope, email and confirmation key before saving
  *
  * @param \Magento\Framework\DataObject $customer
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _beforeSave(\Magento\Framework\DataObject $customer)
 {
     /** @var \Magento\Customer\Model\Customer $customer */
     if ($customer->getStoreId() === null) {
         $customer->setStoreId($this->storeManager->getStore()->getId());
     }
     $customer->getGroupId();
     parent::_beforeSave($customer);
     if (!$customer->getEmail()) {
         throw new ValidatorException(__('Please enter a customer email.'));
     }
     $connection = $this->getConnection();
     $bind = ['email' => $customer->getEmail()];
     $select = $connection->select()->from($this->getEntityTable(), [$this->getEntityIdField()])->where('email = :email');
     if ($customer->getSharingConfig()->isWebsiteScope()) {
         $bind['website_id'] = (int) $customer->getWebsiteId();
         $select->where('website_id = :website_id');
     }
     if ($customer->getId()) {
         $bind['entity_id'] = (int) $customer->getId();
         $select->where('entity_id != :entity_id');
     }
     $result = $connection->fetchOne($select, $bind);
     if ($result) {
         throw new AlreadyExistsException(__('A customer with the same email already exists in an associated website.'));
     }
     // set confirmation key logic
     if ($customer->getForceConfirmed() || $customer->getPasswordHash() == '') {
         $customer->setConfirmation(null);
     } elseif (!$customer->getId() && $customer->isConfirmationRequired()) {
         $customer->setConfirmation($customer->getRandomConfirmationKey());
     }
     // remove customer confirmation key from database, if empty
     if (!$customer->getConfirmation()) {
         $customer->setConfirmation(null);
     }
     $this->_validate($customer);
     return $this;
 }
Esempio n. 3
0
 /**
  * Get all product images
  *
  * @param \Magento\Framework\DataObject $product
  * @param int $storeId
  * @return array
  */
 protected function _getAllProductImages($product, $storeId)
 {
     $product->setStoreId($storeId);
     $gallery = $this->_mediaAttribute->loadProductGalleryByAttributeId($product, $this->_getMediaGalleryModel()->getAttribute()->getId());
     $imagesCollection = [];
     if ($gallery) {
         $productMediaPath = $this->_getMediaConfig()->getBaseMediaUrlAddition();
         foreach ($gallery as $image) {
             $imagesCollection[] = new \Magento\Framework\DataObject(['url' => $productMediaPath . $image['file'], 'caption' => $image['label'] ? $image['label'] : $image['label_default']]);
         }
     }
     return $imagesCollection;
 }