本文整理汇总了PHP中Magento\Framework\Object::addData方法的典型用法代码示例。如果您正苦于以下问题:PHP Object::addData方法的具体用法?PHP Object::addData怎么用?PHP Object::addData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Object
的用法示例。
在下文中一共展示了Object::addData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddData
/**
* Tests \Magento\Framework\Object->addData()
*/
public function testAddData()
{
$this->_object->addData(['test' => 'value']);
$this->assertEquals('value', $this->_object->getData('test'));
$this->_object->addData(['test' => 'value1']);
$this->assertEquals('value1', $this->_object->getData('test'));
$this->_object->addData(['test2' => 'value2']);
$this->assertEquals(['test' => 'value1', 'test2' => 'value2'], $this->_object->getData());
}
示例2: postRequest
/**
* 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;
}
示例3: execute
/**
* @return \Magento\Framework\Controller\Result\Json
*/
public function execute()
{
$response = new Object();
$id = $this->getRequest()->getParam('id');
if (intval($id) > 0) {
$product = $this->productRepository->getById($id);
$response->setId($id);
$response->addData($product->getData());
$response->setError(0);
} else {
$response->setError(1);
$response->setMessage(__('We can\'t retrieve the product ID.'));
}
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$resultJson->setData($response->toArray());
return $resultJson;
}