本文整理汇总了PHP中Magento\Framework\DataObject类的典型用法代码示例。如果您正苦于以下问题:PHP DataObject类的具体用法?PHP DataObject怎么用?PHP DataObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testValidate
/**
* @param string
* @dataProvider validateProvider
*/
public function testValidate($data)
{
$object = new DataObject();
$object->setData($this->attributeName, $data);
$this->assertTrue($this->model->validate($object));
$this->assertTrue($this->model->validate($object));
}
示例2: render
/**
* Render grid column
*
* @param \Magento\Framework\DataObject $row
* @return string
*/
public function render(\Magento\Framework\DataObject $row)
{
$actions = [];
$actions[] = ['url' => $this->getUrl('adminhtml/*/preview', ['id' => $row->getId()]), 'popup' => true, 'caption' => __('Preview')];
$this->getColumn()->setActions($actions);
return parent::render($row);
}
示例3: afterSave
/**
* After save
*
* @param \Magento\Framework\DataObject $object
* @return $this|void
*/
public function afterSave($object)
{
$value = $object->getData($this->getAttribute()->getName());
if (is_array($value) && !empty($value['delete'])) {
$object->setData($this->getAttribute()->getName(), '');
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
return;
}
try {
/** @var $uploader \Magento\MediaStorage\Model\File\Uploader */
$uploader = $this->_fileUploaderFactory->create(['fileId' => $this->getAttribute()->getName()]);
$uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
} catch (\Exception $e) {
return $this;
}
$path = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('catalog/product/');
$uploader->save($path);
$fileName = $uploader->getUploadedFileName();
if ($fileName) {
$object->setData($this->getAttribute()->getName(), $fileName);
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
}
return $this;
}
示例4: render
/**
* Renders Purchases value
*
* @param \Magento\Framework\DataObject $row
* @return \Magento\Framework\Phrase|string
*/
public function render(\Magento\Framework\DataObject $row)
{
if (($value = $row->getData($this->getColumn()->getIndex())) > 0) {
return $value;
}
return __('Unlimited');
}
示例5: afterSave
/**
* Method is invoked after save
*
* @param \Magento\Framework\DataObject $object
* @return \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
*/
public function afterSave($object)
{
if ($object->getOrderItem()) {
$object->getOrderItem()->save();
}
return parent::beforeSave($object);
}
示例6: displayPrices
/**
* Get "double" prices html (block with base and place currency)
*
* @param \Magento\Framework\DataObject $dataObject
* @param float $basePrice
* @param float $price
* @param bool $strong
* @param string $separator
* @return string
*/
public function displayPrices($dataObject, $basePrice, $price, $strong = false, $separator = '<br/>')
{
$order = false;
if ($dataObject instanceof \Magento\Sales\Model\Order) {
$order = $dataObject;
} else {
$order = $dataObject->getOrder();
}
if ($order && $order->isCurrencyDifferent()) {
$res = '<strong>';
$res .= $order->formatBasePrice($basePrice);
$res .= '</strong>' . $separator;
$res .= '[' . $order->formatPrice($price) . ']';
} elseif ($order) {
$res = $order->formatPrice($price);
if ($strong) {
$res = '<strong>' . $res . '</strong>';
}
} else {
$res = $this->priceCurrency->format($price);
if ($strong) {
$res = '<strong>' . $res . '</strong>';
}
}
return $res;
}
示例7: afterSave
/**
* Save uploaded file and set its name to category
*
* @param \Magento\Framework\DataObject $object
* @return \Magento\Catalog\Model\Category\Attribute\Backend\Image
*/
public function afterSave($object)
{
$value = $object->getData($this->getAttribute()->getName() . '_additional_data');
// if no image was set - nothing to do
if (empty($value) && empty($_FILES)) {
return $this;
}
if (is_array($value) && !empty($value['delete'])) {
$object->setData($this->getAttribute()->getName(), '');
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
return $this;
}
$path = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath('catalog/category/');
try {
/** @var $uploader \Magento\MediaStorage\Model\File\Uploader */
$uploader = $this->_fileUploaderFactory->create(['fileId' => $this->getAttribute()->getName()]);
$uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
$uploader->setAllowRenameFiles(true);
$result = $uploader->save($path);
$object->setData($this->getAttribute()->getName(), $result['file']);
$this->getAttribute()->getEntity()->saveAttribute($object, $this->getAttribute()->getName());
} catch (\Exception $e) {
if ($e->getCode() != \Magento\MediaStorage\Model\File\Uploader::TMP_NAME_EMPTY) {
$this->_logger->critical($e);
}
}
return $this;
}
示例8: render
/**
* Render a grid cell as options
*
* @param \Magento\Framework\DataObject $row
* @return string|void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function render(\Magento\Framework\DataObject $row)
{
$options = $this->_getOptions();
$showMissingOptionValues = (bool) $this->getColumn()->getShowMissingOptionValues();
if (!empty($options) && is_array($options)) {
//transform option format
$output = [];
foreach ($options as $option) {
$output[$option['value']] = $option['label'];
}
$value = $row->getData($this->getColumn()->getIndex());
if (is_array($value)) {
$res = [];
foreach ($value as $item) {
if (isset($output[$item])) {
$res[] = $this->escapeHtml($output[$item]);
} elseif ($showMissingOptionValues) {
$res[] = $this->escapeHtml($item);
}
}
return implode(', ', $res);
} elseif (isset($output[$value])) {
return $this->escapeHtml($output[$value]);
} elseif (in_array($value, $output)) {
return $this->escapeHtml($value);
}
}
}
示例9: beforeSave
/**
* Set new increment id
*
* @param \Magento\Framework\DataObject $object
* @return $this
*/
public function beforeSave($object)
{
if (!$object->getId()) {
$this->getAttribute()->getEntity()->setNewIncrementId($object);
}
return $this;
}
示例10: beforeSave
/**
* Performed before data is saved
*
* @param \Magento\Framework\DataObject $object
* @return $this
*/
public function beforeSave($object)
{
if ($object->getShipment()) {
$object->setParentId($object->getShipment()->getId());
}
return parent::beforeSave($object);
}
示例11: render
/**
* Render minimal price for downloadable products
*
* @param \Magento\Framework\DataObject $row
* @return string
*/
public function render(\Magento\Framework\DataObject $row)
{
if ($row->getTypeId() == 'downloadable') {
$row->setPrice($row->getPrice());
}
return parent::render($row);
}
示例12: render
/**
* Renders grid column
*
* @param \Magento\Framework\DataObject $row
* @return string
*/
public function render(\Magento\Framework\DataObject $row)
{
if ($data = $row->getData($this->getColumn()->getIndex())) {
return $this->dateTimeFormatter->formatObject($this->_localeDate->date(new \DateTime($data)), $this->_getFormat());
}
return $this->getColumn()->getDefault();
}
示例13: _prepareArrayRow
/**
* @param \Magento\Framework\DataObject $row
*/
public function _prepareArrayRow(\Magento\Framework\DataObject $row)
{
$options = [];
$options['option_' . $this->_getAttributeRenderer()->calcOptionHash($row->getData('attribute'))] = 'selected="selected"';
$options['option_' . $this->_getDatafieldRenderer()->calcOptionHash($row->getData('datafield'))] = 'selected="selected"';
$row->setData('option_extra_attrs', $options);
}
示例14: render
/**
* Renders grid column
*
* @param \Magento\Framework\DataObject $row
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function render(\Magento\Framework\DataObject $row)
{
$values = $this->_getValues();
$value = $row->getData($this->getColumn()->getIndex());
$checked = '';
if (is_array($values)) {
$checked = in_array($value, $values) ? ' checked="checked"' : '';
} else {
$checkedValue = $this->getColumn()->getValue();
if ($checkedValue !== null) {
$checked = $value === $checkedValue ? ' checked="checked"' : '';
}
}
$disabled = '';
$disabledValues = $this->getColumn()->getDisabledValues();
if (is_array($disabledValues)) {
$disabled = in_array($value, $disabledValues) ? ' disabled="disabled"' : '';
} else {
$disabledValue = $this->getColumn()->getDisabledValue();
if ($disabledValue !== null) {
$disabled = $value === $disabledValue ? ' disabled="disabled"' : '';
}
}
$this->setDisabled($disabled);
if ($this->getNoObjectId() || $this->getColumn()->getUseIndex()) {
$v = $value;
} else {
$v = $row->getId() != "" ? $row->getId() : $value;
}
return $this->_getCheckboxHtml($v, $checked);
}
示例15: beforeSave
/**
* We need reset attribute set id to attribute after related simple product was saved
*
* @param \Magento\Catalog\Model\ResourceModel\Product $subject
* @param \Magento\Framework\DataObject $object
* @return void
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeSave(\Magento\Catalog\Model\ResourceModel\Product $subject, \Magento\Framework\DataObject $object)
{
/** @var \Magento\Catalog\Model\Product $object */
if ($object->getTypeId() == Configurable::TYPE_CODE) {
$object->getTypeInstance()->getSetAttributes($object);
}
}