本文整理汇总了PHP中Mage_Core_Model_Factory类的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Core_Model_Factory类的具体用法?PHP Mage_Core_Model_Factory怎么用?PHP Mage_Core_Model_Factory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mage_Core_Model_Factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
* Arguments:
* request - Zend_Controller_Request_Http
* config - Mage_Core_Model_Config
* factory - Mage_Core_Model_Factory
* routers - array
*
* @param array $args
*/
public function __construct(array $args)
{
$this->_factory = !empty($args['factory']) ? $args['factory'] : Mage::getModel('core/factory');
$this->_app = !empty($args['app']) ? $args['app'] : Mage::app();
$this->_config = !empty($args['config']) ? $args['config'] : Mage::getConfig();
$this->_request = !empty($args['request']) ? $args['request'] : Mage::app()->getFrontController()->getRequest();
$this->_rewrite = !empty($args['rewrite']) ? $args['rewrite'] : $this->_factory->getModel('core/url_rewrite');
if (!empty($args['routers'])) {
$this->_routers = $args['routers'];
}
}
示例2: _reindex
protected function _reindex()
{
$factory = new Mage_Core_Model_Factory();
$processes = array();
$indexer = $factory->getSingleton($factory->getIndexClassAlias());
$collection = $indexer->getProcessesCollection();
foreach ($collection as $process) {
if ($process->getIndexer()->isVisible() === false) {
continue;
}
$processes[] = $process;
}
foreach ($processes as $process) {
/* @var $process Mage_Index_Model_Process */
try {
$this->_log("Reindexing " . $process->getIndexerCode());
$process->reindexEverything();
} catch (Exception $e) {
Mage::logException($e);
}
}
}
示例3: _getClient
/**
* Retrieve client instance
*
* @param string $metadataTableName
* @return Enterprise_Mview_Model_Client
*/
protected function _getClient($metadataTableName)
{
/** @var $client Enterprise_Mview_Model_Client */
$client = $this->_factory->getModel('enterprise_mview/client', array(array('factory' => $this->_factory)));
$client->init($metadataTableName);
return $client;
}
示例4: save
/**
* Save value
*
* @return Enterprise_UrlRewrite_Model_System_Config_Backend_MatcherPriority
*/
public function save()
{
if ($this->getOldValue() !== $this->getValue()) {
$matchers = explode('-', $this->getValue());
$priority = 0;
/** @var $configModel Mage_Core_Model_Config */
$configModel = $this->_factory->getSingleton('core/config');
foreach ($matchers as $matcher) {
$priority += 10;
$path = sprintf(Enterprise_UrlRewrite_Model_Url_Rewrite::REWRITE_MATCHERS_PRIORITY_PATH, $matcher);
$configModel->saveConfig($path, $priority);
}
}
return $this;
}
示例5: _getUrlByRewriteRow
/**
* Get url by rewrite row
*
* @param array $rewriteRow
* @param string $baseUrl
* @param int $storeId
* @return string
* @throws Exception
*/
protected function _getUrlByRewriteRow($rewriteRow, $baseUrl, $storeId)
{
switch ($rewriteRow['entity_type']) {
case Enterprise_Catalog_Model_Product::URL_REWRITE_ENTITY_TYPE:
$url = $baseUrl . $this->_factory->getHelper('enterprise_catalog')->getProductRequestPath($rewriteRow['request_path'], $storeId, $rewriteRow['category_id']);
break;
case Enterprise_Catalog_Model_Category::URL_REWRITE_ENTITY_TYPE:
$url = $baseUrl . $this->_factory->getHelper('enterprise_catalog')->getCategoryRequestPath($rewriteRow['request_path'], $storeId);
break;
default:
throw new Exception('Unknown entity type ' . $rewriteRow['entity_type']);
break;
}
return $url;
}
示例6: getProductIds
/**
* Retrieve product Ids
*
* @param Enterprise_TargetRule_Model_Index $object
* @return array
*/
public function getProductIds($object)
{
$adapter = $this->_getReadAdapter();
$select = $adapter->select()->from($this->getMainTable(), 'customer_segment_id')->where('type_id = :type_id')->where('entity_id = :entity_id')->where('store_id = :store_id')->where('customer_group_id = :customer_group_id');
$rotationMode = $this->_factory->getHelper('enterprise_targetrule')->getRotationMode($object->getType());
$segmentsIds = array_merge(array(0), $this->_getSegmentsIdsFromCurrentCustomer());
$bind = array(':type_id' => $object->getType(), ':entity_id' => $object->getProduct()->getEntityId(), ':store_id' => $object->getStoreId(), ':customer_group_id' => $object->getCustomerGroupId());
$segmentsList = $adapter->fetchAll($select, $bind);
$foundSegmentIndexes = array();
foreach ($segmentsList as $segment) {
$foundSegmentIndexes[] = $segment['customer_segment_id'];
}
$productIds = array();
foreach ($segmentsIds as $segmentId) {
if (in_array($segmentId, $foundSegmentIndexes)) {
$productIds = array_merge($productIds, $this->getTypeIndex($object->getType())->loadProductIdsBySegmentId($object, $segmentId));
} else {
$matchedProductIds = $this->_matchProductIdsBySegmentId($object, $segmentId);
$productIds = array_merge($matchedProductIds, $productIds);
$this->getTypeIndex($object->getType())->saveResultForCustomerSegments($object, $segmentId, $matchedProductIds);
$this->saveFlag($object, $segmentId);
}
}
$productIds = array_diff(array_unique($productIds), $object->getExcludeProductIds());
if ($rotationMode == Enterprise_TargetRule_Model_Rule::ROTATION_SHUFFLE) {
shuffle($productIds);
}
return $productIds;
}
示例7: login
/**
* 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 = $this->_factory->getModel('admin/user');
$user->login($username, $password);
if ($user->getId()) {
$this->renewSession();
if (Mage::getSingleton('adminhtml/url')->useSecretKey()) {
Mage::getSingleton('adminhtml/url')->renewSecretUrls();
}
$this->setIsFirstPageAfterLogin(true);
$this->setUser($user);
$this->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
$alternativeUrl = $this->_getRequestUri($request);
$redirectUrl = $this->_urlPolicy->getRedirectUrl($user, $request, $alternativeUrl);
if ($redirectUrl) {
Mage::dispatchEvent('admin_session_user_login_success', array('user' => $user));
$this->_response->clearHeaders()->setRedirect($redirectUrl)->sendHeadersAndExit();
}
} else {
Mage::throwException(Mage::helper('adminhtml')->__('Invalid User Name or Password.'));
}
} catch (Mage_Core_Exception $e) {
Mage::dispatchEvent('admin_session_user_login_failed', array('user_name' => $username, 'exception' => $e));
if ($request && !$request->getParam('messageSent')) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$request->setParam('messageSent', true);
}
}
return $user;
}
示例8: addExcludeProcess
/**
* Exclude catalogsearch_fulltext indexer
*
* @deprecated since version 1.13.2
* @param Varien_Event_Observer $observer
*/
public function addExcludeProcess(Varien_Event_Observer $observer)
{
$helper = $this->_factory->getHelper('enterprise_catalogsearch');
if (!$helper->isFulltextOn()) {
$observer->getEvent()->getCollection()->addExcludeProcessByCode('catalogsearch_fulltext');
}
}
示例9: checkDisplaySettings
/**
* Check if tax calculation type and price display settings are compatible
*
* invalid settings if
* Tax Calculation Method Based On 'Total' or 'Row'
* and at least one Display Settings has 'Including and Excluding Tax' value
*
* @param mixed $store
* @return bool
*/
public function checkDisplaySettings($store)
{
if ($this->_factory->getHelper('tax')->getCalculationAgorithm($store) == Mage_Tax_Model_Calculation::CALC_UNIT_BASE) {
return true;
}
return !$this->displayCartWrappingBothPrices($store) && !$this->displayCartCardBothPrices($store) && !$this->displaySalesWrappingBothPrices($store) && !$this->displaySalesCardBothPrices($store);
}
示例10: _toHtml
/**
* ACL validation before html generation
*
* @return string
*/
protected function _toHtml()
{
if ($this->_factory->getSingleton('admin/session')->isAllowed('system/config/tax')) {
return parent::_toHtml();
}
return '';
}
示例11: _prepareAffectedProduct
/**
* Prepare affected product
*/
protected function _prepareAffectedProduct()
{
/** @var $modelCondition Mage_Catalog_Model_Product_Condition */
$modelCondition = $this->_factory->getModel('catalog/product_condition');
$productCondition = $modelCondition->setTable($this->_resource->getTable('catalogrule/affected_product'))->setPkFieldName('product_id');
$this->_app->dispatchEvent('catalogrule_after_apply', array('product' => $this->_getProduct(), 'product_condition' => $productCondition));
$this->_connection->delete($this->_resource->getTable('catalogrule/affected_product'));
}
示例12: insertRuleData
/**
* Inserts rule data into catalogrule/rule_product table
*
* @param Mage_CatalogRule_Model_Rule $rule
* @param array $websiteIds
* @param array $productIds
*/
public function insertRuleData(Mage_CatalogRule_Model_Rule $rule, array $websiteIds, array $productIds = array())
{
/** @var $write Varien_Db_Adapter_Interface */
$write = $this->_getWriteAdapter();
$customerGroupIds = $rule->getCustomerGroupIds();
$fromTime = (int) strtotime($rule->getFromDate());
$toTime = (int) strtotime($rule->getToDate());
$toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
$sortOrder = (int) $rule->getSortOrder();
$actionOperator = $rule->getSimpleAction();
$actionAmount = (double) $rule->getDiscountAmount();
$subActionOperator = $rule->getSubIsEnable() ? $rule->getSubSimpleAction() : '';
$subActionAmount = (double) $rule->getSubDiscountAmount();
$actionStop = (int) $rule->getStopRulesProcessing();
/** @var $helper Mage_Catalog_Helper_Product_Flat */
$helper = $this->_factory->getHelper('catalog/product_flat');
if ($helper->isEnabled() && $helper->isBuiltAllStores()) {
/** @var $store Mage_Core_Model_Store */
foreach ($this->_app->getStores(false) as $store) {
if (in_array($store->getWebsiteId(), $websiteIds)) {
/** @var $selectByStore Varien_Db_Select */
$selectByStore = $rule->getProductFlatSelect($store->getId())->joinLeft(array('cg' => $this->getTable('customer/customer_group')), $write->quoteInto('cg.customer_group_id IN (?)', $customerGroupIds), array('cg.customer_group_id'))->reset(Varien_Db_Select::COLUMNS)->columns(array(new Zend_Db_Expr($store->getWebsiteId()), 'cg.customer_group_id', 'p.entity_id', new Zend_Db_Expr($rule->getId()), new Zend_Db_Expr($fromTime), new Zend_Db_Expr($toTime), new Zend_Db_Expr("'" . $actionOperator . "'"), new Zend_Db_Expr($actionAmount), new Zend_Db_Expr($actionStop), new Zend_Db_Expr($sortOrder), new Zend_Db_Expr("'" . $subActionOperator . "'"), new Zend_Db_Expr($subActionAmount)));
if (count($productIds) > 0) {
$selectByStore->where('p.entity_id IN (?)', array_keys($productIds));
}
$selects = $write->selectsByRange('entity_id', $selectByStore, self::RANGE_PRODUCT_STEP);
foreach ($selects as $select) {
$write->query($write->insertFromSelect($select, $this->getTable('catalogrule/rule_product'), array('website_id', 'customer_group_id', 'product_id', 'rule_id', 'from_time', 'to_time', 'action_operator', 'action_amount', 'action_stop', 'sort_order', 'sub_simple_action', 'sub_discount_amount'), Varien_Db_Adapter_Interface::INSERT_IGNORE));
}
}
}
} else {
if (count($productIds) == 0) {
Varien_Profiler::start('__MATCH_PRODUCTS__');
$productIds = $rule->getMatchingProductIds();
Varien_Profiler::stop('__MATCH_PRODUCTS__');
}
$rows = array();
foreach ($productIds as $productId => $validationByWebsite) {
foreach ($websiteIds as $websiteId) {
foreach ($customerGroupIds as $customerGroupId) {
if (empty($validationByWebsite[$websiteId])) {
continue;
}
$rows[] = array('rule_id' => $rule->getId(), 'from_time' => $fromTime, 'to_time' => $toTime, 'website_id' => $websiteId, 'customer_group_id' => $customerGroupId, 'product_id' => $productId, 'action_operator' => $actionOperator, 'action_amount' => $actionAmount, 'action_stop' => $actionStop, 'sort_order' => $sortOrder, 'sub_simple_action' => $subActionOperator, 'sub_discount_amount' => $subActionAmount);
if (count($rows) == 1000) {
$write->insertMultiple($this->getTable('catalogrule/rule_product'), $rows);
$rows = array();
}
}
}
}
if (!empty($rows)) {
$write->insertMultiple($this->getTable('catalogrule/rule_product'), $rows);
}
}
}
示例13: _restoreInitialLocale
/**
* Restore locale of the initial store
*
* @param string $initialLocaleCode
* @param string $initialArea
*
* @return Mage_Core_Model_App_Emulation
*/
protected function _restoreInitialLocale($initialLocaleCode, $initialArea = Mage_Core_Model_App_Area::AREA_ADMINHTML)
{
$currentLocaleCode = $this->_app->getLocale()->getLocaleCode();
if ($currentLocaleCode != $initialLocaleCode) {
$this->_app->getLocale()->setLocaleCode($initialLocaleCode);
$this->_factory->getSingleton('core/translate')->setLocale($initialLocaleCode)->init($initialArea, true);
}
return $this;
}
示例14: loadByRequestPath
/**
* Load url rewrite entity by request_path
*
* @param array $paths
* @return Enterprise_UrlRewrite_Model_Url_Rewrite
*/
public function loadByRequestPath($paths)
{
$this->setId(null);
$rewriteRows = $this->_getResource()->getRewrites($paths);
$matchers = $this->_factory->getSingleton('enterprise_urlrewrite/system_config_source_matcherPriority')->getRewriteMatchers();
foreach ($matchers as $matcherIndex) {
$matcher = $this->_factory->getSingleton($this->_factory->getConfig()->getNode(sprintf(self::REWRITE_MATCHERS_MODEL_PATH, $matcherIndex), 'default'));
foreach ($rewriteRows as $row) {
if ($matcher->match($row, $paths['request'])) {
$this->setData($row);
break 2;
}
}
}
$this->_afterLoad();
$this->setOrigData();
$this->_hasDataChanges = false;
return $this;
}
示例15: deleteProductCustomRedirects
/**
* Listener for before product delete event. Deletes product custom redirects.
* Needed because of http://bugs.mysql.com/bug.php?id=11472
* @param Varien_Event_Observer $observer
*/
public function deleteProductCustomRedirects(Varien_Event_Observer $observer)
{
if ((string) $this->_app->getConfig()->getNode(Enterprise_UrlRewrite_Model_Index_Observer::XML_PATH_REDIRECT_URL_SUFFIX_UPDATE_ON_SAVE)) {
return;
}
/** @var Mage_Catalog_Model_Product $product */
$product = $observer->getProduct();
/** @var Enterprise_UrlRewrite_Model_Resource_Redirect $redirects */
$redirects = $this->_factory->getResourceModel('enterprise_urlrewrite/redirect');
$redirects->deleteByProductIds(array($product->getId()));
}