/**
  * Test default accessors for basic Magento components.
  */
 public function test_defaults()
 {
     $helper = Praxigento_Quickorder_Config::helper();
     $this->assertTrue($helper instanceof Mage_Core_Helper_Abstract);
     $rsrc = Praxigento_Quickorder_Config::getResourceSuggestion();
     $this->assertTrue($rsrc instanceof Praxigento_Quickorder_Model_Mysql4_Suggestion);
 }
 public function toOptionArray()
 {
     if (!is_null($this->_order)) {
         return $this->_order;
     }
     $this->_order[] = array('label' => Praxigento_Quickorder_Config::helper()->__('Ascending ↑'), 'value' => self::ASC);
     $this->_order[] = array('label' => Praxigento_Quickorder_Config::helper()->__('Descending ↓'), 'value' => self::DESC);
     /** sorted by key: ASC / DESC, cause of default value is ASC (see SysConf w/o data) */
     ksort($this->_order);
     return $this->_order;
 }
示例#3
0
 public function canSeeQuickOrderForm()
 {
     $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
     $allowedGroupIds = Praxigento_Quickorder_Config::cfgCustomerGroupsAllowed();
     if (count($allowedGroupIds) == 0) {
         /** QOF-15 there is no configiration setup yet - enable all groups*/
         $result = true;
     } else {
         $result = in_array($groupId, $allowedGroupIds);
     }
     return $result;
 }
 public function modifyBlockForm(Varien_Event_Observer $observer)
 {
     $block = $observer->getEvent()->getBlock();
     if ($block instanceof Mage_Adminhtml_Block_Customer_Group_Edit_Form) {
         if (Mage::getSingleton('adminhtml/session')->getCustomerGroupData()) {
             $values = Mage::getSingleton('adminhtml/session')->getCustomerGroupData();
         } else {
             $values = Mage::registry('current_group')->getData();
         }
         $form = $block->getForm();
         $fieldset = $form->getElement('base_fieldset');
         $fieldset->addField('can_see_quick_order_form', 'select', array('name' => 'can_see_quick_order_form', 'label' => Praxigento_Quickorder_Config::helper()->__('Can see Quick Order Form'), 'title' => Praxigento_Quickorder_Config::helper()->__('Can see Quick Order Form'), 'class' => 'required-entry', 'required' => true, 'values' => Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray(), 'value' => $values['can_see_quick_order_form']), "access");
     }
 }
 /**
  * Retrieve customer groups as array
  *
  * @return array
  */
 public function toOptionArray()
 {
     if (!$this->_options) {
         $data_arr = Mage::getResourceModel('customer/group_collection')->loadData()->toOptionArray();
         // sort by name
         foreach ($data_arr as $entry) {
             $this->_options[$entry['label']] = $entry;
         }
         /** QOF-15 */
         $allDisallowed['label'] = Praxigento_Quickorder_Config::helper()->__('-- NONE --');
         $allDisallowed['value'] = '-1';
         $this->_options[$allDisallowed['label']] = $allDisallowed;
         ksort($this->_options);
     }
     return $this->_options;
 }
 /**
  * Collect products according to configuration parameters and query from the QOF.
  *
  * @return Mage_Catalog_Model_Resource_Product_Collection
  */
 public function getProductCollection()
 {
     /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */
     $collection = Mage::getModel('catalog/product')->getResourceCollection()->addAttributeToSelect('*')->addMinimalPrice()->addFinalPrice()->addTaxPercents();
     /** Setup filter by product visibility */
     if (!Praxigento_Quickorder_Config::cfgInvisibleIncluded()) {
         /** @var $prodVisible Mage_Catalog_Model_Product_Visibility */
         $prodVisible = Mage::getSingleton('catalog/product_visibility');
         $collection->setVisibility($prodVisible->getVisibleInSiteIds());
     }
     /** Setup filter by product type */
     /** complex prods need a Ajax panel to configire options pn-the-fly */
     //        if (!Praxigento_Quickorder_Config::cfgComplexProdsIncluded()) {
     /** exclude configurable, grouped, bundled products and any custom types */
     $collection->addAttributeToFilter('type_id', array('in', array('simple', 'virtual', 'downloadable')));
     //        }
     /** filter products by customer's query */
     $conditions = array();
     foreach ($this->_filters as $filter) {
         $conditions[] = array('attribute' => $filter, 'like' => "%{$this->_query}%");
     }
     $collection->addAttributeToFilter($conditions);
     /** sort result set */
     $attr = Praxigento_Quickorder_Config::cfgSortAttr();
     $order = Praxigento_Quickorder_Config::cfgSortOrder();
     $collection->addAttributeToSort($attr, $order);
     /** remove out of stock items in case of Magento is configured to show items but QOF - to hide */
     if (Mage::helper('cataloginventory')->isShowOutOfStock() && !Praxigento_Quickorder_Config::cfgOutOfStockEnabled()) {
         /** @var $item Mage_Catalog_Model_Product */
         foreach ($collection as $key => $item) {
             $inventory = $item->getStockItem();
             if (!$inventory->getData('is_in_stock')) {
                 $collection->removeItemByKey($key);
             }
         }
     }
     return $collection;
 }
示例#7
0
 protected function _toHtml()
 {
     return Praxigento_Quickorder_Config::helper()->canSeeQuickOrderForm() ? parent::_toHtml() : '';
 }
 /**
  * Create suggestion according to customer's query.
  */
 public function suggestionAction()
 {
     $this->loadLayout();
     // parse request params and select products to suggestion
     $formQuery = $this->getRequest()->getParam(Praxigento_Quickorder_Config::REQ_PARAM_QUERY);
     $collection = null;
     if ($formQuery) {
         $model = Praxigento_Quickorder_Config::getResourceSuggestion()->setQuery($formQuery);
         $collection = $model->getProductCollection();
     }
     // prepare block to display
     $block = $this->getLayout()->getBlock(Praxigento_Quickorder_Config::UI_BLOCK_SUGGESTION);
     $block->setProductCollection($collection);
     $block->setData(Praxigento_Quickorder_Config::REQ_PARAM_QUERY, $formQuery);
     $block->setTemplate(Praxigento_Quickorder_Config::UI_TMPL_SUGGESTION);
     //
     $this->renderLayout();
 }