protected function _prepareCollection() { $collection = Mage::getResourceModel('reports/tag_product_collection'); $collection->addUniqueTagedCount()->addAllTagedCount()->addStatusFilter(Mage::getModel('tag/tag')->getApprovedStatus())->addGroupByProduct(); $this->setCollection($collection); return parent::_prepareCollection(); }
/** * Retrieve collection instances * * @return Mage_Sales_Model_Resource_Order_Status_History_Collection */ protected function _getCollectionForRetrieve() { /* @var $collection Mage_Sales_Model_Resource_Order_Status_History_Collection */ $collection = Mage::getResourceModel('Mage_Sales_Model_Resource_Order_Status_History_Collection'); $collection->setOrderFilter($this->_loadOrderById($this->getRequest()->getParam(self::PARAM_ORDER_ID))); return $collection; }
public function handleEventBlockAlert($observer) { $product = Mage::registry('current_product'); if ('product.info.addtocart' == $observer->getEvent()->getBlock()->getNameInLayout() && $product->getTypeId() == 'virtual') { $today = date("Y-m-d"); $mainCollection = Mage::getResourceModel('wage_trainevent/trainevent_collection')->addStoreFilter(Mage::app()->getStore())->addProductFilter($product); $firstCollection = $mainCollection->getFirstItem(); $trainEventEndDate = $firstCollection->getData('end_date'); if (strtotime($today) >= strtotime($trainEventEndDate) && $trainEventEndDate) { $isLogged = Mage::helper('customer')->isLoggedIn(); if (!$isLogged) { $transport = $observer->getEvent()->getTransport(); $alertBlock = Mage::app()->getLayout()->createBlock('wage_trainevent/trainevent_subscribe', 'event.subscribe'); $alertBlock->setTemplate('wage_trainevent/subscribe_guest.phtml'); $html = $alertBlock->toHtml(); $transport->setHtml($html); } else { $transport = $observer->getEvent()->getTransport(); $alertBlock = Mage::app()->getLayout()->createBlock('wage_trainevent/trainevent_subscribe', 'event.subscribe'); $alertBlock->setTemplate('wage_trainevent/subscribe_customer.phtml'); $alertBlock->setHtmlClass('alert-stock link-stock-alert'); $alertBlock->setSignupLabel('Sign up to get notified to get next Event Planning'); $html = $alertBlock->toHtml(); $transport->setHtml($html); } } } }
protected function _prepareCollection() { $collection = Mage::getResourceModel('googlebase/type_collection')->addItemsCount(); $this->setCollection($collection); parent::_prepareCollection(); return $this; }
public function save() { foreach ($this->getData() as $i => $row) { $this->setExceptionLocation('Line: ' . $i); $entity = Mage::getResourceModel($this->getEntity()); if (!empty($row['entity_id'])) { try { $entity->load($row['entity_id']); $this->setPosition('Line: ' . $i . (isset($row['entity_id']) ? ', entity_id: ' . $row['entity_id'] : '')); } catch (Exception $e) { $this->addException(Mage::helper('Mage_Eav_Helper_Data')->__('An error occurred while loading a record, aborting. Error: %s', $e->getMessage()), Varien_Convert_Exception::FATAL); } if (!$entity->getId()) { $this->addException(Mage::helper('Mage_Eav_Helper_Data')->__('Invalid entity_id, skipping the record.'), Varien_Convert_Exception::ERROR); continue; } } try { $entity->addData($row)->save(); } catch (Exception $e) { $this->addException(Mage::helper('Mage_Eav_Helper_Data')->__('An error occurred while saving a record, aborting. Error: ', $e->getMessage()), Varien_Convert_Exception::FATAL); } } return $this; }
/** * Retrieve billing agreements collection * * @return Mage_Sales_Model_Mysql4_Billing_Agreement_Collection */ public function getBillingAgreements() { if (is_null($this->_billingAgreements)) { $this->_billingAgreements = Mage::getResourceModel('sales/billing_agreement_collection')->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomerId())->setOrder('agreement_id', 'desc'); } return $this->_billingAgreements; }
protected function _renderCellTemplate($columnName) { $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']'; if ($columnName == "template") { $collection = Mage::getResourceModel('core/email_template_collection')->load(); $arr_select = $collection->toOptionArray(); array_unshift($arr_select, array('label' => Mage::helper('rewardpoints')->__('Default'), 'value' => '')); return $this->_getTemplateRenderer()->setName($inputName)->setTitle($columnName)->setExtraParams('style="width:260px"')->setOptions($arr_select)->toHtml(); } else { if ($columnName == "sender") { $arr_select = array(); $config = Mage::getSingleton('adminhtml/config')->getSection('trans_email')->groups->children(); foreach ($config as $node) { $nodeName = $node->getName(); $label = (string) $node->label; $sortOrder = (int) $node->sort_order; $arr_select[$sortOrder] = array('value' => preg_replace('#^ident_(.*)$#', '$1', $nodeName), 'label' => Mage::helper('adminhtml')->__($label)); } ksort($arr_select); /*array_unshift( $arr_select, array( 'label' => Mage::helper('rewardpoints')->__('Default'), 'value' => '' ) );*/ return $this->_getSenderRenderer()->setName($inputName)->setTitle($columnName)->setExtraParams('style="width:260px"')->setOptions($arr_select)->toHtml(); } } return parent::_renderCellTemplate($columnName); }
protected function _prepareForm() { $collection = Mage::getResourceModel('clmcenter/comment_collection'); $mcenter_id = $this->getRequest()->getParam('id'); $tableName = Mage::getSingleton('core/resource')->getTableName('clmcenter_mcenter'); $collection->getSelect()->joinLeft($tableName, 'main_table.mcenter_id = ' . $tableName . '.mcenter_id', 'title'); $collection->getSelect()->distinct(); $collection->getSelect()->where('main_table.mcenter_id =' . $mcenter_id); $collection->getSelect()->limit(1); $data = $collection->getData(); $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))), 'method' => 'post')); $fieldset = $form->addFieldset('comment_form', array('legend' => Mage::helper('clmcenter')->__('Комментарий'))); $fieldset->addField('title', 'hidden', array('label' => Mage::helper('clmcenter')->__('Наименование'), 'after_element_html' => '<tr><td class="label"><label for="title">Наименование</label></td> <td class="value">' . $data[0]['title'] . '</td></tr>')); $fieldset->addField('user', 'text', array('label' => Mage::helper('clmcenter')->__('Пользователь'), 'name' => 'user')); $fieldset->addField('email', 'text', array('label' => Mage::helper('clmcenter')->__('E-mail'), 'name' => 'email')); $fieldset->addField('comment_status', 'select', array('label' => Mage::helper('clmcenter')->__('Статус'), 'name' => 'comment_status', 'values' => array(array('value' => CommerceLab_Mcenter_Helper_Data::UNAPPROVED_STATUS, 'label' => Mage::helper('clmcenter')->__('Отклонен')), array('value' => CommerceLab_Mcenter_Helper_Data::APPROVED_STATUS, 'label' => Mage::helper('clmcenter')->__('Одобрен'))))); $fieldset->addField('comment', 'editor', array('name' => 'comment', 'label' => Mage::helper('clmcenter')->__('Комментарий'), 'title' => Mage::helper('clmcenter')->__('Комментарий'), 'style' => 'width:500px; height:250px;', 'wysiwyg' => false, 'required' => false)); if (Mage::getSingleton('adminhtml/session')->getMcenterData()) { $form->setValues(Mage::getSingleton('adminhtml/session')->getMcenterData()); Mage::getSingleton('adminhtml/session')->setMcenterData(null); } elseif (Mage::registry('clmcenter_data')) { $form->setValues(Mage::registry('clmcenter_data')->getData()); } $form->setUseContainer(true); $this->setForm($form); return parent::_prepareForm(); }
/** * Retrieve collection instances * * @return Mage_Sales_Model_Resource_Order_Address_Collection */ protected function _getCollectionForRetrieve() { /* @var $collection Mage_Sales_Model_Resource_Order_Address_Collection */ $collection = Mage::getResourceModel('sales/order_address_collection'); $collection->addAttributeToFilter('parent_id', $this->getRequest()->getParam(self::PARAM_ORDER_ID)); return $collection; }
public function getOptionText($value) { if (!$value) { $value = '0'; } $isMultiple = false; if (strpos($value, ',')) { $isMultiple = true; $value = explode(',', $value); } if (!$this->_options) { $collection = Mage::getResourceModel('core/store_collection'); if ('store_id' == $this->getAttribute()->getAttributeCode()) { $collection->setWithoutDefaultFilter(); } $this->_options = $collection->load()->toOptionArray(); if ('created_in' == $this->getAttribute()->getAttributeCode()) { array_unshift($this->_options, array('value' => '0', 'label' => Mage::helper('customer')->__('Admin'))); } } if ($isMultiple) { $values = array(); foreach ($value as $val) { $values[] = $this->_options[$val]; } return $values; } else { return $this->_options[$value]; } return false; }
/** * Get collection from commission table * * Return array of data to with seller commission information * * @return array */ protected function _prepareCollection() { $gid = Mage::helper('marketplace')->getGroupId(); $collection = Mage::getResourceModel('customer/customer_collection')->addNameToSelect()->addAttributeToSelect('email')->addAttributeToSelect('created_at')->addAttributeToSelect('group_id')->addFieldToFilter('group_id', $gid); $this->setCollection($collection); return parent::_prepareCollection(); }
public function getAllOptions() { if (!$this->_options) { $this->_options = Mage::getResourceModel('tax/class_collection')->addFieldToFilter('class_type', 'CUSTOMER')->load()->toOptionArray(); } return $this->_options; }
protected function _prepareLayout() { if (!Mage::helper('core')->isModuleEnabled('Mage_Reports')) { return $this; } $isFilter = $this->getRequest()->getParam('store') || $this->getRequest()->getParam('website') || $this->getRequest()->getParam('group'); $collection = Mage::getResourceModel('reports/order_collection')->calculateSales($isFilter); if ($this->getRequest()->getParam('store')) { $collection->addFieldToFilter('store_id', $this->getRequest()->getParam('store')); } else { if ($this->getRequest()->getParam('website')) { $storeIds = Mage::app()->getWebsite($this->getRequest()->getParam('website'))->getStoreIds(); $collection->addFieldToFilter('store_id', array('in' => $storeIds)); } else { if ($this->getRequest()->getParam('group')) { $storeIds = Mage::app()->getGroup($this->getRequest()->getParam('group'))->getStoreIds(); $collection->addFieldToFilter('store_id', array('in' => $storeIds)); } } } $collection->load(); $sales = $collection->getFirstItem(); $this->addTotal($this->__('Lifetime Sales'), $sales->getLifetime()); $this->addTotal($this->__('Average Orders'), $sales->getAverage()); }
/** * Check is block with such type allowed for parsinf via blockDirective method * * @param $type * @return int */ public function isTypeAllowed($type) { /** @var Mage_Admin_Model_Resource_Block_Collection $collection */ $collection = Mage::getResourceModel('admin/block_collection'); $collection->addFieldToFilter('block_name', array('eq' => $type))->addFieldToFilter('is_allowed', array('eq' => 1)); return $collection->load()->count(); }
public function __construct() { parent::__construct(); //TODO: add full name logic $orders = Mage::getResourceModel('sales/order_collection')->addAttributeToSelect('*')->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')->addAttributeToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())->addAttributeToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))->addAttributeToSort('created_at', 'desc')->setPageSize('5')->load(); $this->setOrders($orders); }
public function toOptionArray() { if (!$this->_options) { $this->_options = Mage::getResourceModel('core/store_collection')->load()->toOptionArray(); } return $this->_options; }
protected function _prepareCollection() { $collection = Mage::getResourceModel('api/role_collection'); $collection->setRolesFilter(); $this->setCollection($collection); return parent::_prepareCollection(); }
protected function _prepareCollection() { //TODO: add full name logic $collection = Mage::getResourceModel('sales/order_collection')->addAttributeToSelect('increment_id')->addAttributeToSelect('created_at')->addAttributeToSelect('grand_total')->addAttributeToSelect('order_currency_code')->addAttributeToSelect('store_id')->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')->addExpressionAttributeToSelect('billing_name', 'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})', array('billing_firstname', 'billing_lastname'))->addExpressionAttributeToSelect('shipping_name', 'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})', array('shipping_firstname', 'shipping_lastname'))->addAttributeToFilter('customer_id', Mage::registry('current_customer')->getEntityId()); $this->setCollection($collection); return parent::_prepareCollection(); }
public function getAllOptions() { $name = 'brends'; $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem(); $attributes = Mage::getResourceModel('eav/entity_attribute_collection')->getData(); $result = array(); foreach ($attributes as $attr) { if ($attr['source_model'] == 'eav/entity_attribute_source_table') { $result[] = $attr; } } $this->_options = array(); $this->_options['0'] = array('label' => '', 'value' => ''); foreach ($result as $res) { $this->_options[] = array('label' => $res['frontend_label'], 'value' => $res['attribute_code']); } return $this->_options; $attributeId = $attributeInfo->getAttributeId(); $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId); $attributeOptions = $attribute->getSource()->getAllOptions(false); return $attributeOptions; if (is_null($this->_options)) { $this->_options = array(array('label' => 'adsf', 'value' => self::MAIN), array('label' => 'asdf1', 'value' => self::OTHER)); } return $this->_options; }
/** * Retreive all region options * * @return array */ public function getAllOptions() { if (!$this->_options) { $this->_options = Mage::getResourceModel('directory/region_collection')->load()->toOptionArray(); } return $this->_options; }
public function getAttributes() { $collection = Mage::getResourceModel('catalog/product_attribute_collection'); $collection->addIsSearchableFilter(); $collection->addFieldToFilter('backend_type', array('varchar', 'text')); return $collection; }
/** * Aggregate Orders data * * @param mixed $from * @param mixed $to * @return Mage_Sales_Model_Resource_Report_Order */ public function aggregate($from = null, $to = null) { Mage::getResourceModel('sales/report_order_createdat')->aggregate($from, $to); Mage::getResourceModel('sales/report_order_updatedat')->aggregate($from, $to); $this->_setFlagData(Mage_Reports_Model_Flag::REPORT_ORDER_FLAG_CODE); return $this; }
/** * Initialize custom resource model */ public function __construct() { parent::_construct(); $this->setModel('adminhtml/report_item'); $this->_resource = Mage::getResourceModel('advancedreports/salesbyhour')->init('advancedreports/salesbyhour'); $this->setConnection($this->getResource()->getReadConnection()); }
protected function _prepareCollection() { //TODO: add full name logic $collection = Mage::getResourceModel('reports/customer_collection')->addAttributeToSelect('firstname')->addAttributeToSelect('lastname'); $this->setCollection($collection); return parent::_prepareCollection(); }
/** * Prepare related orders collection * * @return Mage_Adminhtml_Block_Widget_Grid */ protected function _prepareCollection() { $collection = Mage::getResourceModel('Mage_Sales_Model_Resource_Order_Grid_Collection'); $collection->addBillingAgreementsFilter(Mage::registry('current_billing_agreement')->getId()); $this->setCollection($collection); return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection(); }
/** * Load terms and try to sort it by names * * @return Mage_CatalogSearch_Block_Term */ protected function _loadTerms() { if (empty($this->_terms)) { $this->_terms = array(); $terms = Mage::getResourceModel('catalogsearch/query_collection')->setPopularQueryFilter(Mage::app()->getStore()->getId())->setPageSize(100)->load()->getItems(); if (count($terms) == 0) { return $this; } $this->_maxPopularity = reset($terms)->getPopularity(); $this->_minPopularity = end($terms)->getPopularity(); $range = $this->_maxPopularity - $this->_minPopularity; $range = $range == 0 ? 1 : $range; foreach ($terms as $term) { if (!$term->getPopularity()) { continue; } $term->setRatio(($term->getPopularity() - $this->_minPopularity) / $range); $temp[$term->getName()] = $term; $termKeys[] = $term->getName(); } natcasesort($termKeys); foreach ($termKeys as $termKey) { $this->_terms[$termKey] = $temp[$termKey]; } } return $this; }
/** * Get config resource model * * @return Mage_Searchanise_Store_Mysql4_Config */ public function getResourceModel() { if (is_null($this->_resourceModel)) { $this->_resourceModel = Mage::getResourceModel('searchanise/config'); } return $this->_resourceModel; }
protected function _toHtml() { $rssObj = Mage::getModel('rss/rss'); $order = Mage::registry('current_order'); $title = Mage::helper('rss')->__('Order # %s Notification(s)', $order->getIncrementId()); $newurl = Mage::getUrl('sales/order/view', array('order_id' => $order->getId())); $data = array('title' => $title, 'description' => $title, 'link' => $newurl, 'charset' => 'UTF-8'); $rssObj->_addHeader($data); $resourceModel = Mage::getResourceModel('rss/order'); $results = $resourceModel->getAllCommentCollection($order->getId()); if ($results) { foreach ($results as $result) { $urlAppend = 'view'; $type = $result['entity_type_code']; if ($type && $type != 'order') { $urlAppend = $type; } $type = Mage::helper('rss')->__(ucwords($type)); $title = Mage::helper('rss')->__('Details for %s #%s', $type, $result['increment_id']); $description = '<p>' . Mage::helper('rss')->__('Notified Date: %s<br/>', $this->formatDate($result['created_at'])) . Mage::helper('rss')->__('Comment: %s<br/>', $result['comment']) . '</p>'; $url = Mage::getUrl('sales/order/' . $urlAppend, array('order_id' => $order->getId())); $data = array('title' => $title, 'link' => $url, 'description' => $description); $rssObj->_addEntry($data); } } $title = Mage::helper('rss')->__('Order #%s created at %s', $order->getIncrementId(), $this->formatDate($order->getCreatedAt())); $url = Mage::getUrl('sales/order/view', array('order_id' => $order->getId())); $description = '<p>' . Mage::helper('rss')->__('Current Status: %s<br/>', $order->getStatusLabel()) . Mage::helper('rss')->__('Total: %s<br/>', $order->formatPrice($order->getGrandTotal())) . '</p>'; $data = array('title' => $title, 'link' => $url, 'description' => $description); $rssObj->_addEntry($data); return $rssObj->createRssXml(); }
/** * Initialize custom resource model */ public function __construct() { parent::_construct(); $this->setModel('adminhtml/report_item'); $this->_resource = Mage::getResourceModel('sales/report')->init('sales/order_aggregated_created'); $this->setConnection($this->getResource()->getReadConnection()); }
public function getProductCollectionInitial() { /* $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId(100000005); echo "<pre>"; print_r($invoice->getData()); $invoice->capture()->save(); echo "<pre>"; print_r($invoice->getData()); exit; */ /* $prod = Mage::getModel('catalog/product')->load(198); echo "<pre>"; print_r($prod->getStoreIds()); exit; */ $storeId = Mage::app()->getStore()->getId(); $visibility = array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG); $products = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*')->addOrderedQty()->addAttributeToFilter('visibility', $visibility); //->setOrder('ordered_qty', 'desc'); $pageSize = Mage::helper('bestsellingproduct')->getBestsellingNoProduct(); //$products = Mage::getModel('sales/order')->getCollection(); $filters = Mage::helper('bestsellingproduct')->getBestsellingFilters(); if ($filters == 1) { $products->setOrder('ordered_qty', 'asc'); } else { if ($filters == 2) { $products->setOrder('ordered_qty', 'desc'); } else { if ($filters == 3) { $products->getSelect()->order('rand()'); } else { $products->setOrder('ordered_qty', 'desc'); } } } $products->setPageSize($pageSize); /* if(Mage::registry('current_category')) { $products = Mage::getResourceModel('reports/product_collection') ->addOrderedQty() ->addAttributeToSelect('*') //->addAttributeToSelect(array('name', 'price', 'small_image', 'short_description', 'description')) //edit to suit tastes ->setStoreId($storeId) ->addStoreFilter($storeId) ->addAttributeToFilter('status','1') //->addAttributeToFilter(array(array('attribute'=>'visibility', 'neq'=>1))) ->addCategoryFilter(Mage::registry('current_category')) ->setOrder('ordered_qty', 'desc'); //->setPageSize(20); //best sellers on top } else { $products = Mage::getResourceModel('reports/product_collection') ->addOrderedQty() ->addAttributeToSelect('*') //->addAttributeToSelect(array('name', 'price', 'small_image', 'short_description', 'description')) //edit to suit tastes ->setStoreId($storeId) ->addStoreFilter($storeId) ->addAttributeToFilter('status','1') //->addAttributeToFilter(array(array('attribute'=>'visibility', 'neq'=>1))) ->setOrder('ordered_qty', 'desc'); //->setPageSize(20); //best sellers on top } */ //echo '123'.count($products); //die('here'); // Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products); // Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products); return $products; }