/** * Renders grid column * * @param \Magento\Framework\Object $row * @return string */ public function render(\Magento\Framework\Object $row) { //@todo: check this logic manually if ($data = $row->getData($this->getColumn()->getIndex())) { switch ($this->getColumn()->getPeriodType()) { case 'month': $dateFormat = 'yyyy-MM'; break; case 'year': $dateFormat = 'yyyy'; break; default: $dateFormat = \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT; break; } $format = $this->_getFormat(); try { $data = $this->getColumn()->getGmtoffset() ? \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data)), $format) : \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data), null, false), $format); } catch (\Exception $e) { $data = $this->getColumn()->getTimezone() ? \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data)), $format) : \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data), null, false), $format); } return $data; } return $this->getColumn()->getDefault(); }
/** * After save * * @param \Magento\Framework\Object $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\Core\Model\File\Uploader */ $uploader = $this->_fileUploaderFactory->create(array('fileId' => $this->getAttribute()->getName())); $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(true); } catch (\Exception $e) { return $this; } $path = $this->_filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::MEDIA_DIR)->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; }
/** * Render minimal price for downloadable products * * @param \Magento\Framework\Object $row * @return string */ public function render(\Magento\Framework\Object $row) { if ($row->getTypeId() == 'downloadable') { $row->setPrice($row->getPrice()); } return parent::render($row); }
/** * Render a grid cell as options * * @param \Magento\Framework\Object $row * @return string|void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function render(\Magento\Framework\Object $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); } } }
/** * Render grid column * * @param \Magento\Framework\Object $row * @return string */ public function render(\Magento\Framework\Object $row) { $actions = []; $actions[] = ['url' => $this->getUrl('adminhtml/*/preview', ['id' => $row->getId()]), 'popup' => true, 'caption' => __('Preview')]; $this->getColumn()->setActions($actions); return parent::render($row); }
/** * Set order state and status * * @param string $paymentAction * @param \Magento\Framework\Object $stateObject * @return void */ public function initialize($paymentAction, $stateObject) { $state = $this->getConfigData('order_status'); $stateObject->setState($state); $stateObject->setStatus($state); $stateObject->setIsNotified(false); }
/** * Method is invoked after save * * @param \Magento\Framework\Object $object * @return \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend */ public function afterSave($object) { if ($object->getOrderItem()) { $object->getOrderItem()->save(); } return parent::beforeSave($object); }
/** * Renders Purchases value * * @param \Magento\Framework\Object $row * @return string */ public function render(\Magento\Framework\Object $row) { if (($value = $row->getData($this->getColumn()->getIndex())) > 0) { return $value; } return __('Unlimited'); }
/** * Get payflow transaction id from parent transaction * * @param \Magento\Framework\Object $payment * @return string */ protected function _getParentTransactionId(\Magento\Framework\Object $payment) { if ($payment->getParentTransactionId()) { return $payment->getTransaction($payment->getParentTransactionId())->getAdditionalInformation(self::TRANSPORT_PAYFLOW_TXN_ID); } return $payment->getParentTransactionId(); }
/** * We need reset attribute set id to attribute after related simple product was saved * * @param \Magento\Catalog\Model\Resource\Product $subject * @param \Magento\Framework\Object $object * @return void * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeSave(\Magento\Catalog\Model\Resource\Product $subject, \Magento\Framework\Object $object) { /** @var \Magento\Catalog\Model\Product $object */ if ($object->getTypeId() == Configurable::TYPE_CODE) { $object->getTypeInstance()->getSetAttributes($object); } }
/** * @param \Magento\Framework\Object $observer * @return \Magento\Quote\Model\Quote\Item */ public function processTaxData($observer) { /** @var \Magento\Quote\Model\Quote\Item $item */ $item = $observer->getEvent()->getItem(); $item->setRowTotal($this->getRowTotal($item))->setRowTotalInclTax($this->getRowTotalInclTax($item))->setPrice($this->getUnitDisplayPriceExclTax($item))->setPriceInclTax($this->getUnitDisplayPriceInclTax($item)); return $item; }
/** * Validate * * @param \Magento\Framework\Object $object Quote * @return bool */ public function validate(\Magento\Framework\Object $object) { $all = $this->getAggregator() === 'all'; $true = (bool) $this->getValue(); $found = false; foreach ($object->getAllItems() as $item) { $found = $all; foreach ($this->getConditions() as $cond) { $validated = $cond->validate($item); if ($all && !$validated || !$all && $validated) { $found = $validated; break; } } if ($found && $true || !$true && $found) { break; } } // found an item and we're looking for existing one if ($found && $true) { return true; } elseif (!$found && !$true) { // not found and we're making sure it doesn't exist return true; } return false; }
/** * Save uploaded file and set its name to category * * @param \Magento\Framework\Object $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; }
public function testGetInstructionsSetInstructions() { $this->assertNull($this->_instructions->getInstructions()); $testInstruction = 'first test'; $this->_method->setInstructions($testInstruction); $this->assertEquals($testInstruction, $this->_instructions->getInstructions()); }
/** * Get "double" prices html (block with base and place currency) * * @param \Magento\Framework\Object $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; }
/** * Create url for passed item using passed url model * @param \Magento\Framework\Object $item * @return string */ public function getUrl($item) { if ($this->_authorization->isAllowed('Magento_Customer::manage') && $item->getCustomerId()) { return parent::getUrl($item); } return false; }
/** * Return recurring payment child Orders Ids * * * @param \Magento\Framework\Object $object * @return array */ public function getChildOrderIds($object) { $adapter = $this->_getReadAdapter(); $bind = array(':payment_id' => $object->getId()); $select = $adapter->select()->from(array('main_table' => $this->getTable('recurring_payment_order')), array('order_id'))->where('payment_id=:payment_id'); return $adapter->fetchCol($select, $bind); }
/** * Set new increment id * * @param \Magento\Framework\Object $object * @return $this */ public function beforeSave($object) { if (!$object->getId()) { $this->getAttribute()->getEntity()->setNewIncrementId($object); } return $this; }
/** * Format total value based on order currency * * @param \Magento\Framework\Object $total * @return string */ public function formatValue($total) { if (!$total->getIsFormated()) { return $this->_adminHelper->displayPrices($this->getOrder(), $total->getBaseValue(), $total->getValue()); } return $total->getValue(); }
/** * Retrieve attribute value * * @param \Magento\Framework\Object $object * @return mixed */ public function getValue(\Magento\Framework\Object $object) { $value = $object->getData($this->getAttribute()->getAttributeCode()); if (in_array($this->getConfigField('input'), ['select', 'boolean'])) { $valueOption = $this->getOption($value); if (!$valueOption) { $opt = $this->_attrBooleanFactory->create(); $options = $opt->getAllOptions(); if ($options) { foreach ($options as $option) { if ($option['value'] == $value) { $valueOption = $option['label']; } } } } $value = $valueOption; } elseif ($this->getConfigField('input') == 'multiselect') { $value = $this->getOption($value); if (is_array($value)) { $value = implode(', ', $value); } } return $value; }
/** * Get item qty * * @param \Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar $subject * @param callable $proceed * @param \Magento\Framework\Object $item * * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundGetItemQty(\Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar $subject, \Closure $proceed, \Magento\Framework\Object $item) { if ($item->getProduct()->getTypeId() == \Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE) { return ''; } return $proceed($item); }
/** * Performed before data is saved * * @param \Magento\Framework\Object $object * @return $this */ public function beforeSave($object) { if ($object->getShipment()) { $object->setParentId($object->getShipment()->getId()); } return parent::beforeSave($object); }
/** * Prepare data before save * * @param \Magento\Framework\Object $object * @return $this */ protected function _beforeSave($object) { if (!$object->getData($this->getAttribute()->getAttributeCode())) { $object->setData($this->getAttribute()->getAttributeCode(), $this->_storeManager->getStore()->getId()); } return $this; }
/** * Refresh product rewrites * * @param \Magento\Framework\Object $object * @return $this */ public function afterSave($object) { if ($object->dataHasChangedFor($this->getAttribute()->getName())) { $this->_catalogUrl->refreshProductRewrites(null, $object, true); } return $this; }
/** * @param string * @dataProvider validateProvider */ public function testValidate($data) { $object = new Object(); $object->setData($this->attributeName, $data); $this->assertTrue($this->model->validate($object)); $this->assertTrue($this->model->validate($object)); }
/** * Method is invoked before save * * @param \Magento\Framework\Object $object * @return \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend */ public function beforeSave($object) { if ($object->getCreditmemo()) { $object->setParentId($object->getCreditmemo()->getId()); } return parent::beforeSave($object); }
/** * @param \Magento\Framework\Object $subject * @param bool $result * @return bool */ public function afterCanDisplayCustomValue(\Magento\Framework\Object $subject, $result) { $carrierCode = $subject->getShipment()->getCarrierCode(); if (!$carrierCode) { return (bool) $result || false; } return (bool) $result || (bool) $carrierCode == \Magento\Fedex\Model\Carrier::CODE; }
/** * Perform operation before save * * @param \Magento\Framework\Object $object * @return $this */ public function beforeSave($object) { if ($object->getOrder()) { $object->setParentId($object->getOrder()->getId()); } parent::beforeSave($object); return $this; }
/** * Return image url * * @param \Magento\Framework\Object $object * @return string|null */ public function getUrl($object) { $url = false; if ($image = $object->getData($this->getAttribute()->getAttributeCode())) { $url = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . self::IMAGE_PATH_SEGMENT . $image; } return $url; }
/** * @param \Magento\Catalog\Model\Product\Attribute\Backend\Price $subject * @param \Closure $proceed * @param \Magento\Catalog\Model\Product|\Magento\Framework\Object $object * @return bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundValidate(\Magento\Catalog\Model\Product\Attribute\Backend\Price $subject, \Closure $proceed, $object) { if ($object instanceof \Magento\Catalog\Model\Product && $object->getTypeId() == \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE && $object->getPriceType() == \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) { return true; } else { return $proceed($object); } }