/** * Tests \Magento\Framework\Object->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\Object $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\Object $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; }
/** * Validate product attribute value for condition * * @param \Magento\Framework\Object $object * @return bool */ public function validate(\Magento\Framework\Object $object) { $attrCode = $this->getAttribute(); if ('category_ids' == $attrCode) { return $this->validateAttribute($object->getAvailableInCategories()); } $oldAttrValue = $object->hasData($attrCode) ? $object->getData($attrCode) : null; $this->_setAttributeValue($object); $result = $this->validateAttribute($object->getData($this->getAttribute())); $this->_restoreOldAttrValue($object, $oldAttrValue); return (bool) $result; }
/** * Before save * * @param \Magento\Framework\Object $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; }
/** * Before Attribute Save Process * * @param \Magento\Framework\Object $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; }
/** * 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\Object $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; }
/** * Return Widgets Insertion Plugin Window URL * * @param \Magento\Framework\Object $config Editor element config * @return string */ public function getWidgetWindowUrl($config) { $params = array(); $skipped = is_array($config->getData('skip_widgets')) ? $config->getData('skip_widgets') : array(); 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); }
/** * Prepare data for passed table * * @param \Magento\Framework\Object $object * @param string $table * @return array */ protected function _prepareDataForTable(\Magento\Framework\Object $object, $table) { $data = []; $fields = $this->_getWriteAdapter()->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->_getWriteAdapter()->prepareColumnValue($fields[$field], $fieldValue); } elseif (!empty($fields[$field]['NULLABLE'])) { $data[$field] = null; } } } } return $data; }
/** * Determine whether current integration came from config file * * @param \Magento\Framework\Object $row * @return bool */ protected function _isConfigBasedIntegration(Object $row) { return $row->hasData(Integration::SETUP_TYPE) && $row->getData(Integration::SETUP_TYPE) == Integration::TYPE_CONFIG; }
/** * Before save method * * @param \Magento\Framework\Object $object * @return $this */ public function beforeSave($object) { $attrCode = $this->getAttribute()->getAttributeCode(); if (!$object->hasData($attrCode) && $this->getDefaultValue()) { $object->setData($attrCode, $this->getDefaultValue()); } return $this; }
/** * Display price attribute value in base order currency and in place order currency * * @param \Magento\Framework\Object $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); }