/**
  * Tests \Magento\Framework\DataObject->hasData()
  */
 public function testHasData()
 {
     $this->assertFalse($this->_object->hasData());
     $this->assertFalse($this->_object->hasData('key'));
     $this->_object->setData('key', 'value');
     $this->assertTrue($this->_object->hasData('key'));
 }
 /**
  * Serialize before saving
  *
  * @param \Magento\Framework\DataObject $object
  * @return $this
  */
 public function beforeSave($object)
 {
     // parent::beforeSave() is not called intentionally
     $attrCode = $this->getAttribute()->getAttributeCode();
     if ($object->hasData($attrCode)) {
         $object->setData($attrCode, serialize($object->getData($attrCode)));
     }
     return $this;
 }
 /**
  * Before save
  *
  * @param \Magento\Framework\DataObject $object
  * @return $this
  */
 public function beforeSave($object)
 {
     if ($object->getId()) {
         return $this;
     }
     if (!$object->hasData('website_id')) {
         $object->setData('website_id', $this->_storeManager->getStore()->getWebsiteId());
     }
     return $this;
 }
 /**
  * @param string $key
  * @return mixed
  */
 public function __get($key)
 {
     if (isset($this->aliasMap[$key])) {
         return $this->__get($this->aliasMap[$key]);
     }
     if (!$this->cache->hasData($key)) {
         $value = $this->wrap($this->loadData($key));
         $this->cache->setData($key, $value);
     }
     return $this->cache->getData($key);
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 protected function _beforeSave(DataObject $post)
 {
     /** @var \Mirasvit\Blog\Model\Post $post */
     if (!$post->hasData('type')) {
         $post->setData('type', \Mirasvit\Blog\Model\Post::TYPE_POST);
     }
     if (!$post->getData('url_key')) {
         $post->setData('url_key', $this->filter->translitUrl($post->getName()));
     }
     $this->saveImage($post);
     return parent::_beforeSave($post);
 }
 /**
  * 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;
 }
Exemple #7
0
 /**
  * Display price attribute value in base order currency and in place order currency
  *
  * @param   \Magento\Framework\DataObject $dataObject
  * @param   string $code
  * @param   bool $strong
  * @param   string $separator
  * @return  string
  */
 public function displayPriceAttribute($dataObject, $code, $strong = false, $separator = '<br/>')
 {
     // Fix for 'bs_customer_bal_total_refunded' attribute
     $baseValue = $dataObject->hasData('bs_' . $code)
         ? $dataObject->getData('bs_' . $code)
         : $dataObject->getData('base_' . $code);
     return $this->displayPrices(
         $dataObject,
         $baseValue,
         $dataObject->getData($code),
         $strong,
         $separator
     );
 }
 /**
  * @param string $key
  * @return mixed
  */
 public function __get($key)
 {
     // echo "{$this->_uid}.__get(" . $key . ')';//var_export($this->aliasMap);
     if (isset($this->aliasMap[$key])) {
         return $this->__get($this->aliasMap[$key]);
     }
     if (!$this->cache->hasData($key)) {
         // echo '!hasData(' . $key . ')';
         $value = $this->wrap($this->loadData($key));
         $this->cache->setData($key, $value);
     }
     // echo 'getData(' . $key . ')';
     return $this->cache->getData($key);
 }
Exemple #9
0
 /**
  * Before Attribute Save Process
  *
  * @param \Magento\Framework\DataObject $object
  * @return $this
  */
 public function beforeSave($object)
 {
     $attributeCode = $this->getAttribute()->getName();
     if ($attributeCode == 'available_sort_by') {
         $data = $object->getData($attributeCode);
         if (!is_array($data)) {
             $data = [];
         }
         $object->setData($attributeCode, join(',', $data));
     }
     if (!$object->hasData($attributeCode)) {
         $object->setData($attributeCode, false);
     }
     return $this;
 }
Exemple #10
0
 /**
  * Return Widgets Insertion Plugin Window URL
  *
  * @param \Magento\Framework\DataObject $config Editor element config
  * @return string
  */
 public function getWidgetWindowUrl($config)
 {
     $params = [];
     $skipped = is_array($config->getData('skip_widgets')) ? $config->getData('skip_widgets') : [];
     if ($config->hasData('widget_filters')) {
         $all = $this->_widgetFactory->create()->getWidgets();
         $filtered = $this->_widgetFactory->create()->getWidgets($config->getData('widget_filters'));
         foreach ($all as $code => $widget) {
             if (!isset($filtered[$code])) {
                 $skipped[] = $widget['@']['type'];
             }
         }
     }
     if (count($skipped) > 0) {
         $params['skip_widgets'] = $this->encodeWidgetsToQuery($skipped);
     }
     return $this->_backendUrl->getUrl('adminhtml/widget/index', $params);
 }
Exemple #11
0
 /**
  * Formatting date value before save
  *
  * Should set (bool, string) correct type for empty value from html form,
  * necessary for further process, else date string
  *
  * @param \Magento\Framework\DataObject $object
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return $this
  */
 public function beforeSave($object)
 {
     $attributeName = $this->getAttribute()->getName();
     $_formated = $object->getData($attributeName . '_is_formated');
     if (!$_formated && $object->hasData($attributeName)) {
         try {
             $value = $this->formatDate($object->getData($attributeName));
         } catch (\Exception $e) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Invalid date'));
         }
         if (is_null($value)) {
             $value = $object->getData($attributeName);
         }
         $object->setData($attributeName, $value);
         $object->setData($attributeName . '_is_formated', true);
     }
     return $this;
 }
 /**
  * Prepare data for passed table
  *
  * @param DataObject $object
  * @param string $table
  * @return array
  */
 protected function _prepareDataForTable(DataObject $object, $table)
 {
     $data = [];
     $fields = $this->getConnection()->describeTable($table);
     foreach (array_keys($fields) as $field) {
         if ($object->hasData($field)) {
             $fieldValue = $object->getData($field);
             if ($fieldValue instanceof \Zend_Db_Expr) {
                 $data[$field] = $fieldValue;
             } else {
                 if (null !== $fieldValue) {
                     $fieldValue = $this->_prepareTableValueForSave($fieldValue, $fields[$field]['DATA_TYPE']);
                     $data[$field] = $this->getConnection()->prepareColumnValue($fields[$field], $fieldValue);
                 } elseif (!empty($fields[$field]['NULLABLE'])) {
                     $data[$field] = null;
                 }
             }
         }
     }
     return $data;
 }
 /**
  * Before save method
  *
  * @param \Magento\Framework\DataObject $object
  * @return $this
  */
 public function beforeSave($object)
 {
     $attrCode = $this->getAttribute()->getAttributeCode();
     if (!$object->hasData($attrCode) && $this->getDefaultValue()) {
         $object->setData($attrCode, $this->getDefaultValue());
     }
     return $this;
 }
 /**
  * Determine whether current integration came from config file
  *
  * @param \Magento\Framework\DataObject $row
  * @return bool
  */
 protected function _isConfigBasedIntegration(DataObject $row)
 {
     return $row->hasData(Integration::SETUP_TYPE) && $row->getData(Integration::SETUP_TYPE) == Integration::TYPE_CONFIG;
 }