public function validateAction() { $response = new Varien_Object(); $response->setError(false); try { /** * @todo implement full validation process with errors returning which are ignoring now */ } 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()->addError($e->getMessage()); $this->_initLayoutMessages('adminhtml/session'); $response->setError(true); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); } $this->getResponse()->setBody($response->toJson()); }
/** * 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()); }
public function validateAction() { $postData = $this->getRequest()->getPost('post'); $response = new Varien_Object(); if (!$postData['post_identifier']) { $url = Mage::helper('blog/post')->friendlyURL($postData['title']); } else { $url = Mage::helper('blog/post')->friendlyURL($postData['post_identifier']); } $urlInstance = Mage::getModel('blog/url'); if ($urlInstance->validate($url . '.html', 'post_id', $postData['entity_id'])) { $response->setError(true); $response->setAttribute("post_identifier"); $response->setMessage(Mage::helper('blog')->__("The value of post identifier is unique")); $response->setData('post_identifier', $url); } else { $response->setError(false); } $this->getResponse()->setBody($response->toJson()); }
public function validateAction() { $response = new Varien_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; } $product = Mage::getModel('catalog/product')->setId($this->getRequest()->getParam('id'))->addData($productData)->validate(); } catch (Mage_Eav_Model_Entity_Attribute_Exception $e) { $response->setError(true); $response->setAttribute($e->getAttributeCode()); $response->setMessage($e->getMessage()); } catch (Exception $e) { $this->_getSession()->addError($e->getMessage()); $this->_initLayoutMessages('adminhtml/session'); $response->setError(true); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); } $this->getResponse()->setBody($response->toJson()); }
public function validateAction() { $url = $this->getRequest()->getPost('tag_identifier'); if (!$url) { $url = Mage::helper('blog/post')->friendlyURL($this->getRequest()->getPost('name')); } else { $url = Mage::helper('blog/post')->friendlyURL($url); } $response = new Varien_Object(); $response->setError(false); $urlInstance = Mage::getModel('blog/url'); if ($urlInstance->validate('tag/' . $url . '.html', 'tag_id', $this->getRequest()->getParam('id'))) { $response->setError(true); $response->setAttribute("Tag Identifier"); $response->setMessage("Tag identifier is unique"); $response->setData('identifier', $url); } $this->getResponse()->setBody($response->toJson()); }
public function validateAction() { $postData = $this->getRequest()->getPost(); $response = new Varien_Object(); if (isset($postData['identifier'])) { $identifier = $postData['identifier']; $model = Mage::getModel('themeframework/theme')->load($identifier, 'identifier'); $id = 0; if (isset($postData['theme_id'])) { $id = $postData['theme_id']; } if ($model->getId()) { if ($model->getId() != $id) { $response->setError(true); $response->setAttribute("info_identifier"); $response->setMessage(Mage::helper('themeframework')->__("The value of identifier is unique")); } else { $response->setError(false); } } else { $response->setError(false); } } else { $response->setError(false); } $this->getResponse()->setBody($response->toJson()); }
/** * Validate product * */ public function validateAction() { $response = new Varien_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 Mage_Catalog_Model_Product */ $product = Mage::getModel('Mage_Catalog_Model_Product'); $product->setData('_edit_mode', true); if ($storeId = $this->getRequest()->getParam('store')) { $product->setStoreId($storeId); } if ($setId = $this->getRequest()->getParam('set')) { $product->setAttributeSetId($setId); } if ($typeId = $this->getRequest()->getParam('type')) { $product->setTypeId($typeId); } if ($productId = $this->getRequest()->getParam('id')) { $product->load($productId); } $dateFields = array(); $attributes = $product->getAttributes(); foreach ($attributes as $attrKey => $attribute) { if ($attribute->getBackend()->getType() == 'datetime') { if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') { $dateFields[] = $attrKey; } } } $productData = $this->_filterDates($productData, $dateFields); $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()); $product->validate(); /** * @todo implement full validation process with errors returning which are ignoring now */ // if (is_array($errors = $product->validate())) { // foreach ($errors as $code => $error) { // if ($error === true) { // Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__('Attribute "%s" is invalid.', $product->getResource()->getAttribute($code)->getFrontend()->getLabel())); // } // else { // Mage::throwException($error); // } // } // } } 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()->addError($e->getMessage()); $this->_initLayoutMessages('Mage_Adminhtml_Model_Session'); $response->setError(true); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); } $this->getResponse()->setBody($response->toJson()); }
/** * Validate product * */ public function validateAction() { $response = new Varien_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; } $product = Mage::getModel('catalog/product'); $product->setData('_edit_mode', true); if ($storeId = $this->getRequest()->getParam('store')) { $product->setStoreId($storeId); } if ($setId = $this->getRequest()->getParam('set')) { $product->setAttributeSetId($setId); } if ($typeId = $this->getRequest()->getParam('type')) { $product->setTypeId($typeId); } if ($productId = $this->getRequest()->getParam('id')) { $product->load($productId); } $product->addData($productData); $product->validate(); /** * @todo implement full validation process with errors returning which are ignoring now */ // if (is_array($errors = $product->validate())) { // foreach ($errors as $code => $error) { // if ($error === true) { // Mage::throwException(Mage::helper('catalog')->__('Attribute "%s" is invalid.', $product->getResource()->getAttribute($code)->getFrontend()->getLabel())); // } // else { // Mage::throwException($error); // } // } // } } 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()->addError($e->getMessage()); $this->_initLayoutMessages('adminhtml/session'); $response->setError(true); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); } $this->getResponse()->setBody($response->toJson()); }
public function validateAction() { $categoryData = $this->getRequest()->getPost('general'); if (!$categoryData['url_key']) { $url = Mage::helper('blog/post')->friendlyURL($categoryData['name']); } else { $url = Mage::helper('blog/post')->friendlyURL($categoryData['url_key']); } $response = new Varien_Object(); $newUrlPath = ''; $id = (int) $this->getRequest()->getParam('id', false); /* Category exists */ if ($id) { $category = Mage::getModel('blog/category')->load($id); if ($category->getLevel() == 1) { $response->setError(false); } else { $oldUrlPathArray = explode('/', $category->getPathUrl()); if ($url == $oldUrlPathArray[count($oldUrlPathArray) - 1]) { // url_key is not change $response->setError(false); } else { /* Create new url path to validate */ unset($oldUrlPathArray[count($oldUrlPathArray) - 1]); $oldUrlPathArray[] = $url; $newUrlPath = sprintf('%s.html', implode('/', $oldUrlPathArray)); } } } else { $parentId = $this->getRequest()->getParam('parent'); if (!$parentId) { if ($storeId = $this->getRequest()->getParam('store')) { $parentId = Mage::helper('blog/category')->getRootCategory()->getId(); } else { $parentId = EM_Blog_Model_Category::TREE_ROOT_ID; } } if ($parentId == EM_Blog_Model_Category::TREE_ROOT_ID) { // Create new root category $response->setError(false); } else { $parent = Mage::getModel('blog/category')->load($parentId); if ($parent->getPathUrl()) { $newUrlPath = sprintf('%s/%s.html', $parent->getPathUrl(), $url); } else { $newUrlPath = sprintf('%s.html', $url); } } } /* Validate new url path */ if ($newUrlPath) { $urlInstance = Mage::getModel('blog/url'); if ($urlInstance->validate($newUrlPath, 'category_id', $id)) { $response->setError(true); $response->setAttribute("url_key"); $response->setMessage(Mage::helper('blog')->__("The path %s is unique", $newUrlPath)); $response->setData('url_key', $url); } else { $response->setError(false); } } $this->getResponse()->setBody($response->toJson()); }
/** * Validate product * * @return $response */ public function validate() { $response = new Varien_Object(); $response->setError(false); try { $productData = $this->getRequest()->getPost(); $productData['stock_data']['use_config_manage_stock'] = 0; /* @var $product Mage_Catalog_Model_Product */ $product = Mage::getModel('catalog/product'); if ($storeId = Mage::app()->getStore()->getStoreId()) { $product->setStoreId($storeId); } if ($setId = $this->getRequest()->getParam('attribute_set_id')) { $product->setAttributeSetId($setId); } if ($typeId = $this->getRequest()->getParam('type_id')) { $product->setTypeId($typeId); } if ($productId = $this->getRequest()->getParam('productid')) { $product->setData('_edit_mode', true); $product->load($productId); } $dateFields = array(); $attributes = $product->getAttributes(); foreach ($attributes as $attrKey => $attribute) { if ($attribute->getBackend()->getType() == 'datetime') { if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') { $dateFields[] = $attrKey; } } } $productData = $this->_filterDates($productData, $dateFields); $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()); $product->validate(); } 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()->addError(Mage::helper('marketplace')->__($e->getMessage())); $this->_initLayoutMessages('core/session'); $response->setError(true); $response->setMessage($e->getMessage()); } return $response; }
public function validateAction() { $postData = $this->getRequest()->getPost(); $response = new Varien_Object(); $slideshow_id = Mage::app()->getFrontController()->getRequest()->getParam("slideshow_id", 0); if (isset($postData['identifier'])) { $identifier = $postData['identifier']; $model = Mage::getModel('revslideshow/revslideshow')->load($identifier, 'identifier'); if ($model->getId()) { if ($model->getId() != $slideshow_id) { $response->setError(true); $response->setAttribute("info_identifier"); $response->setMessage(Mage::helper('revslideshow')->__("The value of identifier is unique")); } else { $response->setError(false); } } else { $response->setError(false); } } else { $response->setError(false); } $this->getResponse()->setBody($response->toJson()); }
public function validateAction() { $postData = $this->getRequest()->getPost(); $response = new Varien_Object(); if (!$postData['identifier']) { $identifier = Mage::helper('flexibleblock')->friendlyIdentifier($postData['title']); } else { $identifier = Mage::helper('flexibleblock')->friendlyIdentifier($postData['identifier']); } $collection = Mage::getResourceModel('flexibleblock/fblock_collection')->addAttributeToFilter('identifier', $identifier); $id = $this->getRequest()->getParam('id'); if ($id) { $collection->addAttributeToFilter('entity_id', array('neq' => $id)); } if ($collection->getSize() > 0) { $response->setError(true); $response->setAttribute("fblock_identifier"); $response->setMessage(Mage::helper('flexibleblock')->__("The value of identifier is unique")); } else { $response->setError(false); } $this->getResponse()->setBody($response->toJson()); }