本文整理汇总了PHP中Magento\Framework\Object::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP Object::setData方法的具体用法?PHP Object::setData怎么用?PHP Object::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Object
的用法示例。
在下文中一共展示了Object::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: afterSave
/**
* 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;
}
示例3: afterSave
/**
* 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;
}
示例4: _beforeSave
/**
* 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;
}
示例5: testValidate
/**
* @param string
* @dataProvider validateProvider
*/
public function testValidate($data)
{
$object = new Object();
$object->setData($this->attributeName, $data);
$this->assertTrue($this->model->validate($object));
$this->assertTrue($this->model->validate($object));
}
示例6: beforeSave
/**
* 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;
}
示例7: _restoreOldAttrValue
/**
* Restore old attribute value
*
* @param \Magento\Framework\Object $object
* @param mixed $oldAttrValue
* @return void
*/
protected function _restoreOldAttrValue($object, $oldAttrValue)
{
$attrCode = $this->getAttribute();
if (is_null($oldAttrValue)) {
$object->unsetData($attrCode);
} else {
$object->setData($attrCode, $oldAttrValue);
}
}
示例8: 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\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;
}
示例9: testDebug
/**
* Tests \Magento\Framework\Object->debug()
*/
public function testDebug()
{
$data = ['key1' => 'value1', 'key2' => ['test'], 'key3' => $this->_object];
$this->_object->setData($data);
$debug = $data;
unset($debug['key3']);
$debug['key3 (Magento\\Framework\\Object)'] = '*** RECURSION ***';
$this->assertEquals($debug, $this->_object->debug());
}
示例10: renderElement
/**
* 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');
}
示例11: beforeSave
/**
* 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;
}
示例12: beforeSave
/**
* Before save
*
* @param \Magento\Framework\Object $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;
}
示例13: beforeSave
/**
* 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);
}
示例14: _unserialize
/**
* 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;
}
示例15: beforeSave
/**
* Before save
*
* @param \Magento\Framework\Object $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;
}