Пример #1
0
 protected function _prepareCollection()
 {
     $collection = AO::getModel('sitemap/sitemap')->getCollection();
     /* @var $collection Mage_Sitemap_Model_Mysql4_Sitemap_Collection */
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
Пример #2
0
 public function getEntitySummary($product, $storeId = 0)
 {
     $summaryData = AO::getModel('review/review_summary')->setStoreId($storeId)->load($product->getId());
     $summary = new Varien_Object();
     $summary->setData($summaryData->getData());
     $product->setRatingSummary($summary);
 }
 protected function _getUrlModel()
 {
     if (is_null($this->_url)) {
         $this->_url = AO::getModel('adminhtml/url');
     }
     return $this->_url;
 }
 protected function _prepareCollection()
 {
     $collection = AO::getResourceModel('reports/tag_product_collection');
     $collection->addTagedCount()->addProductFilter($this->getRequest()->getParam('id'))->addStatusFilter(AO::getModel('tag/tag')->getApprovedStatus())->addStoresVisibility()->setActiveFilter()->addGroupByTag()->setRelationId();
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
Пример #5
0
 /**
  * Retrieve wishlist by logged in customer
  *
  * @return Mage_Wishlist_Model_Wishlist
  */
 public function getWishlist()
 {
     if (is_null($this->_wishlist)) {
         $this->_wishlist = AO::getModel('wishlist/wishlist')->loadByCustomer($this->_getCurrentCustomer());
     }
     return $this->_wishlist;
 }
Пример #6
0
 protected function _construct()
 {
     $this->_init('catalogindex/indexer_price');
     $this->_currencyModel = AO::getModel('directory/currency');
     $this->_customerGroups = AO::getModel('customer/group')->getCollection();
     return parent::_construct();
 }
Пример #7
0
 /**
  * Try to login user in admin
  *
  * @param  string $username
  * @param  string $password
  * @param  Mage_Core_Controller_Request_Http $request
  * @return Mage_Admin_Model_User|null
  */
 public function login($username, $password, $request = null)
 {
     if (empty($username) || empty($password)) {
         return;
     }
     try {
         /* @var $user Mage_Admin_Model_User */
         $user = AO::getModel('admin/user');
         $user->login($username, $password);
         if ($user->getId()) {
             if (AO::getSingleton('adminhtml/url')->useSecretKey()) {
                 AO::getSingleton('adminhtml/url')->renewSecretUrls();
             }
             $session = AO::getSingleton('admin/session');
             $session->setIsFirstVisit(true);
             $session->setUser($user);
             $session->setAcl(AO::getResourceModel('admin/acl')->loadAcl());
             if ($requestUri = $this->_getRequestUri($request)) {
                 header('Location: ' . $requestUri);
                 exit;
             }
         } else {
             AO::throwException(AO::helper('adminhtml')->__('Invalid Username or Password.'));
         }
     } catch (Mage_Core_Exception $e) {
         if ($request && !$request->getParam('messageSent')) {
             AO::getSingleton('adminhtml/session')->addError($e->getMessage());
             $request->setParam('messageSent', true);
         }
     }
     return $user;
 }
Пример #8
0
 protected function _loadAttribute($id)
 {
     if (!isset($this->_attributeCache[$id])) {
         $this->_attributeCache[$id] = AO::getModel('eav/entity_attribute')->load($id);
     }
     return $this->_attributeCache[$id];
 }
 protected function _prepareForm()
 {
     if (!$this->_form) {
         if ($this->getQuote()->getCustomerIsGuest()) {
             $display = array('email' => 1);
         } else {
             $display = array('group_id' => 1, 'email' => 2);
         }
         $this->_form = new Varien_Data_Form();
         $fieldset = $this->_form->addFieldset('main', array());
         $customerModel = AO::getModel('customer/customer');
         foreach ($customerModel->getAttributes() as $attribute) {
             if (!array_key_exists($attribute->getAttributeCode(), $display)) {
                 continue;
             }
             if ($inputType = $attribute->getFrontend()->getInputType()) {
                 $element = $fieldset->addField($attribute->getAttributeCode(), $inputType, array('name' => $attribute->getAttributeCode(), 'label' => $attribute->getFrontend()->getLabel(), 'class' => $attribute->getFrontend()->getClass(), 'required' => $attribute->getIsRequired()))->setEntityAttribute($attribute);
                 if ($inputType == 'select' || $inputType == 'multiselect') {
                     $element->setValues($attribute->getFrontend()->getSelectOptions());
                 }
                 $element->setSortOrder($display[$attribute->getAttributeCode()]);
             }
         }
         /*
          * want to sort element only when there are more than one element
          */
         if ($fieldset->getElements()->count() > 1) {
             $fieldset->getElements()->usort(array($this, '_sortMethods'));
         }
         $this->_form->addFieldNameSuffix('order[account]');
         $this->_form->setValues($this->getCustomerData());
     }
     return $this;
 }
Пример #10
0
 protected function _prepareCollection()
 {
     $collection = AO::getModel('core/website')->getCollection()->joinGroupAndStore();
     $this->setCollection($collection);
     parent::_prepareCollection();
     return $this;
 }
Пример #11
0
 /**
  * Custom options downloader
  */
 public function downloadCustomOptionAction()
 {
     $quoteItemOptionId = $this->getRequest()->getParam('id');
     $secretKey = $this->getRequest()->getParam('key');
     $option = AO::getModel('sales/quote_item_option')->load($quoteItemOptionId);
     if ($option->getId()) {
         try {
             $info = unserialize($option->getValue());
             if ($secretKey != $info['secret_key']) {
                 throw new Exception();
             }
             $filePath = AO::getBaseDir() . $info['order_path'];
             if (!is_file($filePath) || !is_readable($filePath)) {
                 // try get file from quote
                 $filePath = AO::getBaseDir() . $info['quote_path'];
                 if (!is_file($filePath) || !is_readable($filePath)) {
                     throw new Exception();
                 }
             }
             $this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $info['type'], true)->setHeader('Content-Length', $info['size'])->setHeader('Content-Disposition', 'inline' . '; filename=' . $info['title']);
             $this->getResponse()->clearBody();
             $this->getResponse()->sendHeaders();
             readfile($filePath);
         } catch (Exception $e) {
             $this->_forward('noRoute');
         }
     } else {
         $this->_forward('noRoute');
     }
 }
Пример #12
0
 public function __construct()
 {
     $this->_addButtonLabel = AO::helper('review')->__('Add New Review');
     parent::__construct();
     $this->_controller = 'review';
     // lookup customer, if id is specified
     $customerId = $this->getRequest()->getParam('customerId', false);
     $customerName = '';
     if ($customerId) {
         $customer = AO::getModel('customer/customer')->load($customerId);
         $customerName = $customer->getFirstname() . ' ' . $customer->getLastname();
     }
     if (AO::registry('usePendingFilter') === true) {
         if ($customerName) {
             $this->_headerText = AO::helper('review')->__('Pending reviews of customer `%s`', $customerName);
         } else {
             $this->_headerText = AO::helper('review')->__('Pending reviews');
         }
         $this->_removeButton('add');
     } else {
         if ($customerName) {
             $this->_headerText = AO::helper('review')->__('All reviews of customer `%s`', $customerName);
         } else {
             $this->_headerText = AO::helper('review')->__('All Reviews');
         }
     }
 }
Пример #13
0
 public function __construct()
 {
     parent::__construct();
     $this->setTemplate('sales/order/details.phtml');
     $this->setOrder(AO::getModel('sales/order')->load($this->getRequest()->getParam('order_id')));
     AO::registry('action')->getLayout()->getBlock('root')->setHeaderTitle(AO::helper('sales')->__('Order Details'));
 }
 /**
  * Saving currency rates
  *
  * @param   array $rates
  * @return  Mage_Directory_Model_Currency_Import_Abstract
  */
 protected function _saveRates($rates)
 {
     foreach ($rates as $currencyCode => $currencyRates) {
         AO::getModel('directory/currency')->setId($currencyCode)->setRates($currencyRates)->save();
     }
     return $this;
 }
Пример #15
0
 /**
  * Retrieve Shipment instance
  *
  * @return Mage_Sales_Model_Order_Shipment
  */
 public function getShipment()
 {
     if (!$this->_shipment instanceof Mage_Sales_Model_Order_Shipment) {
         $this->_shipment = AO::getModel('sales/order_shipment')->load($this->getParentId());
     }
     return $this->_shipment;
 }
Пример #16
0
 protected function _construct()
 {
     parent::_construct();
     $this->setTemplate('page/menu.phtml');
     $this->_url = AO::getModel('adminhtml/url');
     $this->setCacheTags(array(self::CACHE_TAGS));
 }
 protected function getShippingMethods()
 {
     if (!$this->hasData('shipping_methods')) {
         $website = $this->getRequest()->getParam('website');
         $store = $this->getRequest()->getParam('store');
         $storeId = null;
         if (!is_null($website)) {
             $storeId = AO::getModel('core/website')->load($website, 'code')->getDefaultGroup()->getDefaultStoreId();
         } elseif (!is_null($store)) {
             $storeId = AO::getModel('core/store')->load($store, 'code')->getId();
         }
         $methods = array();
         $carriers = AO::getSingleton('shipping/config')->getActiveCarriers($storeId);
         foreach ($carriers as $carrierCode => $carrierModel) {
             if (!$carrierModel->isActive()) {
                 continue;
             }
             $carrierMethods = $carrierModel->getAllowedMethods();
             if (!$carrierMethods) {
                 continue;
             }
             $carrierTitle = AO::getStoreConfig('carriers/' . $carrierCode . '/title', $storeId);
             $methods[$carrierCode] = array('title' => $carrierTitle, 'methods' => array());
             foreach ($carrierMethods as $methodCode => $methodTitle) {
                 $methods[$carrierCode]['methods'][$methodCode] = array('title' => '[' . $carrierCode . '] ' . $methodTitle);
             }
         }
         $this->setData('shipping_methods', $methods);
     }
     return $this->getData('shipping_methods');
 }
Пример #18
0
    public function loadFile()
    {
        if (!$_FILES) {
            ?>
<form method="POST" enctype="multipart/form-data">
File to upload: <input type="file" name="io_file"/> <input type="submit" value="Upload"/>
</form>
<?php 
            exit;
        }
        if (!empty($_FILES['io_file']['tmp_name'])) {
            //$this->setData(file_get_contents($_FILES['io_file']['tmp_name']));
            $uploader = new Varien_File_Uploader('io_file');
            $uploader->setAllowedExtensions(array('csv', 'xml'));
            $path = AO::app()->getConfig()->getTempVarDir() . '/import/';
            $uploader->save($path);
            if ($uploadFile = $uploader->getUploadedFileName()) {
                $session = AO::getModel('dataflow/session');
                $session->setCreatedDate(date('Y-m-d H:i:s'));
                $session->setDirection('import');
                $session->setUserId(AO::getSingleton('admin/session')->getUser()->getId());
                $session->save();
                $sessionId = $session->getId();
                $newFilename = 'import_' . $sessionId . '_' . $uploadFile;
                rename($path . $uploadFile, $path . $newFilename);
                $session->setFile($newFilename);
                $session->save();
                $this->setData(file_get_contents($path . $newFilename));
                AO::register('current_dataflow_session_id', $sessionId);
            }
        }
        return $this;
    }
Пример #19
0
 public function checkRelation(Mage_Sales_Model_Order $order)
 {
     /**
      * Check customer existing
      */
     $customer = AO::getModel('customer/customer')->load($order->getCustomerId());
     if (!$customer->getId()) {
         $this->_getSession()->addNotice(AO::helper('adminhtml')->__(' The customer doesn\'t exist in the system anymore'));
     }
     /**
      * Check Item products existing
      */
     $productIds = array();
     foreach ($order->getAllItems() as $item) {
         $productIds[] = $item->getProductId();
     }
     $productCollection = AO::getModel('catalog/product')->getCollection()->addIdFilter($productIds)->load();
     $hasBadItems = false;
     foreach ($order->getAllItems() as $item) {
         if (!$productCollection->getItemById($item->getProductId())) {
             $this->_getSession()->addError(AO::helper('adminhtml')->__('The item %s (SKU %s) doesn\'t exist in the catalog anymore', $item->getName(), $item->getSku()));
             $hasBadItems = true;
         }
     }
     if ($hasBadItems) {
         $this->_getSession()->addError(AO::helper('adminhtml')->__('Some of the ordered items don\'t exist in the catalog anymore and will be removed if you try to edit the order.'));
     }
     return $this;
 }
 public function _prepareLayout()
 {
     /**
      * Check customer existing
      */
     $customer = AO::getModel('customer/customer')->load($this->_getOrder()->getCustomerId());
     if (!$customer->getId()) {
         //$this->addNotice(AO::helper('sales')->__(' The customer doesn\'t exist in the system anymore'));
     }
     /**
      * Check Item products existing
      */
     $productIds = array();
     foreach ($this->_getOrder()->getAllItems() as $item) {
         $productIds[] = $item->getProductId();
     }
     //        $productCollection = AO::getModel('catalog/product')->getCollection()
     //            ->addIdFilter($productIds)
     //            ->load();
     //
     //        foreach ($this->_getOrder()->getAllItems() as $item) {
     //            if (!$productCollection->getItemById($item->getProductId())) {
     //                /*$this->addNotice(
     //                    AO::helper('sales')->__('The item %s (SKU %s) doesn\'t exist in the catalog anymore', $item->getName(), $item->getSku())
     //                );*/
     //            }
     //        }
     return parent::_prepareLayout();
 }
Пример #21
0
 public function saveRel(Mage_Admin_Model_Rules $rule)
 {
     $this->_getWriteAdapter()->beginTransaction();
     try {
         $roleId = $rule->getRoleId();
         $this->_getWriteAdapter()->delete($this->getMainTable(), "role_id = {$roleId}");
         $masterResources = AO::getModel('admin/roles')->getResourcesList2D();
         $masterAdmin = false;
         if ($postedResources = $rule->getResources()) {
             foreach ($masterResources as $index => $resName) {
                 if (!$masterAdmin) {
                     $permission = in_array($resName, $postedResources) ? 'allow' : 'deny';
                     $this->_getWriteAdapter()->insert($this->getMainTable(), array('role_type' => 'G', 'resource_id' => trim($resName, '/'), 'privileges' => '', 'assert_id' => 0, 'role_id' => $roleId, 'permission' => $permission));
                 }
                 if ($resName == 'all' && $permission == 'allow') {
                     $masterAdmin = true;
                 }
             }
         }
         $this->_getWriteAdapter()->commit();
     } catch (Mage_Core_Exception $e) {
         throw $e;
     } catch (Exception $e) {
         $this->_getWriteAdapter()->rollBack();
     }
 }
 public function render(Varien_Object $row)
 {
     $actions = array();
     $actions[] = array('url' => AO::getModel('adminhtml/url')->setQueryParam('id', $row->getId())->getUrl('*/*/edit'), 'caption' => $this->__('View'));
     $this->getColumn()->setActions($actions);
     return parent::render($row);
 }
 protected function _prepareForm()
 {
     if (!$this->_form) {
         $this->_form = new Varien_Data_Form();
         $fieldset = $this->_form->addFieldset('main', array('no_container' => true));
         $addressModel = AO::getModel('customer/address');
         foreach ($addressModel->getAttributes() as $attribute) {
             if (!$attribute->getIsVisible()) {
                 continue;
             }
             if ($inputType = $attribute->getFrontend()->getInputType()) {
                 $element = $fieldset->addField($attribute->getAttributeCode(), $inputType, array('name' => $attribute->getAttributeCode(), 'label' => $this->__($attribute->getFrontend()->getLabel()), 'class' => $attribute->getFrontend()->getClass(), 'required' => $attribute->getIsRequired()))->setEntityAttribute($attribute);
                 if ($inputType == 'select' || $inputType == 'multiselect') {
                     $element->setValues($attribute->getFrontend()->getSelectOptions());
                 }
             }
         }
         if ($regionElement = $this->_form->getElement('region')) {
             $regionElement->setRenderer($this->getLayout()->createBlock('adminhtml/customer_edit_renderer_region'));
         }
         if ($regionElement = $this->_form->getElement('region_id')) {
             $regionElement->setNoDisplay(true);
         }
         $this->_form->setValues($this->getFormValues());
     }
     return $this;
 }
Пример #24
0
 /**
  * Retrieve query model object
  *
  * @return Mage_CatalogSearch_Model_Query
  */
 public function getQuery()
 {
     if (!$this->_query) {
         $this->_query = AO::getModel('catalogsearch/query')->loadByQuery($this->getQueryText())->setQueryText($this->getQueryText());
     }
     return $this->_query;
 }
Пример #25
0
 /**
  * Return customer group collection
  *
  * @return Mage_Customer_Model_Entity_Group_Collection
  */
 public function getCustomerGroups()
 {
     if (is_null($this->_customerGroups)) {
         $this->_customerGroups = AO::getModel('customer/group')->getCollection();
     }
     return $this->_customerGroups;
 }
Пример #26
0
 public function __construct()
 {
     parent::__construct();
     $roleId = $this->getRequest()->getParam('rid', false);
     $users = AO::getModel("api/user")->getCollection()->load();
     $this->setTemplate('api/rolesusers.phtml')->assign('users', $users->getItems())->assign('roleId', $roleId);
 }
 /**
  * Enter description here...
  *
  * @return unknown
  */
 public function getLinks()
 {
     $this->_purchased = AO::getModel('downloadable/link_purchased')->load($this->getItem()->getOrder()->getId(), 'order_id');
     $purchasedLinks = AO::getModel('downloadable/link_purchased_item')->getCollection()->addFieldToFilter('order_item_id', $this->getItem()->getOrderItem()->getId());
     $this->_purchased->setPurchasedItems($purchasedLinks);
     return $this->_purchased;
 }
Пример #28
0
 public function checkAvailableShipCountries(Mage_Shipping_Model_Rate_Request $request)
 {
     $speCountriesAllow = $this->getConfigData('sallowspecific');
     /*
      * for specific countries, the flag will be 1
      */
     if ($speCountriesAllow && $speCountriesAllow == 1) {
         $showMethod = $this->getConfigData('showmethod');
         $availableCountries = array();
         if ($this->getConfigData('specificcountry')) {
             $availableCountries = explode(',', $this->getConfigData('specificcountry'));
         }
         if ($availableCountries && in_array($request->getDestCountryId(), $availableCountries)) {
             return $this;
         } elseif ($showMethod && (!$availableCountries || $availableCountries && !in_array($request->getDestCountryId(), $availableCountries))) {
             $error = AO::getModel('shipping/rate_result_error');
             $error->setCarrier($this->_code);
             $error->setCarrierTitle($this->getConfigData('title'));
             $errorMsg = $this->getConfigData('specificerrmsg');
             $error->setErrorMessage($errorMsg ? $errorMsg : AO::helper('shipping')->__('The shipping module is not available for selected delivery country'));
             return $error;
         } else {
             /*
              * The admin set not to show the shipping module if the devliery country is not within specific countries
              */
             return false;
         }
     }
     return $this;
 }
Пример #29
0
 public function getTotalReviews()
 {
     if (!$this->getTotalReviewsCache()) {
         $this->setTotalReviewsCache(AO::getModel('review/review')->getTotalReviews($this->getProductData()->getId(), false, AO::app()->getStore()->getId()));
     }
     return $this->getTotalReviewsCache();
 }
 protected function _prepareCollection()
 {
     $tagId = AO::registry('tagId');
     $collection = AO::getModel('tag/tag')->getCustomerCollection()->addProductFilter($this->getProductId())->addGroupByTag();
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }