/** * Renders grid column * * @param \Magento\Framework\DataObject $row * @return mixed */ public function _getValue(\Magento\Framework\DataObject $row) { $result = ''; if ($row->getData('error_file') != '') { $result = '<p> ' . $row->getData('error_file') . '</p><a href="' . $this->getUrl('*/*/download', ['filename' => $row->getData('error_file')]) . '">' . __('Download') . '</a>'; } return $result; }
/** * Post request into gateway * * @param DataObject $request * @param ConfigInterface $config * * @return DataObject * @throws \Zend_Http_Client_Exception */ public function postRequest(DataObject $request, ConfigInterface $config) { $result = new DataObject(); $clientConfig = ['maxredirects' => 5, 'timeout' => 30, 'verifypeer' => $config->getValue('verify_peer')]; if ($config->getValue('use_proxy')) { $clientConfig['proxy'] = $config->getValue('proxy_host') . ':' . $config->getValue('proxy_port'); $clientConfig['httpproxytunnel'] = true; $clientConfig['proxytype'] = CURLPROXY_HTTP; } /** @var ZendClient $client */ $client = $this->httpClientFactory->create(); $client->setUri((bool) $config->getValue('sandbox_flag') ? $config->getValue('transaction_url_test_mode') : $config->getValue('transaction_url')); $client->setConfig($clientConfig); $client->setMethod(\Zend_Http_Client::POST); $client->setParameterPost($request->getData()); $client->setHeaders(['X-VPS-VIT-CLIENT-CERTIFICATION-ID' => '33baf5893fc2123d8b191d2d011b7fdc', 'X-VPS-Request-ID' => $this->mathRandom->getUniqueHash(), 'X-VPS-CLIENT-TIMEOUT' => 45]); $client->setUrlEncodeBody(false); try { $response = $client->request(); $responseArray = []; parse_str(strstr($response->getBody(), 'RESULT'), $responseArray); $result->setData(array_change_key_case($responseArray, CASE_LOWER)); $result->setData('result_code', $result->getData('result')); } catch (\Zend_Http_Client_Exception $e) { $result->addData(['response_code' => -1, 'response_reason_code' => $e->getCode(), 'response_reason_text' => $e->getMessage()]); throw $e; } finally { $this->logger->debug(['request' => $request->getData(), 'result' => $result->getData()], (array) $config->getValue('getDebugReplacePrivateDataKeys'), (bool) $config->getValue('debug')); } return $result; }
/** * 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); }
/** * @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); }
/** * {@inheritdoc} */ public function render(\Magento\Framework\DataObject $row) { if (!$row->getData($this->getColumn()->getIndex())) { return null; } return '<a title="' . __('Edit Store View') . '" href="' . $this->getUrl('adminhtml/*/editStore', ['store_id' => $row->getStoreId()]) . '">' . $this->escapeHtml($row->getData($this->getColumn()->getIndex())) . '</a>'; }
/** * 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()))); }
/** * @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); }
public function assignData(DataObject $data) { $additional_data = new DataObject($data->getAdditionalData()); $info_instance = $this->getInfoInstance(); $info_instance->setAdditionalInformation('ticket', $additional_data->getData('ticket_response_ticket')); $info_instance->setAdditionalInformation('hmac', $additional_data->getData('ticket_response_monetra_resp_hmacsha256')); $info_instance->setAdditionalInformation('sequence', $additional_data->getData('ticket_request_sequence')); $info_instance->setAdditionalInformation('timestamp', $additional_data->getData('ticket_request_timestamp')); return $this; }
/** * {inheritdoc} */ public function handle(InfoInterface $payment, DataObject $response) { $importObject = []; foreach ($this->fieldsToHandle as $field) { if ($response->getData($field)) { $importObject[$field] = $response->getData($field); } } $this->paypalInfoManager->importToPayment($importObject, $payment); }
/** * Column renderer * * @param DataObject $row * @return string */ public function render(DataObject $row) { $value = $row->getData($this->getColumn()->getIndex()); try { $payload = json_encode(unserialize($row->getData('payload'))); } catch (\Exception $e) { $payload = "?"; } return '<span title="' . htmlentities($payload) . '">' . $value . '</span>'; }
/** * {inheritdoc} */ public function handle(InfoInterface $payment, DataObject $response) { if (!in_array($response->getData('result'), [Payflowpro::RESPONSE_CODE_DECLINED_BY_FILTER, Payflowpro::RESPONSE_CODE_FRAUDSERVICE_FILTER])) { return; } $fraudMessages = ['RESPMSG' => $response->getData(self::RESPONSE_MESSAGE)]; if ($response->getData(self::FRAUD_RULES_XML)) { $fraudMessages = array_merge($fraudMessages, $this->getFraudRulesDictionary($response->getData(self::FRAUD_RULES_XML))); } $this->paypalInfoManager->importToPayment([Info::FRAUD_FILTERS => array_merge($fraudMessages, (array) $payment->getAdditionalInformation(Info::FRAUD_FILTERS))], $payment); }
/** * Try to unserialize the attribute value * * @param \Magento\Framework\DataObject $object * @return $this */ protected function _unserialize(\Magento\Framework\DataObject $object) { $attrCode = $this->getAttribute()->getAttributeCode(); if ($object->getData($attrCode)) { try { $unserialized = unserialize($object->getData($attrCode)); $object->setData($attrCode, $unserialized); } catch (\Exception $e) { $object->unsetData($attrCode); } } return $this; }
/** * @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject * @param \Closure $proceed * @param \Magento\Framework\DataObject $entity * @return bool */ public function aroundValidate(\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject, \Closure $proceed, \Magento\Framework\DataObject $entity) { $isAllowedType = !empty(array_filter(array_map(function ($allowedEntity) use($entity) { return $entity instanceof $allowedEntity; }, $this->allowedEntityTypes))); if ($isAllowedType && $this->storeManager->getStore()->getId() !== Store::DEFAULT_STORE_ID) { $attrCode = $subject->getAttribute()->getAttributeCode(); // Null is meaning "no value" which should be overridden by value from default scope if (array_key_exists($attrCode, $entity->getData()) && $entity->getData($attrCode) === null) { return true; } } return $proceed($entity); }
/** * Display price attribute value in base order currency and in place order currency * * @param \Magento\Framework\DataObject $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 ); }
/** * 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; }
/** * 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(); }
/** * 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'); }
/** * 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); } } }
/** * 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; }
/** * 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; }
/** * 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); }
/** * Renders grid column * * @param \Magento\Framework\DataObject $row * @return string */ public function render(\Magento\Framework\DataObject $row) { if ($data = $row->getData($this->getColumn()->getIndex())) { $timezone = $this->getColumn()->getTimezone() !== false ? $this->_localeDate->getConfigTimezone() : 'UTC'; return $this->dateTimeFormatter->formatObject($this->_localeDate->date(new \DateTime($data, new \DateTimeZone($timezone))), $this->_getFormat()); } return $this->getColumn()->getDefault(); }
/** * Return image url * * @param \Magento\Framework\DataObject $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; }
/** * Revert to last design config, used before emulation * * @return void */ public function revertDesign() { if ($this->emulatedDesignConfig) { $this->setDesignConfig($this->emulatedDesignConfig->getData()); $this->cancelDesignConfig(); $this->emulatedDesignConfig = false; } }
/** * Renders grid column * * @param \Magento\Framework\DataObject $row * @return string */ public function render(\Magento\Framework\DataObject $row) { $html = '<input type="text" '; $html .= 'name="' . $this->getColumn()->getId() . '" '; $html .= 'value="' . $row->getData($this->getColumn()->getIndex()) . '"'; $html .= 'class="input-text ' . $this->getColumn()->getInlineCss() . '"/>'; return $html; }
/** * Additional get data with clear mode * * @param string $key * @param bool $clear * @return mixed */ public function getData($key = '', $clear = false) { $data = parent::getData($key); if ($clear && isset($this->_data[$key])) { unset($this->_data[$key]); } return $data; }
/** * Set attribute default value if value empty * * @param \Magento\Framework\DataObject $object * @return $this */ public function beforeSave($object) { $attributeCode = $this->getAttribute()->getName(); if ($object->getData('use_config_' . $attributeCode)) { $object->setData($attributeCode, ''); } return $this; }
/** * Set attribute default value if value empty * * @param \Magento\Framework\DataObject $object * @return $this */ public function beforeSave($object) { $attributeCode = $this->getAttribute()->getName(); if ($object->getData('use_config_' . $attributeCode)) { $object->setData($attributeCode, BooleanSource::VALUE_USE_CONFIG); } return $this; }
/** * @return string */ public function getActiveTitle() { if ($this->activeItem) { return $this->activeItem->getData('title'); } else { return $this->context->getPageConfig()->getTitle()->getShort(); } }
/** * Return Widgets Insertion Plugin Window URL * * @param \Magento\Framework\DataObject $config Editor element config * @return string */ public function getWidgetWindowUrl($config) { $params = []; $skipped = is_array($config->getData('skip_widgets')) ? $config->getData('skip_widgets') : []; 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); }