/** * @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)); }
/** * Test for addFieldsToResponse method * * @return void */ public function testAddFieldsToResponseSuccess() { $testData = $this->getAddFieldsToResponseSuccessTestData(); $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock(); $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $orderPaymentMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Payment')->disableOriginalConstructor()->getMock(); $instanceMock = $this->getMockBuilder('Magento\\Authorizenet\\Model\\Directpost')->disableOriginalConstructor()->getMock(); $requestToAuthorizenetMock = $this->getMockBuilder('Magento\\Authorizenet\\Model\\Directpost\\Request')->disableOriginalConstructor()->setMethods(['setControllerActionName', 'setIsSecure', 'getData'])->getMock(); $requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getControllerName'])->getMockForAbstractClass(); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->coreRegistryMock->expects($this->once())->method('registry')->with('directpost_order')->willReturn($orderMock); $orderMock->expects($this->once())->method('getId')->willReturn($testData['order.getId']); $orderMock->expects($this->once())->method('getPayment')->willReturn($orderPaymentMock); $orderPaymentMock->expects($this->once())->method('getMethod')->willReturn($testData['orderPayment.getMethod']); $this->paymentMock->expects($this->exactly(2))->method('getCode')->willReturn($testData['payment.getCode']); $observerMock->expects($this->atLeastOnce())->method('getData')->willReturnMap($testData['observer.getData']); $this->resultMock->expects($this->once())->method('getData')->willReturn($testData['result.getData']); $orderMock->expects($this->atLeastOnce())->method('getIncrementId')->willReturn($testData['order.getIncrementId']); $this->sessionMock->expects($this->once())->method('addCheckoutOrderIncrementId')->with($testData['session.addCheckoutOrderIncrementId']); $this->sessionMock->expects($this->once())->method('setLastOrderIncrementId')->with($testData['session.setLastOrderIncrementId']); $orderPaymentMock->expects($this->once())->method('getMethodInstance')->willReturn($instanceMock); $instanceMock->expects($this->once())->method('generateRequestFromOrder')->with($orderMock)->willReturn($requestToAuthorizenetMock); $this->actionMock->expects($this->once())->method('getRequest')->willReturn($requestMock); $requestMock->expects($this->once())->method('getControllerName')->willReturn($testData['request.getControllerName']); $requestToAuthorizenetMock->expects($this->once())->method('setControllerActionName')->with($testData['requestToAuthorizenet.setControllerActionName']); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); $storeMock->expects($this->once())->method('isCurrentlySecure')->willReturn($testData['store.isCurrentlySecure']); $requestToAuthorizenetMock->expects($this->once())->method('setIsSecure')->with($testData['requestToAuthorizenet.setIsSecure']); $requestToAuthorizenetMock->expects($this->once())->method('getData')->willReturn($testData['requestToAuthorizenet.getData']); $this->resultMock->expects($this->once())->method('setData')->with($testData['result.setData']); $this->addFieldsToResponseObserver->execute($observerMock); }
/** * 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); }
/** * 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; }
/** * 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'); }
/** * 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); }
/** * 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; }
/** * 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; }
/** * 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); } } }
/** * 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; }
/** * 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); }
/** * 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); }
/** * 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(); }
/** * @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); }
/** * @param bool $isValid * @dataProvider addBillingAgreementToSessionDataProvider */ public function testAddBillingAgreementToSession($isValid) { $agreement = $this->getMock('Magento\\Paypal\\Model\\Billing\\Agreement', [], [], '', false); $agreement->expects($this->once())->method('isValid')->will($this->returnValue($isValid)); $comment = $this->getMockForAbstractClass('Magento\\Framework\\Model\\AbstractModel', [], '', false, true, true, ['__wakeup']); $order = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false); $order->expects($this->once())->method('addStatusHistoryComment')->with($isValid ? __('Created billing agreement #%1.', 'agreement reference id') : __('We can\'t create a billing agreement for this order.'))->will($this->returnValue($comment)); if ($isValid) { $agreement->expects($this->any())->method('__call')->with('getReferenceId')->will($this->returnValue('agreement reference id')); $agreement->expects($this->once())->method('addOrderRelation')->with($order); $order->expects(new MethodInvokedAtIndex(0))->method('addRelatedObject')->with($agreement); $this->_checkoutSession->expects($this->once())->method('__call')->with('setLastBillingAgreementReferenceId', ['agreement reference id']); } else { $this->_checkoutSession->expects($this->once())->method('__call')->with('unsLastBillingAgreementReferenceId'); $agreement->expects($this->never())->method('__call'); } $order->expects(new MethodInvokedAtIndex($isValid ? 1 : 0))->method('addRelatedObject')->with($comment); $payment = $this->getMock('Magento\\Sales\\Model\\Order\\Payment', [], [], '', false); $payment->expects($this->once())->method('__call')->with('getBillingAgreementData')->will($this->returnValue('not empty')); $payment->expects($this->once())->method('getOrder')->will($this->returnValue($order)); $agreement->expects($this->once())->method('importOrderPayment')->with($payment)->will($this->returnValue($agreement)); $this->_event->setPayment($payment); $this->_agreementFactory->expects($this->once())->method('create')->will($this->returnValue($agreement)); $this->_model->execute($this->_observer); }
/** * 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); }
/** * 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); } }
public function render(DataObject $row) { $storeViewId = $this->getRequest()->getParam('store'); $banner = $this->_bannerFactory->create()->setStoreViewId($storeViewId)->load($row->getId()); $srcImage = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $banner->getImage(); return '<image width="150" height="50" src ="' . $srcImage . '" alt="' . $banner->getImage() . '" >'; }
/** * Format total value based on order currency * * @param \Magento\Framework\DataObject $total * @return string */ public function formatValue($total) { if (!$total->getIsFormated()) { return $this->_adminHelper->displayPrices($this->getOrder(), $total->getBaseValue(), $total->getValue()); } return $total->getValue(); }
/** * Get item qty * * @param \Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar $subject * @param callable $proceed * @param \Magento\Framework\DataObject $item * * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundGetItemQty(\Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar $subject, \Closure $proceed, \Magento\Framework\DataObject $item) { if ($item->getProduct()->getTypeId() == \Magento\Bundle\Model\Product\Type::TYPE_CODE) { return ''; } return $proceed($item); }
/** * @param array $paymentMethodsAvailability * @param array $blocks * @dataProvider addAvailabilityOfMethodsDataProvider */ public function testAddPaypalShortcuts($paymentMethodsAvailability, $blocks) { $this->paypalConfigMock->expects($this->any())->method('isMethodAvailable')->will($this->returnValueMap($paymentMethodsAvailability)); $layoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Layout')->setMethods(['createBlock'])->disableOriginalConstructor()->getMock(); $shortcutButtonsMock = $this->getMockBuilder('Magento\\Catalog\\Block\\ShortcutButtons')->setMethods(['getLayout', 'addShortcut'])->disableOriginalConstructor()->getMock(); $blockInstances = []; $atPosition = 0; foreach ($blocks as $blockName => $blockInstance) { if ($this->paypalConfigMock->isMethodAvailable($blockInstance[1])) { $block = $this->getMockBuilder($blockInstance[0])->setMethods(null)->disableOriginalConstructor()->getMock(); $blockInstances[$blockName] = $block; $layoutMock->expects(new MethodInvokedAtIndex($atPosition))->method('createBlock')->with($blockName)->will($this->returnValue($block)); $atPosition++; } } $shortcutButtonsMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock)); $atPosition = 0; foreach ($blocks as $blockName => $blockInstance) { if ($this->paypalConfigMock->isMethodAvailable($blockInstance[1])) { $shortcutButtonsMock->expects(new MethodInvokedAtIndex($atPosition))->method('addShortcut')->with($this->identicalTo($blockInstances[$blockName])); $atPosition++; } } $this->_event->setContainer($shortcutButtonsMock); $this->_model->execute($this->_observer); }
/** * Prepare data before save * * @param \Magento\Framework\DataObject $object * @return $this */ protected function _beforeSave($object) { if (!$object->getData($this->getAttribute()->getAttributeCode())) { $object->setData($this->getAttribute()->getAttributeCode(), $this->_storeManager->getStore()->getId()); } return $this; }
/** * Method is invoked before save * * @param \Magento\Framework\DataObject $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); }
/** * Renders grid column * * @param \Magento\Framework\DataObject $row * @return string */ public function render(\Magento\Framework\DataObject $row) { $thumbDirtmp = str_replace($this->_imageprocessor->getSliderMediaPath(), $this->_imageprocessor->getSliderMediaPath('thumb'), $row->getSliderImagePath()); return '<span class="grid-row-title"> <img src="' . $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $thumbDirtmp . '" > </span>'; }
/** * Assign extra parameters to row * */ protected function _prepareArrayRow(\Magento\Framework\DataObject $row) { $optionExtraAttr = []; $optionExtraAttr['option_' . $this->_getStatusRenderer()->calcOptionHash($row->getData('status'))] = 'selected="selected"'; $optionExtraAttr['option_' . $this->_getAutomationRenderer()->calcOptionHash($row->getData('automation'))] = 'selected="selected"'; $row->setData('option_extra_attrs', $optionExtraAttr); }
/** * Don't add item to the collection if only fixed are allowed and its carrier is not fixed * * @param \Magento\Quote\Model\Quote\Address\Rate $rate * @return $this */ public function addItem(\Magento\Framework\DataObject $rate) { $carrier = $this->_carrierFactory->get($rate->getCarrier()); if ($this->_allowFixedOnly && (!$carrier || !$carrier->isFixed())) { return $this; } return parent::addItem($rate); }
/** * Render the description of given row. * * @param \Magento\Framework\DataObject $row * @return string */ public function render(\Magento\Framework\DataObject $row) { $customerId = (int) $row->getData($this->getColumn()->getIndex()); if ($customerId > 0) { return '<a href="' . $this->getUrl('customer/index/edit', array('id' => $customerId)) . '" target="_blank">' . $customerId . '</a>'; } return nl2br(htmlspecialchars($row->getData($this->getColumn()->getIndex()))); }
public function render(\Magento\Framework\DataObject $row) { $ticket = $this->ticketFactory->create()->load($row->getId()); if ($ticket && $ticket->getId()) { return $ticket->getSeverityAsLabel(); } return ''; }
/** * @param \Magento\Framework\DataObject $row */ protected function _prepareArrayRow(\Magento\Framework\DataObject $row) { $options = []; $options['option_' . $this->_getAttributeRenderer()->calcOptionHash($row->getData('attribute'))] = 'selected="selected"'; $options['option_' . $this->_getConditionsRenderer()->calcOptionHash($row->getData('conditions'))] = 'selected="selected"'; $options['option_' . $this->_getValueRenderer()->calcOptionHash($row->getData('cvalue'))] = 'selected="selected"'; $row->setData('option_extra_attrs', $options); }
/** * Perform operation before save * * @param \Magento\Framework\DataObject $object * @return $this */ public function beforeSave($object) { if ($object->getOrder()) { $object->setParentId($object->getOrder()->getId()); } parent::beforeSave($object); return $this; }