protected function _isEditedEntityLoaded($type, $config, $params, $entity) { if (parent::_isEditedEntityLoaded($type, $config, $params, $entity) && isset($params['additional']['class_type'])) { return $entity->getClassType() == $params['additional']['class_type']; } return false; }
public function checkUserEditPermissions($type, $model, $block = null, $params = array()) { if (parent::checkUserEditPermissions($type, $model, $block, $params)) { return Mage::getSingleton('admin/session')->isAllowed('sales/tax/rates'); } return false; }
/** * Return whether current request corresponds to an export one for active grid * * @param Mage_Core_Controller_Request_Http $request Request object * @return bool */ public function isExportRequest($request) { if (!is_null($this->_typeModel)) { return $this->_typeModel->isExportRequest($request, $this->getBlockType()); } return false; }
protected function _getSavedFieldValueForRender($type, $config, $params, $entity) { if ($config['id'] == 'store_id') { return $entity->getStores(); } else { return parent::_getSavedFieldValueForRender($type, $config, $params, $entity); } }
protected function _beforeSaveEditedFieldValue($type, $config, $params, $entity, $value) { if ($entity->getId() == Mage_Customer_Model_Group::NOT_LOGGED_IN_ID) { // Prevent from unique check (also made in original form, because code input is disabled and setCode is forced) $entity->setCode(null); } return parent::_beforeSaveEditedFieldValue($type, $config, $params, $entity, $value); }
protected function _getExportTypes($gridType) { $exportTypes = parent::_getExportTypes($gridType); foreach ($exportTypes as $key => $type) { if (!isset($type['params'])) { $exportTypes[$key]['params'] = array(); } $exportTypes[$key]['params'] = array_merge($exportTypes[$key]['params'], array('order_id' => $this->_getOrderId())); } return $exportTypes; }
protected function _beforeSaveEditedFieldValue($type, $config, $params, $entity, $value) { $model = Mage::getModel('catalogsearch/query'); $model->setStoreId($entity->getStoreId()); $model->loadByQueryText($entity->getQueryText()); if ($model->getId() && $model->getId() != $entity->getId()) { Mage::throwException(Mage::helper('catalog')->__('Search Term with such search query already exists.')); } $entity->setIsProcessed(0); return parent::_beforeSaveEditedFieldValue($type, $config, $params, $entity, $value); }
protected function _isEditedEntityLoaded($type, $config, $params, $entity) { if (parent::_isEditedEntityLoaded($type, $config, $params, $entity)) { if ($entity->getStatus() == $entity->getPendingStatus()) { return isset($params['additional']['use_pending_filter']); } else { return !isset($params['additional']['use_pending_filter']); } } return false; }
protected function _beforeApplyEditedFieldValue($type, $config, $params, $entity, &$value) { if (Mage::helper('customgrid')->isMageVersionGreaterThan(1, 5, 0) && in_array($config['id'], array('sitemap_filename', 'sitemap_path'))) { $fileName = $config['id'] == 'sitemap_filename' ? $entity->getSitemapFilename() : $value; $path = $config['id'] == 'sitemap_path' ? $entity->getSitemapPath() : $value; if (!empty($fileName) && !empty($path)) { $resultPath = rtrim($path, '\\/') . DS . $fileName; $helper = Mage::helper('adminhtml/catalog'); $validator = Mage::getModel('core/file_validator_availablePath'); $validator->setPaths($helper->getSitemapValidPaths()); if (!$validator->isValid($resultPath)) { Mage::throwException(implode("\n", $validator->getMessages())); } } } if (Mage::helper('customgrid/config_editor')->getSitemapDeleteFile() && $entity->getSitemapFilename() && file_exists($entity->getPreparedFilename())) { unlink($entity->getPreparedFilename()); } return parent::_beforeApplyEditedFieldValue($type, $config, $params, $entity, $value); }
protected function _getSavedFieldValueForRender($type, $config, $params, $entity) { if ($config['id'] == 'qty') { if ($stockItem = $entity->getStockItem()) { // Reload stock item to get the updated value $stockItem->setProductId(null)->assignProduct($entity); } $value = $this->_getProductInventoryData($entity, 'qty') * 1; return strval($value) !== '' ? $value : 0; } return parent::_getSavedFieldValueForRender($type, $config, $params, $entity); }
protected function _beforeApplyEditedFieldValue($type, $config, $params, $entity, &$value) { $entity->addData(array('tax_customer_class' => array_unique($entity->getCustomerTaxClasses()), 'tax_product_class' => array_unique($entity->getProductTaxClasses()), 'tax_rate' => array_unique($entity->getRates()))); return parent::_beforeApplyEditedFieldValue($type, $config, $params, $entity, $value); }
protected function _getSavedFieldValueForRender($type, $config, $params, $entity) { if ($config['id'] == 'store_ids') { $storesIds = $entity->getStoreIds(); return is_array($storesIds) ? $storesIds : explode(',', $storesIds); } else { return parent::_getSavedFieldValueForRender($type, $config, $params, $entity); } }
/** * Iterate collection and call callback method per item * For callback method first argument always is item object * * @param string $callback * @param array $args additional arguments for callback method * @return Mage_Adminhtml_Block_Widget_Grid */ public function _exportIterateCollection($callback, array $args) { if (!is_array($this->_blcg_exportInfos)) { return parent::_exportIterateCollection($callback, $args); } else { // Custom export if (!is_null($this->_blcg_exportedCollection)) { $originalCollection = $this->_blcg_exportedCollection; } else { $originalCollection = $this->getCollection(); } if ($originalCollection->isLoaded()) { // Should do the trick in all exceptions (if not loaded page size can be changed) Mage::throwException(Mage::helper('customgrid')->__('This grid does not seem to be compatible with the custom export. If you wish to report this problem, please indicate this class name : "%s"', get_class($this))); } // 1000 up to 1.4, class var from 1.5 $exportPageSize = isset($this->_exportPageSize) ? $this->_exportPageSize : 1000; $infos = $this->_blcg_exportInfos; $total = isset($infos['custom_size']) ? intval($infos['custom_size']) : (isset($infos['size']) ? intval($infos['size']) : $exportPageSize); if ($total <= 0) { return; } $fromResult = isset($infos['from_result']) ? intval($infos['from_result']) : 1; $pageSize = min($total, $exportPageSize); $page = ceil($fromResult / $pageSize); $pitchSize = $fromResult > 1 ? $fromResult - 1 - ($page - 1) * $pageSize : 0; $break = false; $count = null; while ($break !== true) { $collection = clone $originalCollection; $collection->setPageSize($pageSize); $collection->setCurPage($page); if (!is_null($this->_blcg_typeModel)) { $this->_blcg_typeModel->beforeGridExportLoadCollection($this, $collection); } $collection->load(); if (!is_null($this->_blcg_typeModel)) { $this->_blcg_typeModel->afterGridExportLoadCollection($this, $collection); } if (is_null($count)) { $count = $collection->getSize(); $total = min(max(0, $count - $fromResult + 1), $total); if ($total == 0) { $break = true; continue; } $first = true; $exported = 0; } $page++; $i = 0; foreach ($collection as $item) { if ($first) { if ($i++ < $pitchSize) { continue; } else { $first = false; } } if (++$exported > $total) { $break = true; break; } call_user_func_array(array($this, $callback), array_merge(array($item), $args)); } } } }
protected function _beforeSaveEditedFieldValue($type, $config, $params, $entity, $value) { $category = Mage::registry('current_category')->getId() ? Mage::registry('current_category') : null; if ($category) { $entity->setCategoryId($category->getId()); } $product = Mage::registry('current_product')->getId() ? Mage::registry('current_product') : null; if ($product) { $entity->setProductId($product->getId()); } if ($product || $category) { $catalogUrlModel = Mage::getSingleton('catalog/url'); $idPath = $catalogUrlModel->generatePath('id', $product, $category); // If redirect specified try to find friendly URL $found = false; if (in_array($entity->getOptions(), array('R', 'RP'))) { $rewrite = Mage::getResourceModel('catalog/url')->getRewriteByIdPath($idPath, $entity->getStoreId()); if (!$rewrite) { Mage::throwException('Chosen product does not associated with the chosen store or category.'); } if ($rewrite->getId() && $rewrite->getId() != $entity->getId()) { $entity->setIdPath($idPath); $entity->setTargetPath($rewrite->getRequestPath()); $found = true; } } if (!$found) { $entity->setIdPath($idPath); $entity->setTargetPath($catalogUrlModel->generatePath('target', $product, $category)); } } return parent::_beforeSaveEditedFieldValue($type, $config, $params, $entity, $value); }
/** * Update grid available custom columns and save * * @param array $columns New columns informations * @return this */ public function updateCustomColumns(array $columns, $mustSave = true) { $this->loadColumns(); $helper = $this->_getHelper(); if (!is_null($this->_typeModel)) { $typeCode = $this->_typeModel->getCode(); } else { return $this; } $availableColumns = $this->getAvailableCustomColumns(); $availableCodes = array_keys($availableColumns); // Requested codes $customCodes = !is_null($typeCode) ? $columns : array(); // Codes of the same grid type that are already used $usedCodes = array(); // IDs that should be removed $removedIds = array(); foreach ($this->_originIds[self::GRID_COLUMN_ORIGIN_CUSTOM] as $columnId) { if (!is_null($typeCode)) { $parts = explode('/', $this->_columns[$columnId]['index']); if ($typeCode == $parts[0] && in_array($parts[1], $customCodes) && in_array($parts[1], $availableCodes)) { $usedCodes[] = $parts[1]; } else { $removedIds[] = $columnId; } } else { $removedIds[] = $columnId; } } // Add new columns whenever needed $newCodes = array_intersect($availableCodes, array_diff($customCodes, $usedCodes)); $columnsGroups = $this->getCustomColumnsGroups(); foreach ($newCodes as $code) { $newColumnId = $this->_getNextCustomColumnId(); $columnModel = $availableColumns[$code]; if (isset($columnsGroups[$columnModel->getGroupId()]) && $this->_getConfigHelper()->getAddGroupToCustomColumnsDefaultHeader()) { $header = $helper->__('%s (%s)', $columnModel->getName(), $columnsGroups[$columnModel->getGroupId()]); } else { $header = $columnModel->getName(); } $this->_columns[$newColumnId] = array('grid_id' => $this->getId(), 'id' => $newColumnId, 'index' => $typeCode . '/' . $code, 'width' => '', 'align' => self::GRID_COLUMN_ALIGNMENT_LEFT, 'header' => $header, 'order' => $this->_getNextOrder(), 'origin' => self::GRID_COLUMN_ORIGIN_CUSTOM, 'is_visible' => 1, 'filter_only' => 0, 'is_system' => 0, 'missing' => 0, 'store_id' => null, 'renderer_type' => null, 'renderer_params' => null, 'allow_edit' => 0, 'custom_params' => null); $this->_originIds[self::GRID_COLUMN_ORIGIN_CUSTOM][] = $newColumnId; } // Remove necessary IDs foreach ($removedIds as $columnId) { unset($this->_columns[$columnId]); } // Recompute max order, as it may have now changed $this->_recomputeMaxOrder(); return $mustSave ? $this->save() : $this->setDataChanges(true); }
protected function _afterSaveEditedAttributeValue($type, $config, $params, $entity, $value, $result) { if ($this->_mustUseDefaultValueForSave($config, $params)) { // Force product reload if default value was used, to ensure getting the good (default) value for rendering $config['config']['render_reload'] = true; } /* TODO from 1.5, but what about giving the choice to the user ? and for which attributes ? (not just all, as it is certainly not useful in most of the cases) // Mage::getModel('catalogrule/rule')->applyAllRulesToProduct($productId); */ return parent::_afterSaveEditedAttributeValue($type, $config, $params, $entity, $value, $result); }