public function importratesAction() { $websiteId = $this->getRequest()->getParam('website_id'); $csvFile = !empty($_FILES['import']['tmp_name']) ? $_FILES['import']['tmp_name'] : null; if (!$websiteId || !$csvFile) { $this->_getSession()->addError($this->__("Please specify the website and file you wish to import")); $this->_redirect('*/*/import'); return; } $_FILES = array('groups' => array('tmp_name' => array('tablerate' => array('fields' => array('import' => array('value' => $csvFile)))))); $params = new Varien_Object(); $params->setScopeId($websiteId); $condition = array('groups' => array('tablerate' => array('fields' => array('condition_name' => array('value' => $this->_getShippingRatesAdminHelper()->getWebsiteConfigData('carriers/tablerate/condition_name', $websiteId)))))); $params->addData($condition); $tableRate = Mage::getResourceModel('shipping/carrier_tablerate'); /* @var $tableRate Mage_Shipping_Model_Resource_Carrier_Tablerate */ $message = ""; try { $tableRate->uploadAndImport($params); } catch (Mage_Core_Exception $e) { $message = $e->getMessage(); } catch (Exception $e) { $this->_getSession()->addError($this->__("An error occurred whilst importing the tablerates: %s", $e->getMessage())); $this->_redirect('*/*/import'); return; } if (!$message) { $message = $this->__("Table rates imported successfully"); $this->_getSession()->addSuccess($message); } else { $this->_getSession()->addError(str_replace("\n", "<br />", $message)); } $this->_redirect('*/*/index'); }
public function importratesAction() { if (!$this->_checkCarrierCode()) { return; } $websiteId = $this->getRequest()->getParam('website_id'); $csvFile = !empty($_FILES['import']['tmp_name']) ? $_FILES['import']['tmp_name'] : null; if (!$websiteId || !$csvFile) { $this->_getSession()->addError($this->__("Please specify the website and file you wish to import")); $this->_redirect('*/*/import', array("carrier" => $this->_getTableRateHelper()->getCarrierCode())); return; } $params = new Varien_Object(); $params->setScopeId($websiteId); $resourceClass = null; $method = null; $this->_getTableRateHelper()->getImportAction($resourceClass, $method); $message = ""; try { Mage::getResourceModel($resourceClass)->{$method}($params, $csvFile); } catch (Mage_Core_Exception $e) { $message = $e->getMessage(); } catch (Exception $e) { $this->_getSession()->addError($this->__("An error occurred whilst importing the tablerates: %s", $e->getMessage())); $this->_redirect('*/*/import', array("carrier" => $this->_getTableRateHelper()->getCarrierCode())); return; } if (!$message) { $message = $this->__("Table rates imported successfully"); $this->_getSession()->addSuccess($message); } else { $this->_getSession()->addError(str_replace("\n", "<br />", $message)); } $this->_redirect('*/*/index', array("carrier" => $this->_getTableRateHelper()->getCarrierCode())); }