Exemplo n.º 1
0
 /**
  * Post request into gateway
  *
  * @param Object $request
  * @param ConfigInterface $config
  *
  * @return Object
  * @throws \Exception
  */
 public function postRequest(Object $request, ConfigInterface $config)
 {
     $result = new Object();
     $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 (\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;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function render(\Magento\Framework\Object $row)
 {
     if (!$row->getData($this->getColumn()->getIndex())) {
         return null;
     }
     return '<a title="' . __('Edit Store') . '"
         href="' . $this->getUrl('adminhtml/*/editGroup', ['group_id' => $row->getGroupId()]) . '">' . $this->escapeHtml($row->getData($this->getColumn()->getIndex())) . '</a>';
 }
 /**
  * {inheritdoc}
  */
 public function handle(InfoInterface $payment, Object $response)
 {
     $importObject = [];
     foreach ($this->fieldsToHandle as $field) {
         if ($response->getData($field)) {
             $importObject[$field] = $response->getData($field);
         }
     }
     $this->paypalInfoManager->importToPayment($importObject, $payment);
 }
Exemplo n.º 4
0
 /**
  * {inheritdoc}
  */
 public function handle(InfoInterface $payment, Object $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);
 }
Exemplo n.º 5
0
 /**
  * Try to unserialize the attribute value
  *
  * @param \Magento\Framework\Object $object
  * @return $this
  */
 protected function _unserialize(\Magento\Framework\Object $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;
 }
Exemplo n.º 6
0
 /**
  * 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');
 }
Exemplo n.º 7
0
 /**
  * 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;
 }
Exemplo n.º 8
0
 /**
  * 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;
 }
Exemplo n.º 9
0
 /**
  * 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();
 }
Exemplo n.º 10
0
 /**
  * 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);
         }
     }
 }
Exemplo n.º 11
0
 /**
  * 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;
 }
Exemplo n.º 12
0
 /**
  * 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;
 }
Exemplo n.º 13
0
 /**
  * Renders grid column
  *
  * @param   \Magento\Framework\Object $row
  * @return  string
  */
 public function render(\Magento\Framework\Object $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;
 }
Exemplo n.º 14
0
 /**
  * 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;
 }
Exemplo n.º 15
0
 /**
  * Renders grid column
  *
  * @param   \Magento\Framework\Object $row
  * @return  string
  */
 public function render(\Magento\Framework\Object $row)
 {
     if ($data = $row->getData($this->getColumn()->getIndex())) {
         $format = $this->_getFormat();
         return \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data)), $format);
     }
     return $this->getColumn()->getDefault();
 }
Exemplo n.º 16
0
 /**
  * Set attribute default value if value empty
  *
  * @param \Magento\Framework\Object $object
  * @return $this
  */
 public function beforeSave($object)
 {
     $attributeCode = $this->getAttribute()->getName();
     if ($object->getData('use_config_' . $attributeCode)) {
         $object->setData($attributeCode, '');
     }
     return $this;
 }
Exemplo n.º 17
0
 /**
  * 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;
     }
 }
Exemplo n.º 18
0
 /**
  * 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;
 }
Exemplo n.º 19
0
 /**
  * Prepare variable wysiwyg config
  *
  * @param \Magento\Framework\Object $config
  * @return array
  */
 public function getWysiwygPluginSettings($config)
 {
     $variableConfig = [];
     $onclickParts = ['search' => ['html_id'], 'subject' => 'MagentovariablePlugin.loadChooser(\'' . $this->getVariablesWysiwygActionUrl() . '\', \'{{html_id}}\');'];
     $variableWysiwyg = [['name' => 'magentovariable', 'src' => $this->getWysiwygJsPluginSrc(), 'options' => ['title' => __('Insert Variable...'), 'url' => $this->getVariablesWysiwygActionUrl(), 'onclick' => $onclickParts, 'class' => 'add-variable plugin']]];
     $configPlugins = $config->getData('plugins');
     $variableConfig['plugins'] = array_merge($configPlugins, $variableWysiwyg);
     return $variableConfig;
 }
Exemplo n.º 20
0
 /**
  * Formatting date value before save
  *
  * Should set (bool, string) correct type for empty value from html form,
  * necessary for further process, else date string
  *
  * @param \Magento\Framework\Object $object
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return $this
  */
 public function beforeSave($object)
 {
     $attributeName = $this->getAttribute()->getName();
     $_formated = $object->getData($attributeName . '_is_formated');
     if (!$_formated && $object->hasData($attributeName)) {
         try {
             $value = $this->formatDate($object->getData($attributeName));
         } catch (\Exception $e) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Invalid date'));
         }
         if (is_null($value)) {
             $value = $object->getData($attributeName);
         }
         $object->setData($attributeName, $value);
         $object->setData($attributeName . '_is_formated', true);
     }
     return $this;
 }
Exemplo n.º 21
0
 /**
  * Return Widgets Insertion Plugin Window URL
  *
  * @param \Magento\Framework\Object $config Editor element config
  * @return string
  */
 public function getWidgetWindowUrl($config)
 {
     $params = array();
     $skipped = is_array($config->getData('skip_widgets')) ? $config->getData('skip_widgets') : array();
     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);
 }
Exemplo n.º 22
0
 /**
  * Validate EAV model attributes with data models
  *
  * @param \Magento\Framework\Object|array $entityData Data set from the Model attributes
  * @return bool
  */
 public function isValid($entityData)
 {
     if ($entityData instanceof \Magento\Framework\Object) {
         $this->_entityData = $entityData->getData();
     } else {
         $this->_entityData = $entityData;
     }
     return $this->validateData($this->_data, $this->_attributes, $this->_entityType);
 }
Exemplo n.º 23
0
 /**
  * Find an element in layout, render it and return string with its output
  *
  * @param string $name
  * @param bool $useCache
  * @return string
  */
 public function renderElement($name, $useCache = true)
 {
     $this->build();
     if (!isset($this->_renderElementCache[$name]) || !$useCache) {
         $this->_renderElementCache[$name] = $this->renderNonCachedElement($name);
     }
     $this->_renderingOutput->setData('output', $this->_renderElementCache[$name]);
     $this->_eventManager->dispatch('core_layout_render_element', ['element_name' => $name, 'layout' => $this, 'transport' => $this->_renderingOutput]);
     return $this->_renderingOutput->getData('output');
 }
Exemplo n.º 24
0
 /**
  * Returns rate for the row, 1 by default
  *
  * @param \Magento\Framework\Object $row
  * @return float|int
  */
 protected function _getRate($row)
 {
     if ($rate = $this->getColumn()->getRate()) {
         return floatval($rate);
     }
     if ($rate = $row->getData($this->getColumn()->getRateField())) {
         return floatval($rate);
     }
     return 1;
 }
Exemplo n.º 25
0
 /**
  * Prepare data for save
  *
  * @param \Magento\Framework\Object $object
  * @return \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
  */
 public function beforeSave($object)
 {
     $attributeCode = $this->getAttribute()->getAttributeCode();
     $data = $object->getData($attributeCode);
     if (is_array($data)) {
         $data = array_filter($data);
         $object->setData($attributeCode, implode(',', $data));
     }
     return parent::beforeSave($object);
 }
Exemplo n.º 26
0
 /**
  * Before save
  *
  * @param \Magento\Framework\Object $object
  * @return $this
  */
 public function beforeSave($object)
 {
     $attributeName = $this->getAttribute()->getName();
     $urlKey = $object->getData($attributeName);
     if ($urlKey == '') {
         $urlKey = $object->getName();
     }
     $object->setData($attributeName, $object->formatUrlKey($urlKey));
     return $this;
 }
Exemplo n.º 27
0
 /**
  * Renders a column
  *
  * @param   \Magento\Framework\Object $row
  * @return  string
  */
 public function render(\Magento\Framework\Object $row)
 {
     $value = $row->getData($this->getColumn()->getIndex());
     if ($this->stringHelper->strlen($value) > 30) {
         $value = '<span title="' . $this->escapeHtml($value) . '">' . $this->escapeHtml($this->filterManager->truncate($value, array('length' => 30))) . '</span>';
     } else {
         $value = $this->escapeHtml($value);
     }
     return $value;
 }
Exemplo n.º 28
0
 /**
  * Validate data
  *
  * @param Object $response
  * @return bool
  */
 public function validate(Object $response)
 {
     $config = $this->getConfig();
     foreach ($this->avsCheck as $fieldName => $settingName) {
         if ($config->getValue($settingName) == static::CONFIG_ON && strtolower((string) $response->getData($fieldName)) === static::RESPONSE_NO) {
             $response->setRespmsg($this->errorsMessages[$settingName]);
             return false;
         }
     }
     return true;
 }
Exemplo n.º 29
0
 /**
  * Tests \Magento\Framework\Object->__call()
  *
  * @expectedException \Magento\Framework\Exception
  */
 public function testCall()
 {
     $this->_object->setData(['key' => 'value']);
     $this->_object->setTest('test');
     $this->assertEquals('test', $this->_object->getData('test'));
     $this->assertEquals($this->_object->getData('test'), $this->_object->getTest());
     $this->assertTrue($this->_object->hasTest());
     $this->_object->unsTest();
     $this->assertNull($this->_object->getData('test'));
     $this->_object->testTest();
 }
Exemplo n.º 30
0
 /**
  * Add price rule filter
  *
  * @param \Magento\Reports\Model\Resource\Report\Collection\AbstractCollection $collection
  * @param \Magento\Framework\Object $filterData
  * @return \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid
  */
 protected function _addCustomFilter($collection, $filterData)
 {
     if ($filterData->getPriceRuleType()) {
         $rulesList = $filterData->getData('rules_list');
         if (isset($rulesList[0])) {
             $rulesIds = explode(',', $rulesList[0]);
             $collection->addRuleFilter($rulesIds);
         }
     }
     return parent::_addCustomFilter($filterData, $collection);
 }