當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Framework\DataObject類代碼示例

本文整理匯總了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));
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:11,代碼來源:CustomlayoutupdateTest.php

示例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);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:13,代碼來源:Action.php

示例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;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:32,代碼來源:Image.php

示例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');
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:13,代碼來源:Purchases.php

示例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);
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:13,代碼來源:Item.php

示例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;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:36,代碼來源:Admin.php

示例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;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:34,代碼來源:Image.php

示例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);
         }
     }
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:35,代碼來源:Options.php

示例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;
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:13,代碼來源:Increment.php

示例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);
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:13,代碼來源:Child.php

示例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);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:13,代碼來源:Price.php

示例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();
 }
開發者ID:whoople,項目名稱:magento2-testing,代碼行數:13,代碼來源:Date.php

示例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);
 }
開發者ID:dotmailer,項目名稱:dotmailer-magento2-extension,代碼行數:10,代碼來源:Customdatafields.php

示例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);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:39,代碼來源:Checkbox.php

示例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);
     }
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:16,代碼來源:Product.php


注:本文中的Magento\Framework\DataObject類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。