Ejemplo n.º 1
0
 /**
  * Translates a category id stored in the supplied field to a full category path.
  *
  * @param array $aRow A flat product row
  * @param string $vField The name of the filed in which the category id is found.
  * @param Mage_Core_Model_Store $oStore The store context we're currently exporting.
  * @return mixed
  */
 public function translate($aRow, $vField, $oStore)
 {
     if ($oStore->getId() !== $this->_iStoreId) {
         $this->_iDefaultCondition = Mage::getStoreConfig(self::CONFIG_CONDITION, $oStore->getId());
         $this->_iStoreId = $oStore->getId();
     }
     $vFieldValue = false;
     if (array_key_exists($vField, $aRow)) {
         $vFieldValue = $aRow[$vField];
     }
     return Mage::getSingleton('aligent_feeds/source_condition')->getGoogleValue($vFieldValue ? $vFieldValue : $this->_iDefaultCondition);
 }
 /**
  * Retrieve store Id
  *
  * @return int
  */
 public function getStoreId()
 {
     if (is_null($this->_store)) {
         try {
             $this->_store = Mage::app()->getStore($this->getVar('store'));
         } catch (Exception $e) {
             $message = Mage::helper('eav')->__('Invalid store specified');
             $this->addException($message, Varien_Convert_Exception::FATAL);
             throw $e;
         }
     }
     return $this->_store->getId();
 }
Ejemplo n.º 3
0
 /**
  * @magentoDataFixture Mage/Core/_files/store.php
  * @magentoDbIsolation enabled
  * @dataProvider saveActionDataProvider
  * @param array $inputData
  * @param array $defaultAttributes
  * @param array $attributesSaved
  */
 public function testSaveAction($inputData, $defaultAttributes, $attributesSaved = array())
 {
     $store = new Mage_Core_Model_Store();
     $store->load('fixturestore', 'code');
     $storeId = $store->getId();
     $this->getRequest()->setPost($inputData);
     $this->getRequest()->setParam('store', $storeId);
     $this->getRequest()->setParam('id', 2);
     $this->dispatch('backend/admin/catalog_category/save');
     $messages = Mage::getSingleton('Mage_Backend_Model_Session')->getMessages(false)->getItemsByType(Mage_Core_Model_Message::SUCCESS);
     $this->assertNotEmpty($messages, "Could not save category");
     $this->assertEquals('The category has been saved.', current($messages)->getCode());
     $category = new Mage_Catalog_Model_Category();
     $category->setStoreId($storeId);
     $category->load(2);
     $errors = array();
     foreach ($attributesSaved as $attribute => $value) {
         $actualValue = $category->getData($attribute);
         if ($value !== $actualValue) {
             $errors[] = "value for '{$attribute}' attribute must be '{$value}', but '{$actualValue}' is found instead";
         }
     }
     foreach ($defaultAttributes as $attribute => $exists) {
         if ($exists !== $category->getExistsStoreValueFlag($attribute)) {
             if ($exists) {
                 $errors[] = "custom value for '{$attribute}' attribute is not found";
             } else {
                 $errors[] = "custom value for '{$attribute}' attribute is found, but default one must be used";
             }
         }
     }
     $this->assertEmpty($errors, "\n" . join("\n", $errors));
 }
Ejemplo n.º 4
0
 public function export(Mage_Core_Model_Store $oStore, $vFeedname, Mage_Core_Model_Config_Element $oConfig)
 {
     Mage::getSingleton('aligent_feeds/log')->log("Beginning {$vFeedname} export for store #" . $oStore->getId() . " - " . $oStore->getName());
     Mage::getSingleton('aligent_feeds/log')->logMemoryUsage();
     Mage::getSingleton('aligent_feeds/log')->log("Initialising file writers...");
     $this->_initWriters($oStore, $vFeedname, $oConfig);
     // Prepare the csv file header
     Mage::getSingleton('aligent_feeds/log')->log("Begin preparing header rows...");
     Mage::getSingleton('aligent_feeds/log')->logMemoryUsage();
     $this->_prepareHeaders($oConfig);
     // Initialise the formatter
     Mage::getSingleton('aligent_feeds/log')->log("Initialising Feed Formatter...");
     Mage::getSingleton('aligent_feeds/feed_formatter')->init($oStore, $oConfig);
     Mage::getSingleton('aligent_feeds/log')->log("Initialised Feed Formatter.");
     Mage::getSingleton('aligent_feeds/log')->logMemoryUsage();
     $oConn = Mage::getModel('core/resource')->getConnection('catalog_read');
     $vCategoryProductTable = Mage::getModel('core/resource_setup', 'core_setup')->getTable('catalog/category_product');
     $vCategoryFlatTable = Mage::getResourceSingleton('catalog/category_flat')->getMainStoreTable($oStore->getId());
     $vProductFlatTable = Mage::getResourceModel('catalog/product_flat_indexer')->getFlatTableName($oStore->getId());
     // Complicated subquery to get the most deeply nested category that this
     // product is assigned to.  Picking the most deeply nested on the assumption
     // that the deepest category is most likely to be the most specific.
     $oSubSelect = new Varien_Db_Select($oConn);
     $oSubSelect->from(array('ccf' => $vCategoryFlatTable), 'entity_id')->joinInner(array('ccp2' => 'catalog_category_product'), 'ccf.entity_id=ccp2.category_id', array())->where('ccp2.product_id=main_table.entity_id')->where('ccf.is_active=1')->order('level', Zend_Db_Select::SQL_DESC)->limit(1);
     $oSelect = new Varien_Db_Select($oConn);
     $oSelect->from(array('main_table' => $vProductFlatTable), array('main_table.*', 'category_id' => new Zend_Db_Expr('(' . $oSubSelect . ')')))->where('visibility IN (?)', array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH));
     // Allow the feed definition to include a "before_query_filter".  This method
     // will be allowed to modify the query before it's executed.
     if ($oConfig->before_query_filter) {
         Mage::getSingleton('aligent_feeds/log')->log("Calling before query filter...");
         $vClass = (string) $oConfig->before_query_filter->class;
         $vMethod = (string) $oConfig->before_query_filter->method;
         $aParams = (array) $oConfig->before_query_filter->params;
         Mage::getSingleton($vClass)->{$vMethod}($oSelect, $oStore, $aParams);
         Mage::getSingleton('aligent_feeds/log')->log("Before query filter done.");
     }
     Mage::getSingleton('aligent_feeds/log')->log("Exporting products...");
     $oResource = Mage::getModel('core/resource_iterator')->walk($oSelect, array(function ($aArgs) {
         Mage::getSingleton('aligent_feeds/log')->log("Exporting product #" . $aArgs['idx'] . "  SKU: " . $aArgs['row']['sku'], Zend_Log::DEBUG, true);
         if ($aArgs['idx'] % 100 == 0) {
             Mage::getSingleton('aligent_feeds/log')->log("Exporting product #" . $aArgs['idx'] . "...", Zend_Log::INFO);
             Mage::getSingleton('aligent_feeds/log')->logMemoryUsage();
         }
         $aRows = Mage::getSingleton('aligent_feeds/feed_formatter')->prepareRow($aArgs['row']);
         if (count($aRows) > 0) {
             foreach ($aRows as $aRow) {
                 foreach ($aArgs['writers'] as $oWriter) {
                     $oWriter->writeDataRow($aRow);
                 }
             }
         }
     }), array('writers' => $this->_oWriters, 'config' => $oConfig, 'store' => $oStore));
     $this->_closeWriters();
     $this->_sendFeed();
     Mage::getSingleton('aligent_feeds/status')->addSuccess("Generated {$vFeedname} data for store #" . $oStore->getId() . " - " . $oStore->getName());
     Mage::getSingleton('aligent_feeds/log')->log("Finished {$vFeedname} data export for store #" . $oStore->getId() . " - " . $oStore->getName());
     Mage::getSingleton('aligent_feeds/log')->logMemoryUsage();
     return $this;
 }
Ejemplo n.º 5
0
 public function setData($key, $value = null)
 {
     parent::setData($key, $value);
     if ($this->getStoreId() && $this->store && $this->store->getId() != $this->getStoreId()) {
         $this->store = null;
     }
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * @param string $key
  * @return mixed
  */
 protected function getConfig($key)
 {
     if (isset($this->_store)) {
         $storeId = $this->_store->getId();
     } else {
         $storeId = null;
     }
     return Mage::getStoreConfig('mehulchaudhari_feedsgenerator/' . $this->_configPath . '/' . $key, $storeId);
 }
Ejemplo n.º 7
0
 /**
  * Translates a category id stored in the supplied field to a full category path.
  *
  * @param array $aRow A flat product row
  * @param string $vField The name of the filed in which the category id is found.
  * @param Mage_Core_Model_Store $oStore The store context we're currently exporting.
  * @return mixed
  */
 public function translate($aRow, $vField, $oStore)
 {
     if ($oStore->getId() !== $this->_iStoreId) {
         $this->_aCategoryPaths = array();
         $this->_initCategories($oStore);
         $this->_iStoreId = $oStore->getId();
     }
     return $this->_getCategoryPath($aRow[$vField]);
 }
Ejemplo n.º 8
0
 /**
  * Return subscriber object with basic attribues
  *
  * @param string $email
  * @param string $status OPTIONAL
  * @return Mage_Newsletter_Model_Subscriber
  */
 protected function _getSubscriberObject($email, $status = Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED)
 {
     $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
     $subscriber->setImportMode(TRUE)->setBulksync(TRUE);
     if (!$subscriber->getId()) {
         $subscriber->setStoreId($this->_store->getId())->setSubscriberConfirmCode(Mage::getModel('newsletter/subscriber')->randomSequence())->setEmail($email);
     }
     $subscriber->setStatus($status);
     return $subscriber;
 }
 /**
  * @param Adyen_Subscription_Model_Product_Subscription $subscription
  * @param Mage_Core_Model_Store|int $store
  * @return $this
  */
 public function loadBySubscription(Adyen_Subscription_Model_Product_Subscription $subscription, $store)
 {
     $labels = $this->getCollection()->addFieldToFilter('subscription_id', $subscription->getId());
     if ($store instanceof Mage_Core_Model_Store) {
         $storeId = $store->getId();
     } else {
         $storeId = $store;
     }
     $labels->addFieldToFilter('store_id', $storeId);
     return $labels->getFirstItem();
 }
Ejemplo n.º 10
0
 /**
  * Function retrieves extension stored in Magento configuration.
  * Default in category extension.
  * @param Mage_Core_Model_Store $store
  */
 public function getExtension($store)
 {
     if (!isset($store) || !$store) {
         return Mage::getStoreConfig('catalog/seo/category_url_suffix');
     }
     $extension = Mage::getStoreConfig('catalog/seo/category_url_suffix', $store->getId());
     if (isset($extension) && $extension != '' && $extension[0] == '.') {
         $extension = '\\' . $extension;
     }
     return $extension;
 }
 /**
  * @param Mage_Core_Model_Store $store
  */
 protected function _flushAllSpecialPrices($store)
 {
     /** @var Mage_Catalog_Model_Resource_Product_Collection $products */
     $products = Mage::getResourceModel('catalog/product_collection')->setStoreId($store->getId())->addAttributeToFilter('special_from_date', array('lteq' => now(true)))->addAttributeToFilter(array(array('attribute' => 'special_to_date', 'gteq' => now(true)), array('attribute' => 'special_to_date', 'null' => true)))->addWebsiteFilter($store->getWebsiteId());
     $size = $products->getSize();
     if ($size) {
         $msg = sprintf('process store %s and %s product(s) with all special prices', $store->getCode(), $size);
         Mage::getSingleton('core/resource_iterator')->walk($products->getSelect(), array(array($this, 'iteratorCallback')), array('size' => $size, 'msg' => $msg, 'store' => $store));
         echo PHP_EOL;
     }
 }
Ejemplo n.º 12
0
 /**
  * Retrieve request_path using id_path and current store's id.
  *
  * @param string $idPath
  * @param int|Mage_Core_Model_Store $store
  * @return string|false
  */
 public function getRequestPathByIdPath($idPath, $store)
 {
     if ($store instanceof Mage_Core_Model_Store) {
         $storeId = (int) $store->getId();
     } else {
         $storeId = (int) $store;
     }
     $select = $this->_getReadAdapter()->select();
     /* @var $select Zend_Db_Select */
     $select->from(array('main_table' => $this->getMainTable()), 'request_path')->where('main_table.store_id = ?', $storeId)->where('main_table.id_path = ?', $idPath)->limit(1);
     return $this->_getReadAdapter()->fetchOne($select);
 }
Ejemplo n.º 13
0
 /**
  * @return Mage_Core_Model_Store
  */
 public function getStore()
 {
     // Only attempt to load the store if a storeId is present
     if ($this->_storeId) {
         if (is_null($this->_store) || $this->_store->getId() != $this->_storeId) {
             $this->_store = Mage::getModel('core/store')->load($this->_storeId);
         }
     } else {
         if (is_null($this->_store)) {
             $this->_store = Mage::app()->getStore();
         }
     }
     return $this->_store;
 }
Ejemplo n.º 14
0
 /**
  * @covers Mage_Core_Model_Website::setGroups
  * @covers Mage_Core_Model_Website::setStores
  * @covers Mage_Core_Model_Website::getStores
  */
 public function testSetGroupsAndStores()
 {
     /* Groups */
     $expectedGroup = new Mage_Core_Model_Store_Group();
     $expectedGroup->setId(123);
     $this->_model->setDefaultGroupId($expectedGroup->getId());
     $this->_model->setGroups(array($expectedGroup));
     $groups = $this->_model->getGroups();
     $this->assertSame($expectedGroup, reset($groups));
     /* Stores */
     $expectedStore = new Mage_Core_Model_Store();
     $expectedStore->setId(456);
     $expectedGroup->setDefaultStoreId($expectedStore->getId());
     $this->_model->setStores(array($expectedStore));
     $stores = $this->_model->getStores();
     $this->assertSame($expectedStore, reset($stores));
 }
Ejemplo n.º 15
0
 /**
  * @param Mage_Core_Model_Store $store
  * @return $this
  */
 protected function _addOneClickMethodsToConfig(Mage_Core_Model_Store $store)
 {
     Varien_Profiler::start(__CLASS__ . '::' . __FUNCTION__);
     $customer = Mage::helper('adyen/billing_agreement')->getCurrentCustomer();
     if (!$customer || !$customer->getId()) {
         return $this;
     }
     $baCollection = Mage::getResourceModel('adyen/billing_agreement_collection');
     $baCollection->addFieldToFilter('customer_id', $customer->getId());
     $baCollection->addFieldToFilter('store_id', $store->getId());
     $baCollection->addActiveFilter();
     foreach ($baCollection as $billingAgreement) {
         // Only show payment methods that are enabled by the merchant
         $agreementData = json_decode($billingAgreement->agreement_data, true);
         $recurringPaymentType = Mage::getStoreConfig('payment/adyen_oneclick/recurring_payment_type', $store);
         $this->_createPaymentMethodFromBA($billingAgreement, $store);
     }
     Varien_Profiler::stop(__CLASS__ . '::' . __FUNCTION__);
 }
Ejemplo n.º 16
0
 /**
  * @return Mage_Customer_Model_Customer
  */
 public function createCustomer(Mage_Core_Model_Store $store, array $addressInfo = array())
 {
     /** @var $customer Mage_Customer_Model_Customer */
     $customer = Mage::getModel('customer/customer')->setId(null);
     $customer->setData('firstname', $addressInfo['firstname']);
     $customer->setData('lastname', $addressInfo['lastname']);
     $customer->setData('email', $addressInfo['email']);
     $customer->setData('password', $addressInfo['customer_password']);
     $customer->setData('confirmation', $addressInfo['confirm_password']);
     $account = $this->getAccount();
     if ($websiteId = $account->getData('orders_customer_new_website')) {
         $customer->setWebsiteId($websiteId);
     } else {
         if (!$store->getId()) {
             $customer->setWebsiteId(Mage::helper('M2ePro/Sales')->getDefaultWebsiteId());
         } else {
             $customer->setStore($store);
         }
     }
     if ($groupId = $account->getData('orders_customer_new_group')) {
         $customer->setGroupId($groupId);
     }
     if ($account->isCustomerSubscribeToNewsletterEnabled()) {
         $customer->setIsSubscribed(1);
     }
     // Remove confirmation if required
     if ($customer->getConfirmation() && $customer->isConfirmationRequired()) {
         $customer->setConfirmation(null);
     }
     $customer->save();
     // Add customer address
     // ---------------------------
     /** @var $customerAddress Mage_Customer_Model_Address */
     $customerAddress = Mage::getModel('customer/address')->setData($addressInfo)->setCustomerId($customer->getId())->setIsDefaultBilling('1')->setIsDefaultShipping('1');
     $customerAddress->implodeStreetAddress();
     $customerAddress->save();
     // --------------------------
     if ($account->isCustomerNewAccountNotificationEnabled()) {
         $customer->sendNewAccountEmail('registered', '', $store->getId());
     }
     return $customer;
 }
Ejemplo n.º 17
0
 /**
  * @param Mage_Core_Model_Store $store
  * @return $this
  */
 protected function _addOneClickMethodsToConfig(Mage_Core_Model_Store $store)
 {
     Varien_Profiler::start(__CLASS__ . '::' . __FUNCTION__);
     $customer = Mage::helper('adyen/billing_agreement')->getCurrentCustomer();
     if (!$customer || !$customer->getId()) {
         return $this;
     }
     $baCollection = Mage::getResourceModel('adyen/billing_agreement_collection');
     $baCollection->addFieldToFilter('customer_id', $customer->getId());
     $baCollection->addFieldToFilter('store_id', $store->getId());
     $baCollection->addFieldToFilter('method_code', 'adyen_oneclick');
     $baCollection->addActiveFilter();
     foreach ($baCollection as $billingAgreement) {
         // only create payment method when label is set
         if ($billingAgreement->getAgreementLabel() != null) {
             $this->_createPaymentMethodFromBA($billingAgreement, $store);
         }
     }
     Varien_Profiler::stop(__CLASS__ . '::' . __FUNCTION__);
 }
Ejemplo n.º 18
0
 /**
  * Gets the absolute preview URL to the current store view front page.
  * The preview url includes "nostodebug=true" parameter.
  *
  * @param Mage_Core_Model_Store $store the store to get the url for.
  *
  * @return string the url.
  */
 public function getPreviewUrlFront(Mage_Core_Model_Store $store)
 {
     $url = Mage::getUrl('', array('_store' => $store->getId(), '_store_to_url' => true));
     return NostoHttpRequest::replaceQueryParamInUrl('nostodebug', 'true', $url);
 }
Ejemplo n.º 19
0
 /**
  * Set last time when files were generated
  *
  * @param Zend_Date $lastTime
  * @param Mage_Core_Model_Store $store
  */
 public function setLastTimeGenerated(Zend_Date $lastTime = null, $store)
 {
     if (!$lastTime) {
         $lastTime = Zend_Date::now();
     }
     $scope = $store ? 'stores' : 'default';
     $scopeId = $store ? $store->getId() : 0;
     $path = self::XML_PATH_LAST_TIME_GENERATED_DATE;
     $configDataCollection = Mage::getModel('core/config_data')->getCollection()->addFieldToFilter('scope', $scope)->addFieldToFilter('scope_id', $scopeId)->addFieldToFilter('path', array('eq' => $path))->load();
     if (count($configDataCollection)) {
         $configDataCollection->getFirstItem()->setValue($lastTime->toString(Zend_Date::ISO_8601))->save();
     } else {
         Mage::getModel('core/config_data')->setPath(self::XML_PATH_LAST_TIME_GENERATED_DATE)->setValue($lastTime->toString(Zend_Date::ISO_8601))->setScope($scope)->setScopeId($scopeId)->save();
     }
     $store->resetConfig();
 }
Ejemplo n.º 20
0
 /**
  * Save the supplied config for the supplied store.
  *
  * @param \Mage_Core_Model_Store $store
  * @param string $xpath
  * @param string $value
  * @return void
  */
 protected function saveStoreConfig(\Mage_Core_Model_Store $store, $xpath, $value)
 {
     $config = $this->getApplication()->getConfig();
     $config->saveConfig($xpath, $value, 'stores', $store->getId());
 }
Ejemplo n.º 21
0
 /**
  * Set store to customer
  *
  * @param Mage_Core_Model_Store $store
  * @return Mage_Customer_Model_Customer
  */
 public function setStore(Mage_Core_Model_Store $store)
 {
     $this->setStoreId($store->getId());
     $this->setWebsiteId($store->getWebsite()->getId());
     return $this;
 }
Ejemplo n.º 22
0
 /**
  * Init Staging Store Views
  *
  * @param Varien_Data_Form $fieldset
  * @param Mage_Core_Model_Store $storeView
  * @param Mage_Core_Model_Website $stagingWebsite
  * @return Enterprise_Staging_Block_Manage_Staging_Edit_Tabs_Website
  */
 protected function _initStoreView($fieldset, $storeView, $stagingWebsite = null)
 {
     $_shift = str_repeat(' ', 6);
     if (!$stagingWebsite) {
         $_id = $storeView->getId();
         $websiteId = $storeView->getWebsiteId();
         $fieldset->addField('master_store_use_' . $_id, 'checkbox', array('label' => $_shift . $storeView->getName(), 'name' => "websites[{$websiteId}][stores][{$_id}][use]", 'value' => $storeView->getId(), 'checked' => true));
         $fieldset->addField('master_store_id_' . $_id, 'hidden', array('label' => Mage::helper('enterprise_staging')->__('Master Store ID'), 'name' => "websites[{$websiteId}][stores][{$_id}][master_store_id]", 'value' => $storeView->getId()));
         $fieldset->addField('master_store_code_' . $_id, 'hidden', array('label' => Mage::helper('enterprise_staging')->__('Master Store Code'), 'name' => "websites[{$websiteId}][stores][{$_id}][master_store_code]", 'value' => $storeView->getCode()));
         $fieldset->addField('staging_store_code_' . $_id, 'hidden', array('label' => Mage::helper('enterprise_staging')->__('Staging Store Code'), 'name' => "websites[{$websiteId}][stores][{$_id}][code]", 'value' => Mage::helper('enterprise_staging/store')->generateStoreCode($storeView->getCode())));
         $fieldset->addField('staging_store_name_' . $_id, 'hidden', array('label' => Mage::helper('enterprise_staging')->__('Staging Store Name'), 'name' => "websites[{$websiteId}][stores][{$_id}][name]", 'value' => $storeView->getName()));
     } else {
         $fieldset->addField('staging_store_' . $storeView->getId(), 'label', array('label' => $_shift . $storeView->getName()));
     }
     return $this;
 }
Ejemplo n.º 23
0
 /**
  * Parse product collection into json
  * @param Mage_Catalog_Model_Product_Collection $collection
  * @param Mage_Core_Model_Store $store
  * @return array
  */
 public function parseJsonData($collection, $store)
 {
     $ignoreFields = array('sku', 'price', 'status');
     $fetchedProducts = 0;
     //is category name searchable
     $solr_include_category_in_search = Mage::helper('solrsearch')->getSetting('solr_search_in_category');
     //use category for facets
     $use_category_as_facet = Mage::helper('solrsearch')->getSetting('use_category_as_facet');
     //use tags for search and facets
     $use_tags_for_search = Mage::helper('solrsearch')->getSetting('use_tags_for_search');
     //use keywords suggestion
     $use_keywords_suggestion = Mage::helper('solrsearch')->getSetting('display_keyword_suggestion');
     //Remove store from Product Url
     $remove_store_from_url = Mage::helper('solrsearch')->getSetting('remove_store_from_url');
     //display brand suggestion
     $display_brand_suggestion = Mage::helper('solrsearch')->getSetting('display_brand_suggestion');
     //display brand suggestion attribute code
     $brand_attribute_code = Mage::helper('solrsearch')->getSetting('brand_attribute_code');
     $brand_attribute_code = trim($brand_attribute_code);
     $includedBrandAttributeCodes = array();
     if ($display_brand_suggestion > 0 && !empty($brand_attribute_code)) {
         $includedBrandAttributeCodes[] = $brand_attribute_code;
     }
     //Product search weight attribute code
     $includedSearchWeightAttributeCodes = array();
     $search_weight_attribute_code = Mage::helper('solrsearch')->getSetting('search_weight_attribute_code');
     $search_weight_attribute_code = trim($search_weight_attribute_code);
     if (!empty($search_weight_attribute_code)) {
         $includedSearchWeightAttributeCodes[] = $search_weight_attribute_code;
     }
     $startPoint = 0;
     $index = 1;
     $textSearch = array();
     $textSearchText = array();
     $documents = "{";
     //loop products
     $collection->load();
     foreach ($collection as $product) {
         $textSearch = array();
         $textSearchText = array();
         $docData = array();
         $_product = Mage::getModel('catalog/product')->setStoreId($store->getId())->load($product->getId());
         //foreach ($this->getProductAttributes() as $key=>$atributeObj) {
         foreach ($product->getAttributes() as $atributeObj) {
             $backendType = $atributeObj->getBackendType();
             $frontEndInput = $atributeObj->getFrontendInput();
             $attributeCode = $atributeObj->getAttributeCode();
             $attributeData = $atributeObj->getData();
             if (!$atributeObj->getIsSearchable() && !in_array($attributeCode, $includedSearchWeightAttributeCodes)) {
                 if (!empty($includedBrandAttributeCodes) && in_array($attributeCode, $includedBrandAttributeCodes)) {
                     //Do nothing...need better solution
                 } else {
                     continue;
                 }
             }
             if ($backendType == 'int') {
                 $backendType = 'varchar';
             }
             $attributeKey = $attributeCode . '_' . $backendType;
             $attributeKeyFacets = $attributeCode . '_facet';
             if (!is_array($atributeObj->getFrontEnd()->getValue($_product))) {
                 $attributeVal = strip_tags($atributeObj->getFrontEnd()->getValue($_product));
             } else {
                 $attributeVal = $atributeObj->getFrontEnd()->getValue($_product);
                 $attributeVal = implode(' ', $attributeVal);
             }
             if ($_product->getData($attributeCode) == null) {
                 $attributeVal = null;
             }
             //Generate product search weigh value
             if (in_array($attributeCode, $includedSearchWeightAttributeCodes)) {
                 if (!empty($attributeVal) && is_numeric($attributeVal)) {
                     $docData['product_search_weight_int'] = $attributeVal;
                     if (!$atributeObj->getIsSearchable()) {
                         continue;
                     }
                 }
             }
             //Start collect values
             $this->logFields[] = $attributeKey;
             if (empty($attributeVal) || $attributeVal == 'No' || $attributeVal == 'None') {
                 unset($docData[$attributeKey]);
                 unset($docData[$attributeKeyFacets]);
                 unset($docData[$attributeCode . '_boost']);
                 unset($docData[$attributeCode . '_boost_exact']);
                 unset($docData[$attributeCode . '_relative_boost']);
             } else {
                 $attributeValFacets = array();
                 if ($frontEndInput == 'multiselect') {
                     $attributeValFacetsArray = @explode(',', $attributeVal);
                     $attributeValFacets = array();
                     foreach ($attributeValFacetsArray as $val) {
                         $attributeValFacets[] = trim($val);
                     }
                 } else {
                     $attributeValFacets[] = trim($attributeVal);
                 }
                 if ($backendType == 'datetime') {
                     $attributeVal = date("Y-m-d\\TG:i:s\\Z", $attributeVal);
                 }
                 if (!in_array($attributeVal, $textSearch) && $attributeVal != 'None' && $attributeCode != 'status' && $attributeCode != 'sku') {
                     if (strlen($attributeVal) > 255) {
                         $textSearchText[] = $attributeVal;
                     } else {
                         $textSearch[] = $attributeVal;
                         $textSearch[] = $atributeObj->getStoreLabel() . ' ' . $attributeVal;
                     }
                 }
                 if ($backendType != 'text' && !in_array($attributeCode, $ignoreFields)) {
                     $docData[$attributeCode . '_boost'] = $attributeVal;
                     $docData[$attributeCode . '_boost_exact'] = $attributeVal;
                     $docData[$attributeCode . '_relative_boost'] = $attributeVal;
                     $docData[$attributeKey] = $attributeVal;
                 }
                 if (isset($attributeData['solr_search_field_weight']) && !empty($attributeData['solr_search_field_weight']) || isset($attributeData['solr_search_field_boost']) && !empty($attributeData['solr_search_field_boost'])) {
                     $docData[$attributeCode . '_boost'] = $attributeVal;
                     $docData[$attributeCode . '_boost_exact'] = $attributeVal;
                     $docData[$attributeCode . '_relative_boost'] = $attributeVal;
                 }
                 if (isset($attributeData['is_filterable_in_search']) && !empty($attributeData['is_filterable_in_search']) && $attributeValFacets != 'No' && $attributeKey != 'price_decimal' && $attributeKey != 'special_price_decimal') {
                     $docData[$attributeKeyFacets] = $attributeValFacets;
                     //$docData[$attributeCode.'_text'] = $attributeValFacets;
                 }
             }
         }
         //Calculate allow categories
         if (!isset($this->allowCategoryIds[$store->getId()])) {
             $allowCategoryIds = ($allowCatIds = $this->getAllowCategoriesByStore($store)) ? $allowCatIds : array();
             $this->allowCategoryIds[$store->getId()] = $allowCategoryIds;
         }
         $cats = $_product->getCategoryIds();
         $catNames = array();
         $catNamesAutocomplete = array();
         $categoryPaths = array();
         $categoryIds = array();
         foreach ($cats as $category_id) {
             if (in_array($category_id, $this->allowCategoryIds[$store->getId()])) {
                 $_cat = Mage::getModel('catalog/category')->setStoreId($store->getId())->load($category_id);
                 if ($_cat && $_cat->getIsActive() && $_cat->getIncludeInMenu()) {
                     $catNames[] = $_cat->getName() . '/' . $_cat->getId();
                     $catNamesAutocomplete[] = $_cat->getName();
                     $categoryPaths[] = $this->getCategoryPath($_cat, $store);
                     $categoryIds[] = $_cat->getId();
                 }
             }
         }
         if ($solr_include_category_in_search > 0) {
             $textSearch = array_merge($textSearch, $catNames);
         }
         $sku = $_product->getSku();
         $textSearch[] = $sku;
         $textSearch[] = str_replace(array('-', '_'), '', $sku);
         if ($use_category_as_facet) {
             $docData['category_facet'] = $catNames;
             $docData['category_text'] = $catNames;
             $docData['category_boost'] = $catNames;
             $docData['category_boost_exact'] = $catNames;
             $docData['category_relative_boost'] = $catNames;
         }
         //Use product tags for search
         if ($use_tags_for_search) {
             $tagNames = $this->getProductTags($_product);
             $docData['product_tags_facet'] = $tagNames;
             $docData['product_tags_boost'] = $tagNames;
             $docData['product_tags_boost_exact'] = $tagNames;
             $docData['product_tags_relative_boost'] = $tagNames;
             $textSearch = array_merge($textSearch, $tagNames);
         }
         $docData['category_path'] = $categoryPaths;
         $docData['textSearch'] = $textSearch;
         $docData['textSearchText'] = $textSearchText;
         /*
         if ($use_keywords_suggestion) {
             $docData['keywordAutocomplete'] = $textSearchText;
             $docData['categoryAutocomplete'] = $catNamesAutocomplete;
         }
         */
         $this->updateDocDataForConfigurableProducts($docData, $_product, $store);
         $solrPriceIncludingTax = 0;
         $solrSpecialPriceIncludingTax = 0;
         Mage::getModel('solrsearch/price')->getProductPrice($_product, $solrPriceIncludingTax, $solrSpecialPriceIncludingTax, $store);
         if ($solrPriceIncludingTax) {
             $this->updatePriceData($docData, $_product, $solrPriceIncludingTax, $solrSpecialPriceIncludingTax, $store);
         }
         if (intval($remove_store_from_url) > 0) {
             $params['_store_to_url'] = false;
             $productUrl = $_product->getUrlInStore($product, $params);
             $baseurl = $store->getBaseUrl();
             $productUrl = str_replace($baseurl, '/', $productUrl);
         } else {
             $productUrl = $_product->getProductUrl();
         }
         if (strpos($productUrl, 'solrbridge_indexer.php')) {
             $productUrl = str_replace('solrbridge_indexer.php', 'index.php', $productUrl);
         }
         if (strpos($productUrl, 'solrbridge.php')) {
             $productUrl = str_replace('solrbridge.php', 'index.php', $productUrl);
         }
         $docData['url_path_varchar'] = $productUrl;
         $docData['name_boost'] = $_product->getName();
         $docData['name_boost_exact'] = $_product->getName();
         $docData['name_relative_boost'] = $_product->getName();
         $docData['products_id'] = $_product->getId();
         $orderCount = $this->getBestSellerCount($_product->getId());
         $docData['order_count_int'] = round($orderCount, 2);
         $docData['category_id'] = $categoryIds;
         $docData['unique_id'] = $store->getId() . 'P' . $_product->getId();
         if (!isset($docData['product_search_weight_int'])) {
             $docData['product_search_weight_int'] = 0;
         }
         $docData['store_id'] = $store->getId();
         $docData['website_id'] = $store->getWebsiteId();
         $docData['sku_id'] = $_product->getSku();
         $stock = $_product->getStockItem();
         if ($stock->getIsInStock()) {
             $docData['instock_int'] = 1;
         } else {
             $docData['instock_int'] = 0;
         }
         $docData['product_status'] = $_product->getStatus();
         $this->generateThumb($_product);
         $documents .= '"add": ' . json_encode(array('doc' => $docData)) . ",";
         $index++;
         $fetchedProducts++;
     }
     $jsonData = trim($documents, ",") . '}';
     return array('jsondata' => $jsonData, 'fetchedProducts' => (int) $fetchedProducts);
 }
Ejemplo n.º 24
0
 /**
  * Get HTML of store chooser
  *
  * @param Mage_Core_Model_Store $storeTo
  * @return string
  */
 public function getChooseFromStoreHtml($storeTo)
 {
     if (!$this->_storeFromHtml) {
         $this->_storeFromHtml = '<select name="copy_to_stores[__store_identifier__]" disabled="disabled">';
         $this->_storeFromHtml .= '<option value="0">' . Mage::helper('catalog')->__('Default Values') . '</option>';
         foreach ($this->getWebsiteCollection() as $_website) {
             if (!$this->hasWebsite($_website->getId())) {
                 continue;
             }
             $optGroupLabel = $this->escapeHtml($_website->getName());
             $this->_storeFromHtml .= '<optgroup label="' . $optGroupLabel . '"></optgroup>';
             foreach ($this->getGroupCollection($_website) as $_group) {
                 $optGroupName = $this->escapeHtml($_group->getName());
                 $this->_storeFromHtml .= '<optgroup label="&nbsp;&nbsp;&nbsp;&nbsp;' . $optGroupName . '">';
                 foreach ($this->getStoreCollection($_group) as $_store) {
                     $this->_storeFromHtml .= '<option value="' . $_store->getId() . '">&nbsp;&nbsp;&nbsp;&nbsp;';
                     $this->_storeFromHtml .= $this->escapeHtml($_store->getName()) . '</option>';
                 }
             }
             $this->_storeFromHtml .= '</optgroup>';
         }
         $this->_storeFromHtml .= '</select>';
     }
     return str_replace('__store_identifier__', $storeTo->getId(), $this->_storeFromHtml);
 }
Ejemplo n.º 25
0
 /**
  * Retreive specified attribute data for specified products from specified store
  *
  * @param array $products
  * @param array $attributes
  * @param Mage_Core_Model_Store $store
  */
 public function getAttributeData($products, $attributes, $store)
 {
     return $this->getResource()->getAttributeData($products, $attributes, $store->getId());
 }
Ejemplo n.º 26
0
 /**
  * Return wrapping model for wrapping ID
  *
  * @param  int $wrappingId
  * @param  Mage_Core_Model_Store $store
  * @return Enterprise_GiftWrapping_Model_Wrapping
  */
 protected function _getWrapping($wrappingId, $store)
 {
     $wrapping = Mage::getModel('enterprise_giftwrapping/wrapping');
     $wrapping->setStoreId($store->getId());
     $wrapping->load($wrappingId);
     return $wrapping;
 }
Ejemplo n.º 27
0
 /**
  * @param                       $requestParams
  * @param Mage_Core_Model_Store $store
  * @return string
  */
 protected function _getCacheKeyForRequest($requestParams, Mage_Core_Model_Store $store)
 {
     $cacheParams = array();
     $cacheParams['store'] = $store->getId();
     foreach ($this->_cacheParams as $paramKey) {
         if (isset($requestParams[$paramKey])) {
             $cacheParams[$paramKey] = $requestParams[$paramKey];
         }
     }
     return md5(implode('|', $cacheParams));
 }
Ejemplo n.º 28
0
 /**
  * Rebuild Catalog Product Flat Data
  *
  * @param Mage_Core_Model_Store|int $store
  * @return Mage_Catalog_Model_Resource_Product_Flat_Indexer
  */
 public function rebuild($store = null)
 {
     if ($store === null) {
         foreach (Mage::app()->getStores() as $store) {
             $this->rebuild($store->getId());
         }
         return $this;
     }
     $storeId = (int) Mage::app()->getStore($store)->getId();
     $this->prepareFlatTable($storeId);
     $this->cleanNonWebsiteProducts($storeId);
     $this->updateStaticAttributes($storeId);
     $this->updateEavAttributes($storeId);
     $this->updateEventAttributes($storeId);
     $this->updateRelationProducts($storeId);
     $this->cleanRelationProducts($storeId);
     $flag = $this->getFlatHelper()->getFlag();
     $flag->setIsBuilt(true)->setStoreBuilt($storeId, true)->save();
     return $this;
 }
 /**
  * Get last used increment part of rewrite request path
  *
  * @param string $urlPath
  * @param Mage_Core_Model_Store $store
  * @return int
  */
 protected function _getRewriteRequestIncrement($urlPath, Mage_Core_Model_Store $store)
 {
     // match request_url abcdef1234(-12)(.html) pattern
     $match = array();
     $regularExpression = '#^([0-9a-z/-]+)(-([0-9]+))?$#i';
     preg_match($regularExpression, $urlPath, $match);
     $match[1] = $match[1] . '-';
     $match[4] = isset($match[4]) ? $match[4] : '';
     $prefix = $match[1];
     $requestPathField = new Zend_Db_Expr($this->_connection->quoteIdentifier('request_path'));
     //select increment part of request path and cast expression to integer
     $urlIncrementPartExpression = $this->_eavHelper->getCastToIntExpression($this->_connection->getSubstringSql($requestPathField, strlen($prefix) + 1, $this->_connection->getLengthSql($requestPathField) . ' - ' . strlen($prefix)));
     $select = $this->_connection->select()->from($this->_getTable('enterprise_urlrewrite/url_rewrite'), new Zend_Db_Expr('MAX(' . $urlIncrementPartExpression . ')'))->where('entity_type = :entity_type')->where('store_id = :store_id')->where('request_path LIKE :request_path')->where($this->_connection->prepareSqlCondition('request_path', array('regexp' => '^' . preg_quote($prefix) . '[0-9]*$')));
     $bind = array('store_id' => (int) $store->getId(), 'request_path' => $prefix . '%', 'entity_type' => Enterprise_Catalog_Model_Category::URL_REWRITE_ENTITY_TYPE);
     return (int) $this->_connection->fetchOne($select, $bind);
 }
Ejemplo n.º 30
0
 /**
  * @param Mage_Core_Model_Store $store
  * @return string
  */
 protected function _getFullStoreName($store)
 {
     if (!isset($this->_fullStoreNames[$store->getId()])) {
         $fullStoreName = $store->getWebsite()->getName() . ' / ' . $store->getGroup()->getName() . ' / ' . $store->getName();
         $this->_fullStoreNames[$store->getId()] = $fullStoreName;
     }
     return $this->_fullStoreNames[$store->getId()];
 }