本文整理汇总了PHP中Mage::getResourceSingleton方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage::getResourceSingleton方法的具体用法?PHP Mage::getResourceSingleton怎么用?PHP Mage::getResourceSingleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage
的用法示例。
在下文中一共展示了Mage::getResourceSingleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: joinCustomers
public function joinCustomers()
{
$customer = Mage::getResourceSingleton('customer/customer');
//TODO: add full name logic
$firstnameAttr = $customer->getAttribute('firstname');
$firstnameAttrId = $firstnameAttr->getAttributeId();
$firstnameTable = $firstnameAttr->getBackend()->getTable();
if ($firstnameAttr->getBackend()->isStatic()) {
$firstnameField = 'firstname';
$attrCondition = '';
} else {
$firstnameField = 'value';
$attrCondition = ' AND _table_customer_firstname.attribute_id = ' . $firstnameAttrId;
}
$this->getSelect()->joinInner(array('_table_customer_firstname' => $firstnameTable), '_table_customer_firstname.entity_id=detail.customer_id' . $attrCondition, array());
$lastnameAttr = $customer->getAttribute('lastname');
$lastnameAttrId = $lastnameAttr->getAttributeId();
$lastnameTable = $lastnameAttr->getBackend()->getTable();
if ($lastnameAttr->getBackend()->isStatic()) {
$lastnameField = 'lastname';
$attrCondition = '';
} else {
$lastnameField = 'value';
$attrCondition = ' AND _table_customer_lastname.attribute_id = ' . $lastnameAttrId;
}
$this->getSelect()->joinInner(array('_table_customer_lastname' => $lastnameTable), '_table_customer_lastname.entity_id=detail.customer_id' . $attrCondition, array())->columns(array('customer_name' => "CONCAT(_table_customer_firstname.{$firstnameField}, ' ', _table_customer_lastname.{$lastnameField})", 'review_cnt' => "COUNT(main_table.review_id)"))->group('detail.customer_id');
return $this;
}
示例2: _prepareForm
/**
* Preparation of current form
*
* @return Inic_Faq_Block_Admin_Edit_Tab_Main Self
*/
protected function _prepareForm()
{
$model = Mage::registry('faq');
$form = new Varien_Data_Form();
$form->setHtmlIdPrefix('faq_');
$fieldset = $form->addFieldset('base_fieldset', array('legend' => Mage::helper('faq')->__('General information'), 'class' => 'fieldset-wide'));
if ($model->getFaqId()) {
$fieldset->addField('faq_id', 'hidden', array('name' => 'faq_id'));
}
$approveInfo = $fieldset->addField('question', 'text', array('name' => 'question', 'label' => Mage::helper('faq')->__('FAQ item question'), 'title' => Mage::helper('faq')->__('FAQ item question'), 'required' => true));
/**
* Check is single store mode
*/
if (!Mage::app()->isSingleStoreMode()) {
$store_id = $fieldset->addField('store_id', 'multiselect', array('name' => 'store_id[]', 'label' => Mage::helper('faq')->__('Store view'), 'title' => Mage::helper('faq')->__('Store view'), 'required' => true, 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true)));
} else {
$store_id = $fieldset->addField('store_id', 'hidden', array('name' => 'store_id[]', 'value' => Mage::app()->getStore(true)->getId()));
$model->setStoreId(Mage::app()->getStore(true)->getId());
}
$status = $fieldset->addField('is_active', 'select', array('label' => Mage::helper('faq')->__('Status'), 'title' => Mage::helper('faq')->__('Item status'), 'name' => 'is_active', 'required' => true, 'options' => array('1' => Mage::helper('faq')->__('Enabled'), '0' => Mage::helper('faq')->__('Disabled'))));
$fieldset->addField('is_most_frequent', 'select', array('label' => Mage::helper('faq')->__('Is Most Frequent'), 'title' => Mage::helper('faq')->__('Is Most Frequent'), 'name' => 'is_most_frequent', 'required' => true, 'options' => array('1' => Mage::helper('faq')->__('Yes'), '0' => Mage::helper('faq')->__('No'))));
$category_id = $fieldset->addField('category_id', 'multiselect', array('label' => Mage::helper('faq')->__('Category'), 'title' => Mage::helper('faq')->__('Category'), 'name' => 'category_id[]', 'required' => false, 'values' => Mage::getResourceSingleton('faq/category_collection')->toOptionArray()));
$fieldset->addField('answer', 'editor', array('name' => 'answer', 'label' => Mage::helper('faq')->__('Content'), 'title' => Mage::helper('faq')->__('Content'), 'style' => 'height:36em;', 'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(), 'state' => 'html', 'required' => true));
$data = $model->getData();
if (!count($data)) {
$data['store_id'] = 0;
}
$form->setValues($data);
$this->setForm($form);
$cat_id = $model->getData('category_id');
$selected = $cat_id ? $cat_id : "";
$this->setChild('form_after', $this->getLayout()->createBlock('faq/adminhtml_widget_form_element_selectdependence')->addFieldMap($store_id->getHtmlId(), $category_id->getHtmlId(), $selected));
return parent::_prepareForm();
}
示例3: prepareItemUrls
/**
* Prepare cart items URLs
*
* @deprecated after 1.7.0.2
*/
public function prepareItemUrls()
{
$products = array();
/* @var $item Mage_Sales_Model_Quote_Item */
foreach ($this->getItems() as $item) {
$product = $item->getProduct();
$option = $item->getOptionByCode('product_type');
if ($option) {
$product = $option->getProduct();
}
if ($item->getStoreId() != Mage::app()->getStore()->getId() && !$item->getRedirectUrl() && !$product->isVisibleInSiteVisibility()) {
$products[$product->getId()] = $item->getStoreId();
}
}
if ($products) {
$products = Mage::getResourceSingleton('catalog/url')->getRewriteByProductStore($products);
foreach ($this->getItems() as $item) {
$product = $item->getProduct();
$option = $item->getOptionByCode('product_type');
if ($option) {
$product = $option->getProduct();
}
if (isset($products[$product->getId()])) {
$object = new Varien_Object($products[$product->getId()]);
$item->getProduct()->setUrlDataObject($object);
}
}
}
}
示例4: _prepareData
protected function _prepareData()
{
$product = Mage::registry('product');
/* @var $product Mage_Catalog_Model_Product */
$this->_itemCollection = $product->getUpSellProductCollection()->setPositionOrder()->addStoreFilter();
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection, Mage::getSingleton('checkout/session')->getQuoteId());
$this->_addProductAttributesAndPrices($this->_itemCollection);
}
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection);
// Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection);
if ($this->getItemLimit('upsell') > 0) {
$this->_itemCollection->setPageSize($this->getItemLimit('upsell'));
}
if ($this->getData('show_bundles')) {
$this->_itemCollection->addAttributeToFilter('type_id', array('eq' => 'bundle'));
// /* Updating collection with desired items */
// Mage::dispatchEvent('catalog_product_upsell', array(
// 'product' => $product,
// 'collection' => $this->_itemCollection,
// 'limit' => $this->getItemLimit()
// ));
} else {
$this->_itemCollection->addAttributeToFilter('type_id', array('neq' => 'bundle'));
}
$this->_itemCollection->load();
foreach ($this->_itemCollection as $product) {
$product->setDoNotUseCategoryId(true);
}
return $this;
}
示例5: afterSave
public function afterSave($object)
{
$generalStoreId = $object->getStoreId();
$periods = $object->getData($this->getAttribute()->getName());
Mage::getResourceSingleton('payperrentals/reservationprices')->deleteByEntityId($object->getId(), $generalStoreId);
if (is_null($periods)) {
return $this;
}
if (is_array($periods)) {
foreach ($periods as $k => $period) {
if (!is_numeric($k)) {
continue;
}
if (array_key_exists('use_default_value', $period) && $period['use_default_value']) {
$storeId = $generalStoreId;
$checkCollection = Mage::getModel('payperrentals/reservationprices')->getCollection()->addFieldToFilter('entity_id', $object->getId())->addFieldToFilter('store_id', $storeId)->addFieldToFilter('numberof', $period['numberof'])->addFieldToFilter('ptype', $period['ptype'])->addFieldToFilter('price', $period['price'])->addFieldToFilter('reservationpricesdates_id', $period['reservationpricesdates_id'])->addFieldToFilter('qty_start', $period['qtystart'])->addFieldToFilter('qty_end', $period['qtyend'])->addFieldToFilter('customers_group', $period['custgroup'])->addFieldToFilter('ptypeadditional', $period['priceadditional'])->addFieldToFilter('ptypeadditional', $period['ptypeadditional'])->addFieldToFilter('damage_waiver', $period['damage_waiver']);
if (count($checkCollection)) {
continue;
}
} else {
$storeId = $generalStoreId;
}
$myRes = Mage::getModel('payperrentals/reservationprices')->setEntityId($object->getId())->setStoreId($storeId)->setNumberof($period['numberof'])->setPtype($period['ptype'])->setPrice($period['price'])->setQtyStart($period['qtystart'])->setQtyEnd($period['qtyend'])->setCustomersGroup($period['custgroup'])->setPtypeadditional($period['ptypeadditional'])->setPriceadditional($period['priceadditional'])->setReservationpricesdatesId($period['reservationpricesdates_id']);
$myRes->save();
}
} elseif ($object->getIsDuplicate() == true) {
$priceCollection = Mage::getModel('payperrentals/reservationprices')->getCollection()->addFieldToFilter('entity_id', $object->getOriginalId());
foreach ($priceCollection as $priceItem) {
$priceItem->setId(null)->setEntityId($object->getId())->save();
}
}
return $this;
}
示例6: joinCustomers
/**
* Join customers
*
* @return Mage_Reports_Model_Resource_Review_Customer_Collection
*/
public function joinCustomers()
{
/**
* Allow to use analytic function to result select
*/
$this->_useAnalyticFunction = true;
/** @var $adapter Varien_Db_Adapter_Interface */
$adapter = $this->getConnection();
/** @var $customer Mage_Customer_Model_Resource_Customer */
$customer = Mage::getResourceSingleton('customer/customer');
/** @var $firstnameAttr Mage_Eav_Model_Entity_Attribute */
$firstnameAttr = $customer->getAttribute('firstname');
/** @var $lastnameAttr Mage_Eav_Model_Entity_Attribute */
$lastnameAttr = $customer->getAttribute('lastname');
$firstnameCondition = array('table_customer_firstname.entity_id = detail.customer_id');
if ($firstnameAttr->getBackend()->isStatic()) {
$firstnameField = 'firstname';
} else {
$firstnameField = 'value';
$firstnameCondition[] = $adapter->quoteInto('table_customer_firstname.attribute_id = ?', (int) $firstnameAttr->getAttributeId());
}
$this->getSelect()->joinInner(array('table_customer_firstname' => $firstnameAttr->getBackend()->getTable()), implode(' AND ', $firstnameCondition), array());
$lastnameCondition = array('table_customer_lastname.entity_id = detail.customer_id');
if ($lastnameAttr->getBackend()->isStatic()) {
$lastnameField = 'lastname';
} else {
$lastnameField = 'value';
$lastnameCondition[] = $adapter->quoteInto('table_customer_lastname.attribute_id = ?', (int) $lastnameAttr->getAttributeId());
}
//Prepare fullname field result
$customerFullname = $adapter->getConcatSql(array("table_customer_firstname.{$firstnameField}", "table_customer_lastname.{$lastnameField}"), ' ');
$this->getSelect()->reset(Zend_Db_Select::COLUMNS)->joinInner(array('table_customer_lastname' => $lastnameAttr->getBackend()->getTable()), implode(' AND ', $lastnameCondition), array())->columns(array('customer_id' => 'detail.customer_id', 'customer_name' => $customerFullname, 'review_cnt' => 'COUNT(main_table.review_id)'))->group('detail.customer_id');
return $this;
}
示例7: getResource
public function getResource()
{
if (!$this->_resource) {
$this->_resource = Mage::getResourceSingleton('catalog_entity/convert');
}
return $this->_resource;
}
示例8: _prepareData
protected function _prepareData()
{
// Default back to core functionality
if (!Mage::helper('predictions')->canOverrideRelatedProducts()) {
return parent::_prepareData();
}
/* Retrieve related product ids here. */
$predictionHelper = Mage::helper('predictions');
$cookieId = array($predictionHelper->getCurrentUserUniqueId());
$customer = Mage::getSingleton('customer/session');
if ($customer->isLoggedIn()) {
$cookieId[] = $customer->getId();
}
$recommendationCollection = Mage::getModel('predictions/recommendation')->getCollection()->addFieldToFilter('cookie_id', array('in' => $cookieId));
// [todo] - Add a collection limit thorugh configuration
// [todo] - Remove when refactored to single id
// if (Mage::getSingleton('customer/session')->isLoggedIn()) {
// $customerData = Mage::getSingleton('customer/session')->getCustomer();
// $recommendationCollection->addFieldToFilter('customer_id', array('eq' => $customerData->getId()));
// }
$predictionioIds = $recommendationCollection->getColumnValues('product_id');
// [review] - Review the logic for loading the product collection for this block
$this->_itemCollection = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' => $predictionioIds))->addAttributeToSelect('required_options')->addStoreFilter();
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection, Mage::getSingleton('checkout/session')->getQuoteId());
$this->_addProductAttributesAndPrices($this->_itemCollection);
}
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection);
$this->_itemCollection->load();
foreach ($this->_itemCollection as $product) {
$product->setDoNotUseCategoryId(true);
}
return $this;
}
示例9: _getCollection
protected function _getCollection()
{
if (is_null($this->_resourceModel)) {
$this->_resourceModel = Mage::getResourceSingleton($this->_resourceClass);
}
return $this->_resourceModel;
}
示例10: getTreeModelInstance
/**
* Enter description here...
*
* @return EM_Blog_Model_Resource_Category_Tree
*/
public function getTreeModelInstance()
{
if (is_null($this->_treeModel)) {
$this->_treeModel = Mage::getResourceSingleton('blog/category_tree');
}
return $this->_treeModel;
}
示例11: saveProducts
/**
* Save configurable product relations
*
* @param Mage_Catalog_Model_Product|int $mainProduct the parent id
* @param array $productIds the children id array
* @return Mage_Catalog_Model_Resource_Product_Type_Configurable
*/
public function saveProducts($mainProduct, $productIds)
{
$isProductInstance = false;
if ($mainProduct instanceof Mage_Catalog_Model_Product) {
$mainProductId = $mainProduct->getId();
$isProductInstance = true;
} else {
$mainProductId = $mainProduct;
}
$old = $mainProduct->getTypeInstance()->getUsedProductIds();
$insert = array_diff($productIds, $old);
$delete = array_diff($old, $productIds);
if ((!empty($insert) || !empty($delete)) && $isProductInstance) {
$mainProduct->setIsRelationsChanged(true);
}
if (!empty($delete)) {
$where = array('parent_id = ?' => $mainProductId, 'product_id IN(?)' => $delete);
$this->_getWriteAdapter()->delete($this->getMainTable(), $where);
}
if (!empty($insert)) {
$data = array();
foreach ($insert as $childId) {
$data[] = array('product_id' => (int) $childId, 'parent_id' => (int) $mainProductId);
}
$this->_getWriteAdapter()->insertMultiple($this->getMainTable(), $data);
}
// configurable product relations should be added to relation table
Mage::getResourceSingleton('catalog/product_relation')->processRelations($mainProductId, $productIds);
return $this;
}
示例12: _prepareForm
/**
* Prepare main form
*
* @return MatheusGontijo_EasyShippingRules_Block_Adminhtml_Easyshippingrules_Custommethod_Edit_Tab_Main
*/
protected function _prepareForm()
{
$model = Mage::registry('current_easyshippingrules_custom_method');
$form = new Varien_Data_Form();
$form->setHtmlIdPrefix('custom_method_');
$form->setFieldNameSuffix('custom_method');
$fieldset = $form->addFieldset('base_fieldset', array('legend' => $this->__('General Information')));
if ($model->getId()) {
$fieldset->addField('easyshippingrules_custom_method_id', 'hidden', array('name' => 'easyshippingrules_custom_method_id'));
}
$carrierValues = Mage::getResourceSingleton('easyshippingrules/carrier_collection')->toOptionArray();
array_unshift($carrierValues, array('label' => '', 'value' => ''));
$fieldset->addField('easyshippingrules_carrier_id', 'select', array('name' => 'easyshippingrules_carrier_id', 'label' => $this->__('Carrier'), 'title' => $this->__('Carrier'), 'values' => $carrierValues));
$fieldset->addField('name', 'text', array('name' => 'name', 'label' => $this->__('Name'), 'title' => $this->__('Name'), 'required' => true));
$fieldset->addField('is_active', 'select', array('label' => Mage::helper('adminhtml')->__('Status'), 'title' => Mage::helper('adminhtml')->__('Status'), 'name' => 'is_active', 'required' => true, 'options' => Mage::getModel('easyshippingrules/system_status')->toArray()));
if (!$model->getId()) {
$model->setIsActive(1);
}
/**
* Check is single store mode
*/
if (!Mage::app()->isSingleStoreMode()) {
$field = $fieldset->addField('store_id', 'multiselect', array('name' => 'stores[]', 'label' => Mage::helper('adminhtml')->__('Store View'), 'title' => Mage::helper('adminhtml')->__('Store View'), 'required' => true, 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true)));
if (!$model->getId()) {
$model->setData('store_id', Mage_Core_Model_App::ADMIN_STORE_ID);
}
$field->setRenderer($this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element'));
} else {
$fieldset->addField('store_id', 'hidden', array('name' => 'stores[]', 'value' => Mage::app()->getStore(true)->getId()));
$model->setStoreId(Mage::app()->getStore(true)->getId());
}
$form->setValues($model->getData());
$this->setForm($form);
return parent::_prepareForm();
}
示例13: widgetDirective
/**
* Generate widget
*
* @param array $construction
* @return string
*/
public function widgetDirective($construction)
{
$params = $this->_getIncludeParameters($construction[2]);
// Determine what name block should have in layout
$name = null;
if (isset($params['name'])) {
$name = $params['name'];
}
// validate required parameter type or id
if (!empty($params['type'])) {
$type = $params['type'];
} elseif (!empty($params['id'])) {
$preconfigured = Mage::getResourceSingleton('widget/widget')->loadPreconfiguredWidget($params['id']);
$type = $preconfigured['widget_type'];
$params = $preconfigured['parameters'];
} else {
return '';
}
// we have no other way to avoid fatal errors for type like 'cms/widget__link', '_cms/widget_link' etc.
$xml = Mage::getSingleton('widget/widget')->getXmlElementByType($type);
if ($xml === null) {
return '';
}
// define widget block and check the type is instance of Widget Interface
$widget = Mage::app()->getLayout()->createBlock($type, $name, $params);
if (!$widget instanceof Mage_Widget_Block_Interface) {
return '';
}
return $widget->toHtml();
}
示例14: getCollection
/**
* @return Convenient_AdminGrid_Model_Resource_Collection_Disk|Varien_Data_Collection
*
* @author Luke Rodgers <lukerodgers90@gmail.com>
*/
public function getCollection()
{
if (is_null($this->_collection)) {
$this->_collection = Mage::getResourceSingleton('convenient_admingrid/collection_disk');
}
return $this->_collection;
}
示例15: getQueueCollection
/**
* Return queue collection with loaded neversent queues
*
* @return Mage_Newsletter_Model_Mysql4_Queue_Collection
*/
public function getQueueCollection()
{
if (is_null($this->_queueCollection)) {
$this->_queueCollection = Mage::getResourceSingleton('newsletter/queue_collection')->addTemplateInfo()->addOnlyUnsentFilter()->load();
}
return $this->_queueCollection;
}