本文整理汇总了PHP中Magento\Framework\DataObject::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObject::setData方法的具体用法?PHP DataObject::setData怎么用?PHP DataObject::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\DataObject
的用法示例。
在下文中一共展示了DataObject::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postRequest
/**
* 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;
}
示例2: testValidate
/**
* @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));
}
示例3: testAuthorize
/**
* 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));
}
示例4: afterSave
/**
* 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;
}
示例5: _prepareArrayRow
/**
* 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);
}
示例6: testValidate
/**
* @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));
}
示例7: _prepareArrayRow
/**
* 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);
}
示例8: _beforeSave
/**
* 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;
}
示例9: afterSave
/**
* 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;
}
示例10: beforeSave
/**
* 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;
}
示例11: beforeSave
/**
* 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;
}
示例12: setMessageToResponse
/**
* 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);
}
示例13: _prepareArrayRow
/**
* @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);
}
示例14: beforeSave
/**
* 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;
}
示例15: execute
/**
* 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;
}