/** * 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; }
/** * @dataProvider validateDataProvider * @param bool $value */ public function testValidate($value) { $attributeCode = 'attr_code'; $attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute', ['getAttributeCode', 'getIsRequired', 'isValueEmpty', 'getIsUnique', 'getEntityType', '__wakeup'], [], '', false); $attributeEntity = $this->getMock('\\Magento\\Framework\\Model\\ResourceModel\\AbstractResourceAbstractEntity', ['checkAttributeUniqueValue']); $attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attributeCode)); $attribute->expects($this->any())->method('getIsRequired')->will($this->returnValue(true)); $attribute->expects($this->any())->method('isValueEmpty')->will($this->returnValue($value)); $attribute->expects($this->any())->method('getIsUnique')->will($this->returnValue(true)); $attribute->expects($this->any())->method('getEntityType')->will($this->returnValue($attributeEntity)); $attributeEntity->expects($this->any())->method('checkAttributeUniqueValue')->will($this->returnValue(true)); $this->attributeRepository->expects($this->once())->method('get')->with('media_gallery')->willReturn($attribute); $this->dataObject->setData(['attr_code' => 'attribute data']); $this->assertEquals(!$value, $this->model->validate($this->dataObject)); }
/** * Test method * with resultCode = RESPONSE_CODE_APPROVED and Origresult != RESPONSE_CODE_FRAUDSERVICE_FILTER */ public function testAuthorize() { $this->initializationAuthorizeMock(); $this->buildRequestData(); $paymentTokenMock = $this->getMock(PaymentTokenInterface::class); $extensionAttributes = $this->getMockBuilder('Magento\\Sales\\Api\\Data\\OrderPaymentExtensionInterface')->disableOriginalConstructor()->setMethods(['setVaultPaymentToken'])->getMock(); $ccDetails = ['cc_type' => 'VI', 'cc_number' => '1111']; $this->responseMock->setData('result_code', Payflowpro::RESPONSE_CODE_APPROVED); $this->responseMock->setData('origresult', 0); $this->responseMock->setData('pnref', 'test-pnref'); $this->gatewayMock->expects($this->once())->method('postRequest')->willReturn($this->responseMock); $this->responseValidator->expects($this->once())->method('validate')->with($this->responseMock); $this->paymentMock->expects($this->once())->method('setTransactionId')->with('test-pnref')->willReturnSelf(); $this->paymentMock->expects($this->once())->method('setIsTransactionClosed')->with(0); $this->paymentMock->expects($this->once())->method('getCcExpYear')->willReturn('2017'); $this->paymentMock->expects($this->once())->method('getCcExpMonth')->willReturn('12'); $this->paymentMock->expects(static::any())->method('getAdditionalInformation')->willReturnMap([[Transparent::CC_DETAILS, $ccDetails], [Transparent::PNREF, 'test-pnref']]); $this->paymentTokenFactory->expects(static::once())->method('create')->willReturn($paymentTokenMock); $paymentTokenMock->expects(static::once())->method('setGatewayToken')->with('test-pnref'); $paymentTokenMock->expects(static::once())->method('setTokenDetails')->with(json_encode($ccDetails)); $paymentTokenMock->expects(static::once())->method('setExpiresAt')->with('2018-01-01 00:00:00'); $this->paymentMock->expects(static::once())->method('getExtensionAttributes')->willReturn($extensionAttributes); $extensionAttributes->expects(static::once())->method('setVaultPaymentToken')->with($paymentTokenMock); $this->assertSame($this->object, $this->object->authorize($this->paymentMock, 33)); }
/** * 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; }
/** * Assign extra parameters to row * */ protected 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 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)); }
/** * 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); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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 message to response object * * @param DataObject $response * @param string[] $messages * @return DataObject */ private function setMessageToResponse($response, $messages) { $messageKey = $this->getRequest()->getParam('message_key', static::DEFAULT_MESSAGE_KEY); if ($messageKey === static::DEFAULT_MESSAGE_KEY) { $messages = reset($messages); } return $response->setData($messageKey, $messages); }
/** * @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->_getConditionsRenderer()->calcOptionHash($row->getData('conditions'))] = 'selected="selected"'; $options['option_' . $this->_getValueRenderer()->calcOptionHash($row->getData('cvalue'))] = 'selected="selected"'; $row->setData('option_extra_attrs', $options); }
/** * 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\DataObject $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; }
/** * Dispatch request * * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface * @throws \Magento\Framework\Exception\NotFoundException */ public function execute() { $response = new DataObject(); $response->setData('error', false); /** @var Json $resultJson */ $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); $resultJson->setData($response); return $resultJson; }
/** * @param object $methodInstance * @param bool $isAllowed * @param bool $isAvailable * @dataProvider restrictAdminBillingAgreementUsageDataProvider */ public function testExecute($methodInstance, $isAllowed, $isAvailable) { $this->_event->setMethodInstance($methodInstance); $this->_authorization->expects($this->any())->method('isAllowed')->with('Magento_Paypal::use')->will($this->returnValue($isAllowed)); $result = new DataObject(); $result->setData('is_available', true); $this->_event->setResult($result); $this->_model->execute($this->_observer); $this->assertEquals($isAvailable, $result->getData('is_available')); }
/** * Prepare data for save * * @param \Magento\Framework\DataObject $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); }
/** * Before save * * @param \Magento\Framework\DataObject $object * @return $this */ public function beforeSave($object) { if ($object->getId()) { return $this; } if (!$object->hasData('website_id')) { $object->setData('website_id', $this->_storeManager->getStore()->getWebsiteId()); } return $this; }
protected function _prepareArrayRow(\Magento\Framework\DataObject $row) { $attrName = $row->getAttrName(); $options = []; if ($attrName) { $options['option_' . $this->_getSourceRenderer()->calcOptionHash($attrName)] = 'selected="selected"'; } $row->setData('option_extra_attrs', $options); return; }
/** * @param string $key * @return mixed */ public function __get($key) { if (isset($this->aliasMap[$key])) { return $this->__get($this->aliasMap[$key]); } if (!$this->cache->hasData($key)) { $value = $this->wrap($this->loadData($key)); $this->cache->setData($key, $value); } return $this->cache->getData($key); }
/** * Tests \Magento\Framework\DataObject->debug() */ public function testDebug() { $data = ['key1' => 'value1', 'key2' => ['test'], 'key3' => $this->_object]; foreach ($data as $key => $value) { $this->_object->setData($key, $value); } $debug = $data; unset($debug['key3']); $debug['key3 (Magento\\Framework\\DataObject)'] = '*** RECURSION ***'; $this->assertEquals($debug, $this->_object->debug()); }
protected function _prepareArrayRow(DataObject $row) { $data = $this->getTableData(); $options = []; foreach (array_keys($data) as $columnId) { $columnData = $data[$columnId]; if (isset($columnData['values'])) { $options['option_' . $this->getRenderer($columnId, $columnData)->calcOptionHash($row->getData($columnId))] = 'selected="selected"'; } } $row->setData('option_extra_attrs', $options); }
/** * 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; }
/** * 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'); }
/** * Prepare existing row data object * * @param DataObject $row * @return void */ protected function _prepareArrayRow(DataObject $row) { $country = $row->getCountryId(); $options = []; if ($country) { $options['option_' . $this->getCountryRenderer()->calcOptionHash($country)] = 'selected="selected"'; $ccTypes = $row->getCcTypes(); foreach ($ccTypes as $cardType) { $options['option_' . $this->getCcTypesRenderer()->calcOptionHash($cardType)] = 'selected="selected"'; } } $row->setData('option_extra_attrs', $options); }
/** * Before save * * @param \Magento\Framework\DataObject $object * @return $this */ public function beforeSave($object) { if ($object->getId()) { return $this; } if (!$object->hasStoreId()) { $object->setStoreId($this->_storeManager->getStore()->getId()); } if (!$object->hasData('created_in')) { $object->setData('created_in', $this->_storeManager->getStore($object->getStoreId())->getName()); } return $this; }
/** * @param string $key * @return mixed */ public function __get($key) { // echo "{$this->_uid}.__get(" . $key . ')';//var_export($this->aliasMap); if (isset($this->aliasMap[$key])) { return $this->__get($this->aliasMap[$key]); } if (!$this->cache->hasData($key)) { // echo '!hasData(' . $key . ')'; $value = $this->wrap($this->loadData($key)); $this->cache->setData($key, $value); } // echo 'getData(' . $key . ')'; return $this->cache->getData($key); }
/** * Load an object by customer_id & coupon_id * * @param \Magento\Framework\DataObject $object * @param int $customerId * @param mixed $couponId * @return $this */ public function loadByCustomerCoupon(\Magento\Framework\DataObject $object, $customerId, $couponId) { $connection = $this->getConnection(); if ($connection && $couponId && $customerId) { $select = $connection->select()->from($this->getMainTable())->where('customer_id =:customet_id')->where('coupon_id = :coupon_id'); $data = $connection->fetchRow($select, [':coupon_id' => $couponId, ':customet_id' => $customerId]); if ($data) { $object->setData($data); } } if ($object instanceof \Magento\Framework\Model\AbstractModel) { $this->_afterLoad($object); } return $this; }
/** * Prepare existing row data object * * @param \Magento\Framework\DataObject $row * @return void */ protected function _prepareArrayRow(\Magento\Framework\DataObject $row) { $country = $row->getCountryId(); $options = []; if ($country) { $options['option_' . $this->getCountryRenderer()->calcOptionHash($country)] = 'selected="selected"'; $ccTypes = $row->getCcTypes(); if (!is_array($ccTypes)) { $ccTypes = [$ccTypes]; } foreach ($ccTypes as $cardType) { $options['option_' . $this->getCcTypesRenderer()->calcOptionHash($cardType)] = 'selected="selected"'; } } $row->setData('option_extra_attrs', $options); return; }
/** * Post handling / currency converting * * @return void * @throws \Exception */ public function execute() { //first of all validate request $post = $this->getRequest()->getPostValue(); if (!$this->getRequest()->isXmlHttpRequest() || !$post) { echo "Asd"; exit; $this->_redirect('*/*/'); return; } $this->getResponse()->setHeader('Content-type', 'application/json'); $response = array('success' => false); try { $postObject = new DataObject(); $postObject->setData($post); $error = false; if (!\Zend_Validate::is(trim($post['base_value']), 'NotEmpty')) { $error = true; } if (!\Zend_Validate::is(trim($post['base']), 'NotEmpty')) { $error = true; } if (!\Zend_Validate::is(trim($post['exchange']), 'NotEmpty')) { $error = true; } if ($error) { throw new \Exception(); } $converterService = $this->_objectManager->create('\\TBat\\Converter\\Model\\Converter\\Service\\Client', array('url' => $this->scopeConfig->getValue(self::XML_PATH_WEBSERVICE_URL))); $result = $converterService->calculate($post['base'], $post['exchange'], $post['base_value']); $response['success'] = true; $response['result'] = $result; $this->messageManager->addSuccess(__('Thanks for using our converter.')); } catch (\Exception $e) { $response['message'] = $e->getMessage(); $this->messageManager->addError(__('We can\'t process your request right now. Sorry, that\'s all we know.')); } $this->getResponse()->setBody($this->jsonEncoder->encode($response)); }