/** * Get store * * @param Varien_Object $request * @return \Mage_Core_Model_Store */ protected function _getStore($request) { $store = Mage::app()->getStore(); if ($request->getStore() !== null) { $store = $request->getStore(); } return $store; }
public function render(Varien_Object $row) { $id = $row->getId(); $arrParam = array('id' => $id); if ($row->getStore() != '') { $arrParam['store'] = $row->getStore(); } $url = $this->getUrl('*/*/edit', $arrParam); return sprintf("<a href='%s'>%s</a>", $url, Mage::helper('catalog')->__('Edit')); }
/** * Save system config event * * @param Varien_Object $observer */ public function saveSystemConfig($observer) { $store = $observer->getStore(); $website = $observer->getWebsite(); $groups['settings']['fields']['cron_schedule']['value'] = $this->_getSchedule(); Mage::getModel('adminhtml/config_data')->setSection('feed')->setWebsite($website)->setStore($store)->setGroups($groups)->save(); }
protected function _prepareForm() { $_form = new Varien_Data_Form(); $this->setForm($_form); $_data = Mage::helper('awautorelated/forms')->getFormData($this->getRequest()->getParam('id')); if (!is_object($_data)) { $_data = new Varien_Object($_data); } $_fieldset = $_form->addFieldset('general_fieldset', array('legend' => $this->__('General'))); $_fieldset->addField('name', 'text', array('name' => 'name', 'label' => $this->__('Name'), 'required' => true)); if ($_data->getData('status') === null) { $_data->setData('status', 1); } $_fieldset->addField('status', 'select', array('name' => 'status', 'label' => $this->__('Status'), 'required' => TRUE, 'values' => Mage::getModel('awautorelated/source_status')->toOptionArray())); if (!Mage::app()->isSingleStoreMode()) { $_fieldset->addField('store', 'multiselect', array('name' => 'store[]', 'label' => $this->__('Store View'), 'required' => TRUE, 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(FALSE, TRUE))); } else { if ($_data->getStore() && is_array($_data->getStore())) { $_stores = $_data->getStore(); if (isset($_stores[0]) && $_stores[0] != '') { $_stores = $_stores[0]; } else { $_stores = 0; } $_data->setStore($_stores); } $_fieldset->addField('store', 'hidden', array('name' => 'store[]')); } if (!$_data->getStore()) { $_data->setStore(0); } if ($_data->getData('customer_groups') === null) { $_data->setData('customer_groups', array(Mage_Customer_Model_Group::CUST_GROUP_ALL)); } $_fieldset->addField('customer_groups', 'multiselect', array('name' => 'customer_groups[]', 'label' => $this->__('Customer groups'), 'title' => $this->__('Customer groups'), 'required' => true, 'values' => Mage::getModel('awautorelated/source_customer_groups')->toOptionArray())); $_fieldset->addField('priority', 'text', array('name' => 'priority', 'label' => $this->__('Priority'), 'title' => $this->__('Priority'), 'required' => false)); $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $_fieldset->addField('date_from', 'date', array('name' => 'date_from', 'label' => $this->__('Date From'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso)); $_fieldset->addField('date_to', 'date', array('name' => 'date_to', 'label' => $this->__('Date To'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso)); $_fieldset->addField('position', 'select', array('name' => 'position', 'label' => $this->__('Position'), 'title' => $this->__('Position'), 'required' => true, 'values' => Mage::getModel('awautorelated/source_position')->toOptionArray(AW_Autorelated_Model_Source_Type::CATEGORY_PAGE_BLOCK))); $_form->setValues($_data); }
protected function _prepareForm() { $_form = new Varien_Data_Form(); $this->setForm($_form); $_data = Mage::getSingleton('adminhtml/session')->getData(AW_Featured_Helper_Data::FORM_DATA_KEY); if (!is_object($_data)) { $_data = new Varien_Object($_data); } $_fieldset = $_form->addFieldset('block_fieldset', array('legend' => $this->__('General'))); $_fieldset->addField('block_name', 'text', array('name' => 'block_name', 'label' => $this->__('Name'), 'required' => TRUE)); $_fieldset->addField('block_id', 'text', array('name' => 'block_id', 'label' => $this->__('Block ID'), 'required' => TRUE)); if (is_null($_data->getIsActive())) { $_data->setIsActive(TRUE); } $_fieldset->addField('is_active', 'select', array('name' => 'is_active', 'label' => $this->__('Status'), 'required' => TRUE, 'values' => Mage::getModel('awfeatured/source_status')->toOptionArray())); if (!Mage::app()->isSingleStoreMode()) { $_fieldset->addField('store', 'multiselect', array('name' => 'store[]', 'label' => $this->__('Store View'), 'required' => TRUE, 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(FALSE, TRUE))); } else { if ($_data->getStore() && is_array($_data->getStore())) { $_stores = $_data->getStore(); if (isset($_stores[0]) && $_stores[0] != '') { $_stores = $_stores[0]; } else { $_stores = 0; } $_data->setStore($_stores); } $_fieldset->addField('store', 'hidden', array('name' => 'store[]')); } if (!$_data->getStore()) { $_data->setStore(0); } $_fieldset->addField('type', 'select', array('name' => 'type', 'label' => $this->__('Representation'), 'values' => Mage::getModel('awfeatured/source_representation')->toOptionArray())); $_fieldset->addField('autoposition', 'select', array('name' => 'autoposition', 'label' => $this->__('Automatic layout position'), 'values' => Mage::getModel('awfeatured/source_autoposition')->toOptionArray())); $_fieldset = $_form->addFieldset('types_data_fset', array('legend' => $this->__('Representation settings'))); $_fieldset->setFieldsetContainerId('awf_types_settings'); $_fieldset->addField('types_data', 'note', array('text' => $this->__('No representation has been selected'))); $_form->setValues($_data); }
protected function _prepareForm() { $form = new Varien_Data_Form(); $blockData = Mage::registry(AW_Autorelated_Adminhtml_ShoppingcartblockController::BLOCK_REGISTRY_KEY); if (!$blockData instanceof Varien_Object) { $blockData = new Varien_Object(); } $fieldset = $form->addFieldset('general', array('legend' => $this->__('General'))); $fieldset->addField('name', 'text', array('name' => 'name', 'label' => $this->__('Name'), 'required' => true)); if ($blockData->getData('status') === null) { $blockData->setData('status', 1); } $fieldset->addField('status', 'select', array('name' => 'status', 'label' => $this->__('Status'), 'required' => true, 'values' => Mage::getModel('awautorelated/source_status')->toOptionArray())); $stores = $blockData->getStore(); if (!Mage::app()->isSingleStoreMode()) { $fieldset->addField('store', 'multiselect', array('name' => 'store[]', 'label' => $this->__('Store View'), 'required' => true, 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true))); } else { if ($stores && is_array($stores) && isset($stores[0]) && $stores[0] != '') { $stores = $stores[0]; } else { $stores = 0; } $fieldset->addField('store', 'hidden', array('name' => 'store[]')); } if ($blockData->getData('customer_groups') === null) { $blockData->setData('customer_groups', array(Mage_Customer_Model_Group::CUST_GROUP_ALL)); } $fieldset->addField('customer_groups', 'multiselect', array('name' => 'customer_groups[]', 'label' => $this->__('Customer groups'), 'title' => $this->__('Customer groups'), 'required' => true, 'values' => Mage::getModel('awautorelated/source_customer_groups')->toOptionArray())); $fieldset->addField('priority', 'text', array('name' => 'priority', 'label' => $this->__('Priority'), 'title' => $this->__('Priority'), 'required' => false)); $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $fieldset->addField('date_from', 'date', array('name' => 'date_from', 'label' => $this->__('Date From'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso)); $fieldset->addField('date_to', 'date', array('name' => 'date_to', 'label' => $this->__('Date To'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso)); $fieldset->addField('position', 'select', array('name' => 'position', 'label' => $this->__('Position'), 'title' => $this->__('Position'), 'required' => true, 'values' => Mage::getModel('awautorelated/source_position')->toOptionArray(AW_Autorelated_Model_Source_Type::SHOPPING_CART_BLOCK))); $form->setValues($blockData->toArray()); $this->setForm($form); }
/** * Returns tax rates for request - either pereforms SELECT from DB, or returns already cached result * Notice that productClassId due to optimization can be array of ids * * @param Varien_Object $request * @return array */ protected function _getRates($request) { // Extract params that influence our SELECT statement and use them to create cache key $storeId = Mage::app()->getStore($request->getStore())->getId(); $customerClassId = $request->getCustomerClassId(); $countryId = $request->getCountryId(); $regionId = $request->getRegionId(); $postcode = $request->getPostcode(); // Process productClassId as it can be array or usual value. Form best key for cache. $productClassId = $request->getProductClassId(); $ids = is_array($productClassId) ? $productClassId : array($productClassId); foreach ($ids as $key => $val) { $ids[$key] = (int) $val; // Make it integer for equal cache keys even in case of null/false/0 values } $ids = array_unique($ids); sort($ids); $productClassKey = implode(',', $ids); // Form cache key and either get data from cache or from DB $cacheKey = implode('|', array($storeId, $customerClassId, $productClassKey, $countryId, $regionId, $postcode)); if (!isset($this->_ratesCache[$cacheKey])) { // Make SELECT and get data $select = $this->_getReadAdapter()->select(); $select->from(array('main_table' => $this->getMainTable()), array('tax_calculation_rate_id', 'tax_calculation_rule_id', 'customer_tax_class_id', 'product_tax_class_id'))->where('customer_tax_class_id = ?', (int) $customerClassId); if ($productClassId) { $select->where('product_tax_class_id IN (?)', $productClassId); } $ifnullTitleValue = $this->_getReadAdapter()->getCheckSql('title_table.value IS NULL', 'rate.code', 'title_table.value'); $ruleTableAliasName = $this->_getReadAdapter()->quoteIdentifier('rule.tax_calculation_rule_id'); $select->join(array('rule' => $this->getTable('tax/tax_calculation_rule')), $ruleTableAliasName . ' = main_table.tax_calculation_rule_id', array('rule.priority', 'rule.position'))->join(array('rate' => $this->getTable('tax/tax_calculation_rate')), 'rate.tax_calculation_rate_id = main_table.tax_calculation_rate_id', array('value' => 'rate.rate', 'rate.tax_country_id', 'rate.tax_region_id', 'rate.tax_postcode', 'rate.tax_calculation_rate_id', 'rate.code'))->joinLeft(array('title_table' => $this->getTable('tax/tax_calculation_rate_title')), "rate.tax_calculation_rate_id = title_table.tax_calculation_rate_id " . "AND title_table.store_id = '{$storeId}'", array('title' => $ifnullTitleValue))->where('rate.tax_country_id = ?', $countryId)->where("rate.tax_region_id IN(?)", array(0, (int) $regionId)); $postcodeIsNumeric = is_numeric($postcode); if ($postcodeIsNumeric) { $selectClone = clone $select; $selectClone->where('rate.zip_is_range IS NOT NULL'); } $select->where('rate.zip_is_range IS NULL'); if ($request->getPostcode() != '*') { $select->where("rate.tax_postcode IS NULL OR rate.tax_postcode IN('*', '', ?)", $this->_createSearchPostCodeTemplates($postcode)); if ($postcodeIsNumeric) { $selectClone->where('? BETWEEN rate.zip_from AND rate.zip_to', $postcode); } } /** * @see ZF-7592 issue http://framework.zend.com/issues/browse/ZF-7592 */ if ($postcodeIsNumeric) { $select = $this->_getReadAdapter()->select()->union(array('(' . $select . ')', '(' . $selectClone . ')')); } $select->order('priority ' . Varien_Db_Select::SQL_ASC)->order('tax_calculation_rule_id ' . Varien_Db_Select::SQL_ASC)->order('tax_country_id ' . Varien_Db_Select::SQL_DESC)->order('tax_region_id ' . Varien_Db_Select::SQL_DESC)->order('tax_postcode ' . Varien_Db_Select::SQL_DESC)->order('value ' . Varien_Db_Select::SQL_DESC); $this->_ratesCache[$cacheKey] = $this->_getReadAdapter()->fetchAll($select); } return $this->_ratesCache[$cacheKey]; }
/** * Load select and return tax rates * * @param Varien_Object $request * @return array */ protected function _getRates($request) { $storeId = Mage::app()->getStore($request->getStore())->getId(); $select = $this->_getReadAdapter()->select(); $select->from(array('main_table' => $this->getMainTable()))->where('customer_tax_class_id = ?', $request->getCustomerClassId()); if ($request->getProductClassId()) { $select->where('product_tax_class_id IN (?)', $request->getProductClassId()); } $select->join(array('rule' => $this->getTable('tax/tax_calculation_rule')), 'rule.tax_calculation_rule_id = main_table.tax_calculation_rule_id', array('rule.priority', 'rule.position')); $select->join(array('rate' => $this->getTable('tax/tax_calculation_rate')), 'rate.tax_calculation_rate_id = main_table.tax_calculation_rate_id', array('value' => 'rate.rate', 'rate.tax_country_id', 'rate.tax_region_id', 'rate.tax_postcode', 'rate.tax_calculation_rate_id', 'rate.code')); $select->joinLeft(array('title_table' => $this->getTable('tax/tax_calculation_rate_title')), "rate.tax_calculation_rate_id = title_table.tax_calculation_rate_id AND title_table.store_id = '{$storeId}'", array('title' => 'IFNULL(title_table.value, rate.code)')); $select->where("rate.tax_country_id = ?", $request->getCountryId())->where("rate.tax_region_id in ('*', '', ?)", $request->getRegionId()); $selectClone = clone $select; $select->where("rate.zip_is_range IS NULL")->where("rate.tax_postcode in ('*', '', ?)", $this->_createSearchPostCodeTemplates($request->getPostcode())); $selectClone->where("rate.zip_is_range IS NOT NULL")->where("? BETWEEN rate.zip_from AND rate.zip_to", $request->getPostcode()); /** * @see ZF-7592 issue http://framework.zend.com/issues/browse/ZF-7592 */ $select = $this->_getReadAdapter()->select()->union(array('(' . $select . ')', '(' . $selectClone . ')')); $order = array('priority ASC', 'tax_calculation_rule_id ASC', 'tax_country_id DESC', 'tax_region_id DESC', 'tax_postcode DESC', 'value DESC'); $select->order($order); return $this->_getReadAdapter()->fetchAll($select); }