本文整理汇总了PHP中Varien_Object::toJson方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Object::toJson方法的具体用法?PHP Varien_Object::toJson怎么用?PHP Varien_Object::toJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Object
的用法示例。
在下文中一共展示了Varien_Object::toJson方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _beforeSave
protected function _beforeSave()
{
if ($this->_mediumData) {
$this->setData('medium_json', $this->_mediumData->toJson());
}
parent::_beforeSave();
}
示例2: _beforeSave
protected function _beforeSave()
{
if ($this->_mediumData) {
$this->setData('medium_json', $this->_mediumData->toJson());
}
if ($this->_campaign) {
$this->setCampaignId($this->_campaign->getId());
}
parent::_beforeSave();
}
示例3: popupajaxAction
public function popupajaxAction()
{
$response = new Varien_Object();
$response->setError(0);
try {
$pageName = $this->getRequest()->getParam('page');
if (!$pageName) {
throw new Exception($this->__('PageType not found'));
}
$pageName = Mage::helper('core')->escapeHtml($pageName);
$popup = Mage::helper('promotional')->getPopup($pageName);
if (isset($popup['promotional_id'])) {
Mage::helper('promotional')->setViewedPopup($popup['promotional_id']);
$response->addData($popup->toArray());
$autoHideTime = Mage::helper('promotional')->getAutoHide();
if ($autoHideTime > 0) {
$response->setAutoHideTime($autoHideTime);
}
} else {
throw new Exception('Promotional Popup not found');
}
} catch (Exception $e) {
$response->setError(1);
$response->setErrorMessage($e->getMessage());
}
$this->getResponse()->setBody($response->toJson());
return;
}
示例4: indexAction
/**
* @todo Rename variables to carry more understandability
*/
public function indexAction()
{
$__VH = Mage::helper('activitystream/dataValidation');
$__activityModel = Mage::getModel('activitystream/activity');
$__VH->mustbeavalidVarienObject($__activityModel);
$__activityCollection = $__activityModel->getCollection();
$__VH->mustbeavalidObject($__activityCollection);
$__moment = $this->getRequest()->getParam('moment');
$__storeFilter = $this->getRequest()->getParam('storefilter');
$__items = $__activityCollection->newestFirst()->startingFrom($__moment)->joinDetails();
switch ($__storeFilter) {
case AW_Activitystream_Helper_Data::STREAM_STOREFILTER_STOREVIEW:
$__activityCollection->filterByStoreView(Mage::app()->getStore()->getStoreId());
break;
case AW_Activitystream_Helper_Data::STREAM_STOREFILTER_STORE:
$__activityCollection->filterByStoreGroup(Mage::app()->getStore()->getGroupId());
break;
case AW_Activitystream_Helper_Data::STREAM_STOREFILTER_WEBSITE:
$__activityCollection->filterByWebsite(Mage::app()->getStore()->getWebsiteId());
break;
}
$__activityCollection->filterByTypes(Mage::helper('activitystream/adminhtml')->getEnabledActivityTypes())->setPageSize(50)->setCurPage(0);
$__activityCollection->load();
$__items = array_reverse($__activityCollection->getItems());
$__activities = array();
foreach ($__items as $__item) {
$__activity = array('DATA' => $__item->getData(), 'RECORD_HTML' => $this->__renderActivity($__item));
array_push($__activities, $__activity);
}
$__responseObject = new Varien_Object();
$__responseObject->setActivities(array_reverse($__activities));
$this->getResponse()->setHeader('Content-Type', 'application/json')->setBody($__responseObject->toJson());
}
示例5: saveAction
/**
* Save shipment
* We can save only new shipment. Existing shipments are not editable
*
* @return null
*/
public function saveAction()
{
$data = $this->getRequest()->getPost('shipment');
if (!empty($data['comment_text'])) {
Mage::getSingleton('adminhtml/session')->setCommentText($data['comment_text']);
}
try {
$shipment = $this->_initShipment();
if (!$shipment) {
$this->_forward('noRoute');
return;
}
$shipment->register();
$comment = '';
if (!empty($data['comment_text'])) {
$shipment->addComment($data['comment_text'], isset($data['comment_customer_notify']), isset($data['is_visible_on_front']));
if (isset($data['comment_customer_notify'])) {
$comment = $data['comment_text'];
}
}
if (!empty($data['send_email'])) {
$shipment->setEmailSent(true);
}
$shipment->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
$responseAjax = new Varien_Object();
$isNeedCreateLabel = isset($data['create_shipping_label']) && $data['create_shipping_label'];
if ($isNeedCreateLabel && $this->_createShippingLabel($shipment)) {
$responseAjax->setOk(true);
}
$this->_saveShipment($shipment);
Mage::dispatchEvent('sales_order_shipment_save_custom', array('post' => $data, 'shipment' => $shipment));
$shipment->sendEmail(!empty($data['send_email']), $comment);
$shipmentCreatedMessage = $this->__('The shipment has been created.');
$labelCreatedMessage = $this->__('The shipping label has been created.');
$this->_getSession()->addSuccess($isNeedCreateLabel ? $shipmentCreatedMessage . ' ' . $labelCreatedMessage : $shipmentCreatedMessage);
Mage::getSingleton('adminhtml/session')->getCommentText(true);
} catch (Mage_Core_Exception $e) {
if ($isNeedCreateLabel) {
$responseAjax->setError(true);
$responseAjax->setMessage($e->getMessage());
} else {
$this->_getSession()->addError($e->getMessage());
$this->_redirect('*/*/new', array('order_id' => $this->getRequest()->getParam('order_id')));
}
} catch (Exception $e) {
Mage::logException($e);
if ($isNeedCreateLabel) {
$responseAjax->setError(true);
$responseAjax->setMessage(Mage::helper('sales')->__('An error occurred while creating shipping label.'));
} else {
$this->_getSession()->addError($this->__('Cannot save shipment.'));
$this->_redirect('*/*/new', array('order_id' => $this->getRequest()->getParam('order_id')));
}
}
if ($isNeedCreateLabel) {
$this->getResponse()->setBody($responseAjax->toJson());
} else {
$this->_redirect('*/sales_order/view', array('order_id' => $shipment->getOrderId()));
}
}
示例6: testToJson
/**
* Tests Varien_Object->toJson()
*/
public function testToJson()
{
$this->_object->setData(array('key1' => 'value1', 'key2' => 'value2'));
$this->assertEquals('{"key1":"value1","key2":"value2"}', $this->_object->toJson());
$this->assertEquals('{"key1":"value1"}', $this->_object->toJson(array('key1')));
$this->assertEquals('{"key1":"value1","key":null}', $this->_object->__toJson(array('key1', 'key')));
}
示例7: getJson
public function getJson()
{
$response = new Varien_Object();
$helper = Mage::helper('yanws/articleUtils');
$response->setUrl(Mage::getBaseUrl());
$response->setConvertTable(Mage::helper('yanws')->_getTransliterator()->getConvertTable());
$response->setBaseRoute($helper::BASE_ROUTE);
return $response->toJson();
}
示例8: getJsonConversionPagesUrl
public function getJsonConversionPagesUrl()
{
$storeViewsUrls = array();
foreach ($this->getStoreViews() as $_store) {
Mage::helper('googleoptimizer')->setStoreId($_store->getId());
$storeViewsUrls[$_store->getCode()] = Mage::helper('googleoptimizer')->getConversionPagesUrl()->getData();
}
$storeViewsUrls = new Varien_Object($storeViewsUrls);
return $storeViewsUrls->toJson();
}
示例9: _saveFile
protected function _saveFile($type, $extensions = array())
{
global $_FILES;
/* @var $core Morphes_Core_Helper_Data */
$core = Mage::helper(strtolower('Morphes_Core'));
/* @var $files Morphes_Core_Helper_Files */
$files = Mage::helper(strtolower('Morphes_Core/Files'));
try {
$isXhr = $this->getRequest()->getParam('qqfile') != null;
if (!$isXhr && !isset($_FILES['qqfile'])) {
throw new Exception($this->__('No files were uploaded.'));
}
$filename = $isXhr ? $this->getRequest()->getParam('qqfile') : $_FILES['qqfile']['name'];
$size = $isXhr ? (int) $_SERVER["CONTENT_LENGTH"] : $_FILES['qqfile']['size'];
$fileinfo = pathinfo($filename);
if (count($extensions) && !in_array(strtolower($fileinfo['extension']), $extensions)) {
throw new Exception($this->__('Invalid file extension %s.', $fileinfo['extension']));
}
if ($size == 0) {
throw new Exception($this->__('File is empty.'));
}
if ($size > min($core->getIniByteValue('post_max_size'), $core->getIniByteValue('upload_max_filesize'))) {
throw new Exception($this->__('File is too large. Current maximum size is %d bytes.'));
}
$relativeUrl = $files->getNewUrl($filename, $type);
$targetFileName = $files->getFilename($relativeUrl, $type, true);
if ($isXhr) {
// save upload as a temp file
$input = fopen("php://input", "r");
$temp = tmpfile();
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
if ($realSize != $size) {
throw new Exception($this->__("File size %d was expected, but %d was actually sent", $size, $realSize));
}
// move temp file to target location
$target = fopen($targetFileName, "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
} else {
if (!move_uploaded_file($_FILES['qqfile']['tmp_name'], $targetFileName)) {
throw new Exception("The upload was cancelled, or server error encountered.");
}
}
$url = $files->getUrl($relativeUrl, $type);
$id = $this->getRequest()->getParam('id');
$response = new Varien_Object(compact('relativeUrl', 'url', 'id'));
$this->getResponse()->setBody($response->toJson());
} catch (Exception $e) {
$response = new Varien_Object(array('error' => $e->getMessage()));
$this->getResponse()->setBody($response->toJson());
}
}
示例10: toJson
public function toJson(array $arrAttributes = array())
{
$this->setSuccess(true);
if ($this->isError()) {
$this->setSuccess(false);
$this->setMsg($this->_error);
} else {
$this->setMsg($this->_msg);
}
return parent::toJson($arrAttributes);
}
示例11: updateAction
public function updateAction()
{
$data = $this->getRequest()->getPost();
$response = array('action' => $data['action'], 'errorMessage' => '');
try {
switch ($data['action']) {
case 'update':
$updateInfo = array();
foreach ($data['items'] as $itemId => $qty) {
$updateInfo[$itemId] = array('qty' => max((int) $qty, 1));
}
$this->_getCart()->updateItems($updateInfo)->save();
$this->_getSession()->setCartWasUpdated(true);
/*
$quoteItem = $cart->getQuote()->getItemById($id);
if (!$quoteItem) {
Mage::throwException($this->__('Quote item is not found.'));
}
if ($qty == 0) {
$cart->removeItem($id);
} else {
$quoteItem->setQty($qty)->save();
}
$this->_getCart()->save();/**/
break;
case 'delete':
$this->_getCart()->removeItem($data['itemId'])->save();
break;
case 'clear':
$oemAttrSetId = Mage::getStoreConfig('arioem/add_to_cart/oem_product_attr_set_id');
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
foreach ($items as $item) {
if ($oemAttrSetId == $item->getProduct()->getAttributeSetId()) {
$this->_getCart()->removeItem($item->getId());
}
}
$this->_getCart()->save();
break;
case 'refresh':
default:
// do nothing here
}
Mage::register('isAJAX', true);
$response['html'] = $this->getLayout()->createBlock('arioem/shoppinglist')->toHtml();
} catch (Exception $e) {
$response['errorMessage'] = Vikont_ARIOEM_Helper_Data::reportError($e->getMessage());
}
$responseAjax = new Varien_Object($response);
$this->getResponse()->setBody($responseAjax->toJson());
}
示例12: validateAction
public function validateAction()
{
$response = new Varien_Object();
$response->setError(false);
$attributeCode = $this->getRequest()->getParam('attribute_code');
$attributeId = $this->getRequest()->getParam('attribute_id');
$attribute = Mage::getModel('catalog/entity_attribute')->loadByCode($this->_entityTypeId, $attributeCode);
if ($attribute->getId() && !$attributeId) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('catalog')->__('Attribute with the same code already exists'));
$this->_initLayoutMessages('adminhtml/session');
$response->setError(true);
$response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
}
$this->getResponse()->setBody($response->toJson());
}
示例13: saveFormAction
/**
* Save grid edit form action
*
*/
public function saveFormAction()
{
$codeId = $this->getRequest()->getParam('code_id');
$response = new Varien_Object();
try {
$model = Mage::getModel('find_feed/codes');
if ($codeId) {
$model->load($codeId);
}
$model->setImportCode($this->getRequest()->getParam('import_code'));
$model->setEavCode($this->getRequest()->getParam('eav_code'));
$model->setIsImported(intval($this->getRequest()->getParam('is_imported')));
$model->save();
$response->setError(0);
} catch (Exception $e) {
$response->setError(1);
$response->setMessage('Save error');
}
$this->getResponse()->setBody($response->toJson());
}
示例14: validateAction
/**
* Attributes validation action
*
*/
public function validateAction()
{
$response = new Varien_Object();
$response->setError(false);
$attributesData = $this->getRequest()->getParam('attributes', array());
$data = new Varien_Object();
try {
if ($attributesData) {
$dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$storeId = $this->_getHelper()->getSelectedStoreId();
foreach ($attributesData as $attributeCode => $value) {
$attribute = Mage::getSingleton('Mage_Eav_Model_Config')->getAttribute('catalog_product', $attributeCode);
if (!$attribute->getAttributeId()) {
unset($attributesData[$attributeCode]);
continue;
}
$data->setData($attributeCode, $value);
$attribute->getBackend()->validate($data);
}
}
} catch (Mage_Eav_Model_Entity_Attribute_Exception $e) {
$response->setError(true);
$response->setAttribute($e->getAttributeCode());
$response->setMessage($e->getMessage());
} catch (Mage_Core_Exception $e) {
$response->setError(true);
$response->setMessage($e->getMessage());
} catch (Exception $e) {
$this->_getSession()->addException($e, $this->__('An error occurred while updating the product(s) attributes.'));
$this->_initLayoutMessages('Mage_Adminhtml_Model_Session');
$response->setError(true);
$response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
}
$this->getResponse()->setBody($response->toJson());
}
示例15: validateAction
/**
* Validate Staging before it save
*
*/
public function validateAction()
{
$response = new Varien_Object();
$response->setError(false);
try {
$stagingData = $this->getRequest()->getPost('staging');
Mage::getModel('enterprise_staging/staging')->setStagingId($this->getRequest()->getParam('id'))->addData($stagingData)->validate();
} catch (Enterprise_Staging_Exception $e) {
$response->setError(true);
$response->setMessage($e->getMessage());
} catch (Exception $e) {
$this->_getSession()->addError(Mage::helper('enterprise_staging')->__('An error occurred while validating data. Please review the log and try again.'));
$this->_initLayoutMessages('adminhtml/session');
$response->setError(true);
$response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
}
$this->getResponse()->setBody($response->toJson());
}