本文整理汇总了PHP中Zend_Filter_Input::getUnescaped方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Filter_Input::getUnescaped方法的具体用法?PHP Zend_Filter_Input::getUnescaped怎么用?PHP Zend_Filter_Input::getUnescaped使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Filter_Input
的用法示例。
在下文中一共展示了Zend_Filter_Input::getUnescaped方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loaddataorderspaymentAction
public function loaddataorderspaymentAction()
{
$this->_helper->viewRenderer->setNoRender();
$this->_helper->getHelper("layout")->disableLayout();
$aInputFilters = array("*" => array(new Zend_Filter_StringTrim()));
$aInputValidators = array("num_row_per_page" => array(new Zend_Validate_Digits()), "curr_page" => array(new Zend_Validate_Digits()), "sort_column" => array(new AppCms2_Validate_SpecialAlpha()), "sort_method" => array(new Zend_Validate_Alpha()));
$oInput = new Zend_Filter_Input($aInputFilters, $aInputValidators, $_POST);
$nNumRowPerPage = $oInput->getUnescaped("num_row_per_page");
$nCurrPage = $oInput->getUnescaped("curr_page");
$sSortColumn = $oInput->getUnescaped("sort_column");
$sSortMethod = $oInput->getUnescaped("sort_method");
$aFilter = array();
foreach ($aFilter as $sKey => $sValue) {
if (!isset($sValue)) {
unset($aFilter[$sKey]);
}
}
$oModelVOrderPaymentHistory = new User_Model_VOrderPaymentHistory();
$oRowset = $oModelVOrderPaymentHistory->getUserPayments($aFilter, $nNumRowPerPage, ($nCurrPage - 1) * $nNumRowPerPage, $sSortColumn . " " . $sSortMethod);
$nNumRows = $oModelVOrderPaymentHistory->getUserPayments($aFilter)->count();
$aJson = array("rowset" => $oRowset->toArray(), "num_rows" => $nNumRows);
header("Content-type: application/json");
echo Zend_Json::encode($aJson);
exit;
}
示例2: _savePanel
/**
* Save changes to an existing panel. This can be expanded to allow adding of new Panels in the future.
*
* @return void
*/
protected function _savePanel()
{
// First of all we need to validate and sanitise the input from the form
$urlFilter = new Zend_Filter();
$urlFilter->addFilter(new Zend_Filter_StringTrim());
$urlFilter->addFilter(new Zend_Filter_StringTrim('/'));
$requiredText = new Zend_Validate();
$requiredText->addValidator(new Zend_Validate_NotEmpty());
$filters = array('id' => 'Digits');
$validators = array('id' => array('allowEmpty' => true), 'content' => array('allowEmpty' => true));
$input = new Zend_Filter_Input($filters, $validators, $_POST);
if ($input->isValid()) {
// Data is all valid, formatted and sanitized so we can save it in the database
$panel = new Datasource_Cms_Panels();
if (!$input->id) {
// This is a new panel so we need to create a new ID
// NOT IMPLEMENTED - YET
} else {
$panel->saveChanges($input->id, $input->getUnescaped('content'));
$panelID = $input->id;
}
// Changes saved - so send them back with a nice success message
$this->_helper->getHelper('FlashMessenger')->addMessage(array('saved' => true));
$this->_helper->getHelper('Redirector')->goToUrl('/cms-admin/panels/edit?id=' . $panelID);
} else {
// Invalid data in form
/*
print_r($_POST);
print_r($input->getErrors());
print_r($input->getInvalid());
*/
}
}
示例3: executeInternal
/**
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function executeInternal()
{
if ($this->getRequest()->getPostValue()) {
try {
/** @var \Magento\CatalogRule\Model\Rule $model */
$model = $this->_objectManager->create('Magento\\CatalogRule\\Model\\Rule');
$this->_eventManager->dispatch('adminhtml_controller_catalogrule_prepare_save', ['request' => $this->getRequest()]);
$data = $this->getRequest()->getPostValue();
$inputFilter = new \Zend_Filter_Input(['from_date' => $this->_dateFilter, 'to_date' => $this->_dateFilter], [], $data);
$data = $inputFilter->getUnescaped();
$id = $this->getRequest()->getParam('rule_id');
if ($id) {
$model->load($id);
if ($id != $model->getId()) {
throw new LocalizedException(__('Wrong rule specified.'));
}
}
$validateResult = $model->validateData(new \Magento\Framework\DataObject($data));
if ($validateResult !== true) {
foreach ($validateResult as $errorMessage) {
$this->messageManager->addError($errorMessage);
}
$this->_getSession()->setPageData($data);
$this->_redirect('catalog_rule/*/edit', ['id' => $model->getId()]);
return;
}
$data['conditions'] = $data['rule']['conditions'];
unset($data['rule']);
$model->loadPost($data);
$this->_objectManager->get('Magento\\Backend\\Model\\Session')->setPageData($model->getData());
$model->save();
$this->messageManager->addSuccess(__('You saved the rule.'));
$this->_objectManager->get('Magento\\Backend\\Model\\Session')->setPageData(false);
if ($this->getRequest()->getParam('auto_apply')) {
$this->getRequest()->setParam('rule_id', $model->getId());
$this->_forward('applyRules');
} else {
if ($model->isRuleBehaviorChanged()) {
$this->_objectManager->create('Magento\\CatalogRule\\Model\\Flag')->loadSelf()->setState(1)->save();
}
if ($this->getRequest()->getParam('back')) {
$this->_redirect('catalog_rule/*/edit', ['id' => $model->getId()]);
return;
}
$this->_redirect('catalog_rule/*/');
}
return;
} catch (LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('Something went wrong while saving the rule data. Please review the error log.'));
$this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
$this->_objectManager->get('Magento\\Backend\\Model\\Session')->setPageData($data);
$this->_redirect('catalog_rule/*/edit', ['id' => $this->getRequest()->getParam('rule_id')]);
return;
}
}
$this->_redirect('catalog_rule/*/');
}
示例4: _beforeSave
/**
* Before model save
* @param \Magefan\Blog\Model\Post $model
* @param \Magento\Framework\App\Request\Http $request
* @return void
*/
protected function _beforeSave($model, $request)
{
/* Prepare dates */
$dateFilter = $this->_objectManager->create('Magento\\Framework\\Stdlib\\DateTime\\Filter\\Date');
$data = $model->getData();
$filterRules = [];
foreach (['publish_time', 'custom_theme_from', 'custom_theme_to'] as $dateField) {
if (!empty($data[$dateField])) {
$filterRules[$dateField] = $dateFilter;
}
}
$inputFilter = new \Zend_Filter_Input($filterRules, [], $data);
$data = $inputFilter->getUnescaped();
$model->setData($data);
/* Prepare author */
if (!$model->getAuthorId()) {
$authSession = $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session');
$model->setAuthorId($authSession->getUser()->getId());
}
/* Prepare relative links */
$data = $request->getPost('data');
$links = isset($data['links']) ? $data['links'] : null;
if ($links && is_array($links)) {
foreach (['post', 'product'] as $linkType) {
if (!empty($links[$linkType]) && is_array($links[$linkType])) {
$linksData = [];
foreach ($links[$linkType] as $item) {
$linksData[$item['id']] = ['position' => $item['position']];
}
$links[$linkType] = $linksData;
}
}
$model->setData('links', $links);
}
/* Prepare images */
$data = $model->getData();
foreach (['featured_img', 'og_img'] as $key) {
if (isset($data[$key]) && is_array($data[$key])) {
if (!empty($data[$key]['delete'])) {
$model->setData($key, null);
} else {
if (isset($data[$key][0]['name']) && isset($data[$key][0]['tmp_name'])) {
$image = $data[$key][0]['name'];
$model->setData($key, Post::BASE_MEDIA_PATH . DIRECTORY_SEPARATOR . $image);
$imageUploader = $this->_objectManager->get('Magefan\\Blog\\ImageUpload');
$imageUploader->moveFileFromTmp($image);
} else {
if (isset($data[$key][0]['name'])) {
$model->setData($key, $data[$key][0]['name']);
}
}
}
} else {
$model->setData($key, null);
}
}
}
示例5: execute
/**
* @return void
*/
public function execute()
{
if ($this->getRequest()->getPost()) {
try {
$model = $this->_objectManager->create('Magento\\CatalogRule\\Model\\Rule');
$this->_eventManager->dispatch('adminhtml_controller_catalogrule_prepare_save', array('request' => $this->getRequest()));
$data = $this->getRequest()->getPost();
$inputFilter = new \Zend_Filter_Input(array('from_date' => $this->_dateFilter, 'to_date' => $this->_dateFilter), array(), $data);
$data = $inputFilter->getUnescaped();
$id = $this->getRequest()->getParam('rule_id');
if ($id) {
$model->load($id);
if ($id != $model->getId()) {
throw new Exception(__('Wrong rule specified.'));
}
}
$validateResult = $model->validateData(new \Magento\Framework\Object($data));
if ($validateResult !== true) {
foreach ($validateResult as $errorMessage) {
$this->messageManager->addError($errorMessage);
}
$this->_getSession()->setPageData($data);
$this->_redirect('catalog_rule/*/edit', array('id' => $model->getId()));
return;
}
$data['conditions'] = $data['rule']['conditions'];
unset($data['rule']);
$model->loadPost($data);
$this->_objectManager->get('Magento\\Backend\\Model\\Session')->setPageData($model->getData());
$model->save();
$this->messageManager->addSuccess(__('The rule has been saved.'));
$this->_objectManager->get('Magento\\Backend\\Model\\Session')->setPageData(false);
if ($this->getRequest()->getParam('auto_apply')) {
$this->getRequest()->setParam('rule_id', $model->getId());
$this->_forward('applyRules');
} else {
$this->_objectManager->create('Magento\\CatalogRule\\Model\\Flag')->loadSelf()->setState(1)->save();
if ($this->getRequest()->getParam('back')) {
$this->_redirect('catalog_rule/*/edit', array('id' => $model->getId()));
return;
}
$this->_redirect('catalog_rule/*/');
}
return;
} catch (Exception $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError(__('An error occurred while saving the rule data. Please review the log and try again.'));
$this->_objectManager->get('Magento\\Framework\\Logger')->logException($e);
$this->_objectManager->get('Magento\\Backend\\Model\\Session')->setPageData($data);
$this->_redirect('catalog_rule/*/edit', array('id' => $this->getRequest()->getParam('rule_id')));
return;
}
}
$this->_redirect('catalog_rule/*/');
}
示例6: filterData
/**
* filter dates
*
* @param array $data
* @return array
*/
public function filterData($data)
{
$inputFilter = new \Zend_Filter_Input(['dob' => $this->dateFilter], [], $data);
$data = $inputFilter->getUnescaped();
if (isset($data['awards'])) {
if (is_array($data['awards'])) {
$data['awards'] = implode(',', $data['awards']);
}
}
return $data;
}
示例7: executeInternal
/**
* Generate Coupons action
*
* @return void
*/
public function executeInternal()
{
if (!$this->getRequest()->isAjax()) {
$this->_forward('noroute');
return;
}
$result = [];
$this->_initRule();
/** @var $rule \Magento\SalesRule\Model\Rule */
$rule = $this->_coreRegistry->registry('current_promo_quote_rule');
if (!$rule->getId()) {
$result['error'] = __('Rule is not defined');
} else {
try {
$data = $this->getRequest()->getParams();
if (!empty($data['to_date'])) {
$inputFilter = new \Zend_Filter_Input(['to_date' => $this->_dateFilter], [], $data);
$data = $inputFilter->getUnescaped();
}
/** @var $generator \Magento\SalesRule\Model\Coupon\Massgenerator */
$generator = $this->_objectManager->get('Magento\SalesRule\Model\Coupon\Massgenerator');
if (!$generator->validateData($data)) {
$result['error'] = __('Invalid data provided');
} else {
$generator->setData($data);
$generator->generatePool();
$generated = $generator->getGeneratedCount();
$this->messageManager->addSuccess(__('%1 coupon(s) have been generated.', $generated));
$this->_view->getLayout()->initMessages();
$result['messages'] = $this->_view->getLayout()->getMessagesBlock()->getGroupedHtml();
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$result['error'] = $e->getMessage();
} catch (\Exception $e) {
$result['error'] = __(
'Something went wrong while generating coupons. Please review the log and try again.'
);
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
}
}
$this->getResponse()->representJson(
$this->_objectManager->get('Magento\Framework\Json\Helper\Data')->jsonEncode($result)
);
}
示例8: execute
public function execute()
{
if ($this->getRequest()->getPostValue()) {
try {
$model = $this->_objectManager->create('Lapisbard\\StoreLocator\\Model\\Locations');
$data = $this->getRequest()->getPostValue();
$inputFilter = new \Zend_Filter_Input([], [], $data);
$data = $inputFilter->getUnescaped();
$id = $this->getRequest()->getParam('id');
if ($id) {
$model->load($id);
if ($id != $model->getId()) {
throw new \Magento\Framework\Exception\LocalizedException(__('The wrong item is specified.'));
}
}
$model->setData($data);
$session = $this->_objectManager->get('Magento\\Backend\\Model\\Session');
$session->setPageData($model->getData());
$model->save();
$this->messageManager->addSuccess(__('You saved the item.'));
$session->setPageData(false);
if ($this->getRequest()->getParam('back')) {
$this->_redirect('lapisbard_storelocator/*/edit', ['id' => $model->getId()]);
return;
}
$this->_redirect('lapisbard_storelocator/*/');
return;
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
$id = (int) $this->getRequest()->getParam('id');
if (!empty($id)) {
$this->_redirect('lapisbard_storelocator/*/edit', ['id' => $id]);
} else {
$this->_redirect('lapisbard_storelocator/*/new');
}
return;
} catch (\Exception $e) {
$this->messageManager->addError(__('Something went wrong while saving the item data. Please review the error log.'));
$this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
$this->_objectManager->get('Magento\\Backend\\Model\\Session')->setPageData($data);
$this->_redirect('lapisbard_storelocator/*/edit', ['id' => $this->getRequest()->getParam('id')]);
return;
}
}
$this->_redirect('lapisbard_storelocator/*/');
}
示例9: _initReportAction
/**
* Report action init operations
*
* @param array|\Magento\Framework\DataObject $blocks
* @return $this
*/
public function _initReportAction($blocks)
{
if (!is_array($blocks)) {
$blocks = [$blocks];
}
$requestData = $this->_objectManager->get('Magento\\Backend\\Helper\\Data')->prepareFilterString($this->getRequest()->getParam('filter'));
$inputFilter = new \Zend_Filter_Input(['from' => $this->_dateFilter, 'to' => $this->_dateFilter], [], $requestData);
$requestData = $inputFilter->getUnescaped();
$requestData['store_ids'] = $this->getRequest()->getParam('store_ids');
$params = new \Magento\Framework\DataObject();
foreach ($requestData as $key => $value) {
if (!empty($value)) {
$params->setData($key, $value);
}
}
foreach ($blocks as $block) {
if ($block) {
$block->setPeriodType($params->getData('period_type'));
$block->setFilterData($params);
}
}
return $this;
}
示例10: initializeFromData
/**
* Initialize product from data
*
* @param \Magento\Catalog\Model\Product $product
* @param array $productData
* @return \Magento\Catalog\Model\Product
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function initializeFromData(\Magento\Catalog\Model\Product $product, array $productData)
{
unset($productData['custom_attributes']);
unset($productData['extension_attributes']);
if ($productData) {
$stockData = isset($productData['stock_data']) ? $productData['stock_data'] : [];
$productData['stock_data'] = $this->stockFilter->filter($stockData);
}
$productData = $this->normalize($productData);
if (!empty($productData['is_downloadable'])) {
$productData['product_has_weight'] = 0;
}
foreach (['category_ids', 'website_ids'] as $field) {
if (!isset($productData[$field])) {
$productData[$field] = [];
}
}
foreach ($productData['website_ids'] as $websiteId => $checkboxValue) {
if (!$checkboxValue) {
unset($productData['website_ids'][$websiteId]);
}
}
$wasLockedMedia = false;
if ($product->isLockedAttribute('media')) {
$product->unlockAttribute('media');
$wasLockedMedia = true;
}
$dateFieldFilters = [];
$attributes = $product->getAttributes();
foreach ($attributes as $attrKey => $attribute) {
if ($attribute->getBackend()->getType() == 'datetime') {
if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') {
$dateFieldFilters[$attrKey] = $this->getDateTimeFilter();
}
}
}
$inputFilter = new \Zend_Filter_Input($dateFieldFilters, [], $productData);
$productData = $inputFilter->getUnescaped();
if (isset($productData['options'])) {
$productOptions = $productData['options'];
unset($productData['options']);
} else {
$productOptions = [];
}
$product->addData($productData);
if ($wasLockedMedia) {
$product->lockAttribute('media');
}
if ($this->storeManager->hasSingleStore() && empty($product->getWebsiteIds())) {
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsite()->getId()]);
}
/**
* Check "Use Default Value" checkboxes values
*/
$useDefaults = (array) $this->request->getPost('use_default', []);
foreach ($useDefaults as $attributeCode => $useDefaultState) {
if ($useDefaultState) {
$product->setData($attributeCode, null);
}
}
$product = $this->setProductLinks($product);
/**
* Initialize product options
*/
if ($productOptions && !$product->getOptionsReadonly()) {
// mark custom options that should to fall back to default value
$options = $this->mergeProductOptions($productOptions, $this->request->getPost('options_use_default'));
$customOptions = [];
foreach ($options as $customOptionData) {
if (empty($customOptionData['is_delete'])) {
if (isset($customOptionData['values'])) {
$customOptionData['values'] = array_filter($customOptionData['values'], function ($valueData) {
return empty($valueData['is_delete']);
});
}
$customOption = $this->getCustomOptionFactory()->create(['data' => $customOptionData]);
$customOption->setProductSku($product->getSku());
$customOption->setOptionId(null);
$customOptions[] = $customOption;
}
}
$product->setOptions($customOptions);
}
$product->setCanSaveCustomOptions(!empty($productData['affect_product_custom_options']) && !$product->getOptionsReadonly());
return $product;
}
示例11: deleteuserAction
public function deleteuserAction()
{
$this->_helper->viewRenderer->setNoRender();
$this->_helper->getHelper("layout")->disableLayout();
$this->getFileUploadScript();
$aInputFilters = array("*" => array(new Zend_Filter_StringTrim()));
$aInputValidators = array("id" => array(new Zend_Validate_Digits()));
$bJson = false;
$oInput = new Zend_Filter_Input($aInputFilters, $aInputValidators, $_POST);
$nId = $oInput->getUnescaped("id");
$oModelUser = new Admin_Model_User();
if ($oModelUser->deleteRow($nId)) {
$bJson = true;
}
header("Content-type: application/json");
echo Zend_Json::encode($bJson);
exit;
}
示例12: testInsertingNullDoesNotGetEscapedWithDefaultEscapeMethod
/**
* @group ZF-3004
*/
public function testInsertingNullDoesNotGetEscapedWithDefaultEscapeMethod()
{
$input = new Zend_Filter_Input(null, null, array('test' => null));
$input->process();
$this->assertFalse($input->hasMissing(), 'Expected hasMissing() to return false');
$this->assertFalse($input->hasInvalid(), 'Expected hasInvalid() to return false');
$this->assertFalse($input->hasUnknown(), 'Expected hasUnknown() to return false');
$this->assertTrue($input->hasValid(), 'Expected hasValid() to return true');
$this->assertNull($input->getUnescaped('test'), 'getUnescaped of test fails to return null');
$this->assertNull($input->getEscaped('test'), 'getEscaped of test fails to return null');
$this->assertNull($input->test, 'magic get of test fails to return null');
}
示例13: filter
/**
* Filtering posted data. Converting localized data if needed
*
* @param array $data
* @return array
*/
public function filter($data)
{
$inputFilter = new \Zend_Filter_Input(['custom_theme_from' => $this->dateFilter, 'custom_theme_to' => $this->dateFilter], [], $data);
$data = $inputFilter->getUnescaped();
return $data;
}
示例14: initialize
/**
* Initialize product before saving
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function initialize(\Magento\Catalog\Model\Product $product)
{
$productData = $this->request->getPost('product');
unset($productData['custom_attributes']);
unset($productData['extension_attributes']);
if ($productData) {
$stockData = isset($productData['stock_data']) ? $productData['stock_data'] : [];
$productData['stock_data'] = $this->stockFilter->filter($stockData);
}
foreach (['category_ids', 'website_ids'] as $field) {
if (!isset($productData[$field])) {
$productData[$field] = [];
}
}
$wasLockedMedia = false;
if ($product->isLockedAttribute('media')) {
$product->unlockAttribute('media');
$wasLockedMedia = true;
}
$dateFieldFilters = [];
$attributes = $product->getAttributes();
foreach ($attributes as $attrKey => $attribute) {
if ($attribute->getBackend()->getType() == 'datetime') {
if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') {
$dateFieldFilters[$attrKey] = $this->dateFilter;
}
}
}
$inputFilter = new \Zend_Filter_Input($dateFieldFilters, [], $productData);
$productData = $inputFilter->getUnescaped();
$product->addData($productData);
if ($wasLockedMedia) {
$product->lockAttribute('media');
}
if ($this->storeManager->hasSingleStore()) {
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsite()->getId()]);
}
/**
* Check "Use Default Value" checkboxes values
*/
$useDefaults = $this->request->getPost('use_default');
if ($useDefaults) {
foreach ($useDefaults as $attributeCode) {
$product->setData($attributeCode, false);
}
}
$links = $this->request->getPost('links');
$links = is_array($links) ? $links : [];
$linkTypes = ['related', 'upsell', 'crosssell'];
foreach ($linkTypes as $type) {
if (isset($links[$type])) {
$links[$type] = $this->jsHelper->decodeGridSerializedInput($links[$type]);
}
}
$product = $this->productLinks->initializeLinks($product, $links);
$productLinks = $product->getProductLinks();
$linkTypes = ['related' => $product->getRelatedReadonly(), 'upsell' => $product->getUpsellReadonly(), 'crosssell' => $product->getCrosssellReadonly()];
foreach ($linkTypes as $linkType => $readonly) {
if (isset($links[$linkType]) && !$readonly) {
foreach ($links[$linkType] as $linkId => $linkData) {
$linkProduct = $this->productRepository->getById($linkId);
$link = $this->productLinkFactory->create();
$link->setSku($product->getSku())->setLinkedProductSku($linkProduct->getSku())->setLinkType($linkType)->setPosition(isset($linkData['position']) ? (int) $linkData['position'] : 0);
$productLinks[] = $link;
}
}
}
$product->setProductLinks($productLinks);
/**
* Initialize product options
*/
if (isset($productData['options']) && !$product->getOptionsReadonly()) {
// mark custom options that should to fall back to default value
$options = $this->mergeProductOptions($productData['options'], $this->request->getPost('options_use_default'));
$customOptions = [];
foreach ($options as $customOptionData) {
if (!(bool) $customOptionData['is_delete']) {
$customOption = $this->customOptionFactory->create(['data' => $customOptionData]);
$customOption->setProductSku($product->getSku());
$customOption->setOptionId(null);
$customOptions[] = $customOption;
}
}
$product->setOptions($customOptions);
}
$product->setCanSaveCustomOptions((bool) $this->request->getPost('affect_product_custom_options') && !$product->getOptionsReadonly());
return $product;
}
示例15: execute
/**
* Validate product
*
* @return void
*/
public function execute()
{
$response = new \Magento\Framework\Object();
$response->setError(false);
try {
$productData = $this->getRequest()->getPost('product');
if ($productData && !isset($productData['stock_data']['use_config_manage_stock'])) {
$productData['stock_data']['use_config_manage_stock'] = 0;
}
/* @var $product \Magento\Catalog\Model\Product */
$product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
$product->setData('_edit_mode', true);
$storeId = $this->getRequest()->getParam('store');
if ($storeId) {
$product->setStoreId($storeId);
}
$setId = $this->getRequest()->getParam('set');
if ($setId) {
$product->setAttributeSetId($setId);
}
$typeId = $this->getRequest()->getParam('type');
if ($typeId) {
$product->setTypeId($typeId);
}
$productId = $this->getRequest()->getParam('id');
if ($productId) {
$product->load($productId);
}
$dateFieldFilters = array();
$attributes = $product->getAttributes();
foreach ($attributes as $attrKey => $attribute) {
if ($attribute->getBackend()->getType() == 'datetime') {
if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') {
$dateFieldFilters[$attrKey] = $this->_dateFilter;
}
}
}
$inputFilter = new \Zend_Filter_Input($dateFieldFilters, array(), $productData);
$productData = $inputFilter->getUnescaped();
$product->addData($productData);
/* set restrictions for date ranges */
$resource = $product->getResource();
$resource->getAttribute('special_from_date')->setMaxValue($product->getSpecialToDate());
$resource->getAttribute('news_from_date')->setMaxValue($product->getNewsToDate());
$resource->getAttribute('custom_design_from')->setMaxValue($product->getCustomDesignTo());
$this->productValidator->validate($product, $this->getRequest(), $response);
} catch (\Magento\Eav\Model\Entity\Attribute\Exception $e) {
$response->setError(true);
$response->setAttribute($e->getAttributeCode());
$response->setMessage($e->getMessage());
} catch (\Magento\Framework\Model\Exception $e) {
$response->setError(true);
$response->setMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
$this->_view->getLayout()->initMessages();
$response->setError(true);
$response->setHtmlMessage($this->_view->getLayout()->getMessagesBlock()->getGroupedHtml());
}
$this->getResponse()->representJson($response->toJson());
}