Search results for: 'vtiger customer portal'
Results in Category pages.
Results in Magefan Blog.
-
VtigerCRM customer portal can not connect to the CRM
We are using VtigerCRM on our local server which provides ldap authentication for http access, also have the customer portal of vtiger on another machine.
When customer portal connects to the server, this authorization problem occurs. The complete error is pasted
Solution
For your login failure you must turn off your error report in vtigerCRM .
open
config.inc.php
add or change the error_reporting value
error_reporting(0);
-
How to create Custom module for vtiger customer portal
Create default widget for vtigerYou change happen in following filesmodules/Users/Users.php modules/Users/language/en_us.lang.php modules/Home/language/en_us.lang.php include/Home.php
Step 1want to see your widget in your home page you follow this step.Add your widget identifier to $homeorder_array in Users.php search "$homeorder_array"I added 'SOLD'var $homeorder_array = array('HDB','ALVT','PLVT','QLTQ','CVLVT','HLT','OLV','GRT','OLTSO','ILTI','MNL','OLTPO','LTFAQ', 'UA', 'PA', 'SOLD');
Do the same in the function getHomeStuffOrder($id) function$this->homeorder_array = array('UA','PA','ALVT','HDB','PLVT','QLTQ','CVLVT','HLT','GRT','OLTSO','ILTI','MNL','OLTPO','LTFAQ','SOLD');
The above will allow vtiger to pull the widget into your myprefrecnes view so you can select to make visibleStep 2:Adding language file to how you look like add line in these files modules/Users/language/en_us.lang.php modules/Home/language/en_us.lang.php search using "Home page order" and add like this'SOLD'=>'Partially Completed Lead',
Step 3:These queries are in Users.php They will add your widget to the DB when a user is created. Remeber you will need to create a new user for this to take affect, because that is when the module info will be inserted into the DB for each user. Also you could manually insert the fields for a existing user.//** $s18=$adb->getUniqueID("vtiger_homestuff"); $visibility=$this->getDefaultHomeModuleVisibility('SOLD',$inVal); $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)"; $res=$adb->pquery($sql, array($s18,18,'Default',$uid,$visibility,'Sold Policies')); //** $sql="insert into vtiger_homedefault values(".$s18.",'SOLD',10,'SoldPolicies')"; $adb->query($sql);
Step 4:In Home.php within the function getDefaultDetails($dfid,$calCnt) add the code that will select your custom widget code }elseif($hometype=="SOLD" && vtlib_isModuleActive("Leads")){ if(isPermitted('Leads','index') == "yes"){ $home_values=$this->getCustomDetails($dfid); } }Step 5:Create the custom code that displays your data My getCustomDetails($dfid) function returns array loded with all the detials to dsplay a widget. You will need to write a similar fucntion that return this array.$title=array(); $title[]='keyMetrics.gif'; $title[]=$app_strings['LBL_HOME_KEY_METRICS']; $title[]='home_metrics'; $header=Array(); $header[]='Lead Name'; $header[]='Company'; $header[]='Phone'; $entries=Array(); for($l=0; $l; $l++ ){ $lastname = $adb->query_result($result,$l,"lastname"); $firstname = $adb->query_result($result,$l,"firstname"); $phone = $adb->query_result($result,$l,"phone"); $lead_id = $adb->query_result($result,$l,"leadid"); $value=array(); $value[]=''.$firstname.' '.$lastname.''; $value[]=''.$company.''; $value[]=''.$phone.''; $entries[]=$value; } $values=Array('Title'=>$title,'Header'=>$header,'Entries'=>$entries); if ( ($display_empty_home_blocks ) || (count($value)!= 0) ) return $values; }
-
Magento 2: How to Check if a Customer is Logged in?
As Magento 2 store owner, you may want to treat logged in and non-logged in customers differently. For example, you may want to offer exclusive features or discounts to logged in customers only. To implement this, you first need to confirm whether a Magento 2 customer is logged in or not?
Methods To Check If A Customer Is Logged-In In Magento 2
There are 2 ways you can check this. By injecting class and by using object manager. Although the 2nd method (object manager) is not recommended, it’s still used as an alternative.
Method 1: By Injecting Class (Dependency Injection)
In this method, first, you need to inject the following class in the constructor method:
/Magento/Customer/Model/Session
protected $_session; public function __construct( ... \Magento\Customer\Model\Session $session, ... ) { ... $this->_session = $session; ... }
Then in your class, use the following code in any function to check if the customer is logged in or not:
if ($this->_session->isLoggedIn()) { // Customer is logged in } else { // Customer is not logged in }
Sample Code:
<?php namespace [Vendor]\[Module]\Controller\Index; use Magento\Framework\App\Action\Context; use Magento\Framework\App\Action\Action; use Magento\Customer\Model\Session; class ClassName extends Action { protected $_session; public function __construct(Context $context, Session $session) { parent::__construct($context); $this->_session = $session; } public function execute() { // by using Session model if($this->_session->isLoggedIn()) { //customer has logged in // your code in here }else{ //Customer is not logged in // your code in here } } }
Method 2: Using Object Manager
You can use this method as an alternative to the above.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerSession = $objectManager->get('Magento\Customer\Model\Session'); if ($customerSession->isLoggedIn()) { // customer login action }
-
Invoke Custom Function on vTiger
Workflow model in vTigercrm how to create custom workflow.It have simple steps to follow to make custom workflow.Step1:create one new file (registerworkflow.php) to register workflow in ur vTiger root .add all these line in that file.require_once 'include/utils/utils.php'; require 'modules/com_vtiger_workflow/VTEntityMethodManager.inc'; $emm = new VTEntityMethodManager($adb); //$emm->addEntityMethod("Module Name","Label", "Path to file" , "Method Name" ); $emm->addEntityMethod("Invoice", "Update Inventory", "include/InventoryHandler.php", "handleInventoryProductRel");
run that file like.http://YOUR-VTIGER/registerworkflow.phpStrictly follow you must run this file at once. If u run that file more than one time u create more entry.Step 2:Go to{YOUR_VTIGER_ROOT FOLDER}/include/InventoryHandler.phpAnd Add these linesfunction handleInventoryProductRel($entity){}Step 3:Go toSettings > Workflow > Workflow List > New Workflow Vtiger Workflow[/caption]Step 4:In YourSettings > Workflow > Edit Task -
Create Vtiger module
Step 1:
Go to this folder "{Your vtiger root}/vtlib/ModuleDir/" copy any of the folder you want to create module for which version if vtiger . Paste in to {Your vtiger root}/modules/{Your Module name}.
Step 2:
Go to following directory "{Your vtiger root}/modules/{Your Module name}/" . You have to change the files name as following. Replace "ModuleFile" into {Your Module name}
ModuleFileAjax.php -> {Your Module name}Ajax.php
ModuleFile.js -> {Your Module name}.js
ModuleFile.php -> {Your Module name}.php
Step 3:
edit the following file in your faverot editor "{Your vtiger root}/modules/{Your Module name}/{Your Module name}.php"
change "payslip" into "{Your Module name}" case sensitive
Change "ModuleClass" into "{Your Module name}"
-
Magento Customer support
Magento Helpdesk used for customer support . For this magento Customer Support system you customer can create support ticket from magento dashboard . From this extension your customer can create the following ,
For Customer
- Create the ticket .
- Can view list of ticket available by created for you ,
- Customer can replay the the ticket ,
-
vTiger SalesOrder item detail view
Here we discuse about how to add vTiger Sales Order item detail in any where in your vTiger , for example if you want to add Sales Order Item detail in your email .you just need that is just add simple function . if you want to add salesorder item view using single function.
getDetailAssociatedProducts('SalesOrder',$focus);
to youse the above function you got all the detail in your html format .
-
WordPress Vtiger Synchronization
WordPress Vtiger Synchronization to synchronize the wordpress user to vtiger user
-
How to Configure Robots.txt in Magento 2
As you know, configuring robot.txt is important to any website that is working on a site’s SEO. Particularly, when you configure the sitemapto allow search engines to index your store, it is necessary to give web crawlers the instructions in the robot.txt file to avoid indexing the disallowed sites. The robot.txt file, that resides in the root of your Magento installation, is directive that search engines such as Google, Yahoo, Bing can recognize and track easily. In this post, I will introduce the guides to configure the robot.txt file so that it works well with your site.
Following steps to Configure robots.txt in Magento 2
- On the Admin panel, click
Stores
. In theSettings
section, selectConfiguration
. - Select
Design
underGeneral
in the panel on the left - Open the
Search Engine Robots
section, and continue with following:- In
Default Robots
, select one of the following:- INDEX, FOLLOW
- NOINDEX, FOLLOW
- INDEX, NOFOLLOW
- NOINDEX, NOFOLLOW
- In the
Edit Custom instruction of robots.txt File
field, enter custom instructions if needed. - In the
Reset to Defaults
field, click onReset to Default
button if you need to restore the default instructions.
- In
- When complete, click
Save Config
.
Examples of Custom Robots.txt file
- Allows Full Access
User-agent:* Disallow:
- Disallows Access to All Folders
User-agent:* Disallow: /
Default Robots.txt for Magento 2
Disallow: /lib/ Disallow: /*.php$ Disallow: /pkginfo/ Disallow: /report/ Disallow: /var/ Disallow: /catalog/ Disallow: /customer/ Disallow: /sendfriend/ Disallow: /review/ Disallow: /*SID= Disallow: /*? # Disable checkout & customer account Disallow: /checkout/ Disallow: /onestepcheckout/ Disallow: /customer/ Disallow: /customer/account/ Disallow: /customer/account/login/ # Disable Search pages Disallow: /catalogsearch/ Disallow: /catalog/product_compare/ Disallow: /catalog/category/view/ Disallow: /catalog/product/view/ # Disable common folders Disallow: /app/ Disallow: /bin/ Disallow: /dev/ Disallow: /lib/ Disallow: /phpserver/ Disallow: /pub/ # Disable Tag & Review (Avoid duplicate content) Disallow: /tag/ Disallow: /review/ # Common files Disallow: /composer.json Disallow: /composer.lock Disallow: /CONTRIBUTING.md Disallow: /CONTRIBUTOR_LICENSE_AGREEMENT.html Disallow: /COPYING.txt Disallow: /Gruntfile.js Disallow: /LICENSE.txt Disallow: /LICENSE_AFL.txt Disallow: /nginx.conf.sample Disallow: /package.json Disallow: /php.ini.sample Disallow: /RELEASE_NOTES.txt # Disable sorting (Avoid duplicate content) Disallow: /*?*product_list_mode= Disallow: /*?*product_list_order= Disallow: /*?*product_list_limit= Disallow: /*?*product_list_dir= # Disable version control folders and others Disallow: /*.git Disallow: /*.CVS Disallow: /*.Zip$ Disallow: /*.Svn$ Disallow: /*.Idea$ Disallow: /*.Sql$ Disallow: /*.Tgz$
More Robots.txt examples
Block Google bot from a folder
User-agent: Googlebot Disallow: /subfolder/
Block Google bot from a page
User-agent: Googlebot Disallow: /subfolder/page-url.html
Common Web crawlers (Bots)
Here are some common bots in the internet.
User-agent: Googlebot User-agent: Googlebot-Image/1.0 User-agent: Googlebot-Video/1.0 User-agent: Bingbot User-agent: Slurp # Yahoo User-agent: DuckDuckBot User-agent: Baiduspider User-agent: YandexBot User-agent: facebot # Facebook User-agent: ia_archiver # Alexa
- On the Admin panel, click
-
Magento 2: Search Repository using SearchCriteriaBuilder, Filter & FilterGroup
This article shows how we can search Magento Repositories using SearchCriteriaBuilder that implements SearchCriteriaInterface. An example is provided of how we can perform search on Product repository in Magento. Similarly, we can search for other entities like Category, Customer, Order, Invoice, CMS Page, CMS Block, etc.
We can add different conditions to build custom search criteria.
Filters
Filter class is used to add custom field, value, and condition type to the search criteria.
$filter ->setField("name") ->setValue("%laptop%") ->setConditionType("like");
condition_type
is optional.- If
condition_type
is not provided then the defaultcondition_type
is set aseq
.
Different condition types:
CONDITION NOTES eq Equals gt Greater than gteq Greater than or equal lt Less than lteq Less than or equal moreq More or equal neq Not equal in The value can contain a comma-separated list of values. nin Not in. The value can contain a comma-separated list of values. like The value can contain the SQL wildcard characters when like is specified. nlike Not like notnull Not null null Null finset A value within a set of values nfinset A value that is not within a set of values. from The beginning of a range. Must be used with to. to The end of a range. Must be used with from.
Filter Groups
FilterGroup class is used to apply multiple search criteria filters.
For
OR
condition: Pass filters array inside the FilterGroup class object.
ForAND
condition: Pass filterGroups array inside the searchCriteria class object.$filter1 ->setField("name") ->setValue("%laptop%") ->setConditionType("like"); $filter2 ->setField("store_id") ->setValue("1") ->setConditionType("eq"); $filterGroup1->setFilters([$filter1, $filter2]); $filter3 ->setField("url_type") ->setValue(1) ->setConditionType("eq"); $filterGroup2->setFilters([$filter3]); $searchCriteria->setFilterGroups([$filterGroup1, $filterGroup2]);
The above code will generate the following conditions:
(name like %laptop% OR store_id eq 1) AND (url_type eq 1)
Sorting
SortOrder is used to apply sorting to the search criteria.
Field and Direction can be passed to the sortOrder object.
Field is the name of the field to sort.
Direction is how we would like to sort the result. The two sorting values areASC
andDESC
.$sortOrder ->setField("email") ->setDirection("ASC"); $searchCriteria->setSortOrders([$sortOrder]);
Pagination
Limit the number in the result.
$searchCriteria->setPageSize(20); //retrieve 20 or less entities
Set the current page
$searchCriteria ->setPageSize(20) ->setCurrentPage(2); //show the 21st to 40th entity
The search engine determines the maximum number of results that a query can return.
For Elasticsearch, the default value of10000
is defined in the module’setc/di.xml
file.Search Items Using Filters
Below is an example of how we can search Product Repository using Search Criteria Builder.
The ProductRepositoryInterface class has the
getList(SearchCriteria $searchCriteria)
function which returns the search result object. The object is an instance of the class that implements the interface SearchResultInterface.FilterBuilder and SearchCriteriaBuilder are used to avoid shared instances, i.e. we will be using
create()
method in the builder object so that Magento will instantiate a new object (unshared object).use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\Api\FilterBuilder; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Catalog\Api\Data\ProductInterface; ... ... $filter = $this->filterBuilder ->setField(ProductInterface::NAME) ->setValue('%headphone%') ->setConditionType('like') ->create(); $this->searchCriteriaBuilder->addFilters([$filter]); $this->searchCriteriaBuilder->setPageSize(20); $searchCriteria = $this->searchCriteriaBuilder->create(); $productsItems = $this->productRepository ->getList($searchCriteria) ->getItems();
Search Items using FilterGroups
Using FilterGroups to add multiple
AND
andOR
conditions to search products.use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\Api\FilterBuilder; use Magento\Framework\Api\Search\FilterGroupBuilder; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Catalog\Api\Data\ProductInterface; ... ... $filter1 = $this->filterBuilder ->setField(ProductInterface::NAME) ->setValue("%laptop%") ->setConditionType("like") ->create(); $filter2 = $this->filterBuilder ->setField("store_id") ->setValue("1") ->setConditionType("eq") ->create(); $filterGroup1 = $this->filterGroupBuilder ->setFilters([$filter1, $filter2]); $filter3 = $this->filterBuilder ->setField("url_type") ->setValue(1) ->setConditionType("eq") ->create(); $filterGroup2 = $this->filterGroupBuilder ->setFilters([$filter3]); $this->searchCriteriaBuilder ->setFilterGroups([$filterGroup1, $filterGroup2]); $this->searchCriteriaBuilder->setPageSize(20); $searchCriteria = $this->searchCriteriaBuilder->create(); $productsItems = $this->productRepository ->getList($searchCriteria) ->getItems();
Product Repository
use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\Catalog\Api\Data\ProductInterface;
Category Repository
use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Api\Data\CategoryInterface;
CMS Page Repository
use Magento\Cms\Api\PageRepositoryInterface; use Magento\Cms\Api\Data\PageInterface;
CMS Block Repository
use Magento\Cms\Api\BlockRepositoryInterface; use Magento\Cms\Api\Data\BlockInterface;
Customer Repository
use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Api\Data\CustomerInterface;
Order Repository
use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Sales\Api\Data\OrderInterface;
-
profile privileges doesn't save/update for some modules on vTiger
Hi,I have vtiger 5.4 installed on Centos 6.2. When I create/edit new profile, privilege of some modules did not save.Solution" So simply edit php.ini (/etc/php5/apache2/php.ini) and uncomment or add a line with: max_input_vars = 2000 " -
Create default widget for vtiger
Create default widget for vtigerYou change happen in following filesmodules/Users/Users.php modules/Users/language/en_us.lang.php modules/Home/language/en_us.lang.php include/Home.php
Step 1want to see your widget in your home page you follow this step.Add your widget identifier to $homeorder_array in Users.php search "$homeorder_array"I added 'SOLD'var $homeorder_array = array('HDB','ALVT','PLVT','QLTQ','CVLVT','HLT','OLV','GRT','OLTSO','ILTI','MNL','OLTPO','LTFAQ', 'UA', 'PA', 'SOLD'); Do the same in the function getHomeStuffOrder($id) function $this->homeorder_array = array('UA', 'PA', 'ALVT','HDB','PLVT','QLTQ','CVLVT','HLT','GRT','OLTSO','ILTI','MNL','OLTPO','LTFAQ','SOLD'); The above will allow vtiger to pull the widget into your myprefrecnes view so you can select to make visibleStep 2: Adding language file to how you look like add line in these files modules/Users/language/en_us.lang.php modules/Home/language/en_us.lang.php search using "Home page order" and add like this'SOLD'=>'Partially Completed Lead',
These queries are in Users.php They will add your widget to the DB when a user is created. Remeber you will need to create a new user for this to take affect, because that is when the module info will be inserted into the DB for each user. Also you could manually insert the fields for a existing user. //** $s18=$adb->getUniqueID("vtiger_homestuff"); $visibility=$this->getDefaultHomeModuleVisibility('SOLD',$inVal); $sql="insert into vtiger_homestuff values(?,?,?,?,?,?)"; $res=$adb->pquery($sql, array($s18,18,'Default',$uid,$visibility,'Sold Policies')); //** $sql="insert into vtiger_homedefault values(".$s18.",'SOLD',10,'SoldPolicies')"; $adb->query($sql);Step 4:In Home.php within the function getDefaultDetails($dfid,$calCnt) add the code that will select your custom widget code }elseif($hometype=="SOLD" && vtlib_isModuleActive("Leads")){ if(isPermitted('Leads','index') == "yes"){ $home_values=$this->getCustomDetails($dfid); } }Step 5:Create the custom code that displays your data My getCustomDetails($dfid) function returns array loded with all the detials to dsplay a widget. You will need to write a similar fucntion that return this array.$title=array(); $title[]='keyMetrics.gif'; $title[]=$app_strings['LBL_HOME_KEY_METRICS']; $title[]='home_metrics'; $header=Array(); $header[]='Lead Name'; $header[]='Company'; $header[]='Phone'; $entries=Array(); for($l=0; $l $lastname = $adb->query_result($result,$l,"lastname"); $firstname = $adb->query_result($result,$l,"firstname"); $phone = $adb->query_result($result,$l,"phone"); $lead_id = $adb->query_result($result,$l,"leadid"); $value=array(); $value[]=''.$firstname.' '.$lastname.''; $value[]=''.$company.''; $value[]=''.$phone.''; $entries[]=$value; } $values=Array('Title'=>$title,'Header'=>$header,'Entries'=>$entries); if ( ($display_empty_home_blocks ) || (count($value)!= 0) ) return $values; } -
Vtiger outgoing mail server setting
Vtiger outgoing mail server setting for gmail user
Mail Server Settings (SMTP) * Server Name User Name youremail@gmail.com Password your email password From Email youremail@gmail.com Requires Authentication? if not working let`s try with this setting
Mail Server Settings (SMTP) * Server Name User Name Password From Email youremail@yourcompany.com Requires Authentication? no need to use user name also password , and finaly don`t enable authentication
-
Magento
From time to time everyone finds them selves in a position where they are faced with a development they have never confronted before. Today I was achieve to get all orders for a customer based on the customer email address.. While there are almost certainly several ways to do this, I found a nice query that is quick, and capable.
$orderCollection = Mage::getModel(‘sales/order’)->getCollection(); $orderCollection->addFieldToFilter(‘customer_email’,'email@domain.com’);
Happy coding, hope this helps next time you’re working on Magento
-
How to add Login/Logout code on magento
Login/Logout Code in Header
<?php
if
(! Mage::getSingleton(
'customer/session'
)->isLoggedIn()): ?>
<a href=
"<?php echo Mage::helper('customer')->getLoginUrl(); ?>"
><?php
echo
$this
->__(
'Login'
) ?></a>
<?php
else
: ?>
<a href=
"<?php echo Mage::helper('customer')->getLogoutUrl(); ?>"
><?php
echo
$this
->__(
'Logout'
) ?></a>
<?php
endif
; ?>
-
How to Set, Retrieve and Unset Session Variables in Magento
Use of session in Magento:
Let’s start this blog with the session definition, ‘It is a way to preserve certain data across subsequent accesses’. This enables you to build more customized applications and increase the appeal of your web site. Now, Let’s see how to set ,unset and retrieve a session in Magento.Generally, Magento session is handled by core Module ‘core/session’. We use “set<session name>” to set a session variable. For more understanding, look on to the following syntax and example.
Mage::getSingleton(‘core/session’)->set<YOUR SESSION NAME>(<VARIABLE NAME>);
Example :
$myValue =’test’;
Mage::getSingleton(‘core/session’)->setMyValue($myValue);In this example, I have declared the variable $myValue as “test”. I am going to set this variable in session. To do so, I have used the default syntax of the Magento in line 2. Now the session variable is set in the magento.Wow, its easy to set the session variable.
Let’s now look, how to get value from the session variable “MyValue”. To retrieve the session variable, we use
get<YOUR SESSION NAME>();
Mage::getSingleton(‘core/session’)->get<YOUR SESSION NAME>();
In our example, we need to get the session value of “MyValue”. For this, let’s use “getMyValue();”. So our code will be as follows,
$getSession =Mage::getSingleton(‘core/session’)->getMyValue();
Next, we will see how to unset the session variable. To unset the session variable, we have the following syntax,
Mage::getSingleton(‘core/session’)->uns<YOUR SESSION NAME>();
Let’s have a simple example to unset the session variable.
Mage::getSingleton(‘core/session’)->unsMyValue();
This code will automatically delete the session of the MyValue.How to Use customer or core session in frontend. Use adminhtml session in the backend.
Core Session :- Mage::getSingleton(‘core/session’)
Customer Session :- Mage::getSingleton(‘customer/session’)
Admin Session :- Mage::getSingleton(‘adminhtml/session’)
Shopping Cart Session :-Mage::getSingleton(‘checkout/session’)->getQuote() -
VtigerCRM - Sorry! Attempt to access restricted file.
The most likely cause for the vTiger error “Sorry! Attempt to access restricted file.” is the $root_directory value in the ‘config.inc.php’ is incorrect or misspelled.
In order to correct it follow the steps below:
- Go to your vTigerCRM directory
- Open “config.inc.php” with your favorite text editor
- Go to line 86 and adjust $root_directory value to correct vTiger directory. Note, that the directory must end with /. It should look something like this – $root_directory = ‘/var/www/vtigercrm/’;
- If you can't find the root directorey
- Open "Index.php" with your favorite text editor add the following code after <?php
-
echo "__dir__";die;
- It's display the root directory
Hope that helps!
-
AW Blog Integrated Search
Magento AW Blog Integrated Search extends your default Magento search to include your Magento CMS pages and AW blog posts content in search results. Blog contents are now listed in search results from integrated AW blog to ensure more keywords and content visibility to user. This extension will reduce the user bounce rate and keep your search more interactive and effective than before. You can add following results in default search in Magento
- Magento CSM pages
- AW Blog post
- Mage Search Tearm Improvement .
Integrating AW blog to Magento is a common way to have blog, more traffic and many more advantages. AW blog extension is well known for an effective blog in Magento community. Magento AW blog Integrated Search is compatible with AW blog extension.
How to Use this Extension
After install extension go to System -> Index Management .
In Index Management check “AW Blog Search Index” click “Reindex Data”Customer can view the search result in front end using default magento search.
-
Magento download product links opening in browser
I have a downloadable product. After I order the product and when my order is complete, I am able to download the product links from ‘My Downloadable Products’ menu in Customer Account section.
I go to ‘My Downloadable Products’ section and I click on the links to download. However, the PDF file opens in the browser itself. I would like to have the feature that asks to download / save as instead of directly opening in the browser.
It is fine with ZIP files. It asks to download and save. However, the PDF files, Images, HTML files, etc. are directly opened in the browser. I want them to download and save. So, a window appearing and asking to save and download the file is what I want.
Solution:
There is a very easy solution to this.
By default, Magento has the Configuration settings to make those files open in the browser itself. You can adjust the configuration settings in Magento Admin to ask for download files instead of opening in the browser.
- Go to System -> Configuration -> Catalog -> Downloadable Product Options -> Use Content Disposition
- Change the setting from inline to attachment.Now, whenever you click the downloadable link, a pop window will always open and ask to download or open the file.
Hope it helps. Thanks.
-
Magento Module Development Database Option
In this blog we will see advanced operations in model and collection, to execute complex sql queries. We will look into collections and details of resource models.First let’s look at model and collection architecture in magento. If you look at a magento model class it extends Mage_Core_Model_Abstract which intern extends Varien_Object.The class Mage_Core_Model_Abstract has function like getId(), load(), save(), delete() etc .
SQL and Mysql4 Resource FilesMysql4 resource files, as I mentioned earlier are used to perform database queries on tables. Below will list how we do sql operations inside resource files.
SELECT QUERY
Suppose we have the file Excellence_Test_Model_Mysql4_Test resource file.
<?php class Excellence_Test_Model_Mysql4_Test extends Mage_Core_Model_Mysql4_Abstract { public function _construct() { $this->_init('test/test', 'test_id'); } public function loadByField($field,$value){ $table = $this->getMainTable(); $where = $this->_getReadAdapter()->quoteInto("$field = ?", $value); $select = $this->_getReadAdapter()->select()->from($table,array('test_id'))->where($where); $id = $this->_getReadAdapter()->fetchOne($sql); return $id; } }
And here is the model file Excellence_Test_Model_Test
<?php class Excellence_Test_Model_Test extends Mage_Core_Model_Abstract { public function _construct() { parent::_construct(); $this->_init('test/test'); } public function loadByField($field,$value){ $id = $this->getResource()->loadByField($field,$value); $this->load($id); } }
In this file there are many new functions which have been used. Let’s take them one by one.
In our model file, we have used this function
$id = $this->getResource()->loadByField($field,$value);
$this->getResource() function returns the resource model’s object. So we are simply calling the loadyByField($field,$value) function in the resource model.
getTable() function
Now in our Mysql4 file, in the loadByField() function we have used $table = $this->getMainTable(); .This function returns the table name of the current model, i.e the one defined in the class’s constructor. If you want to get table name of another sql table in magento, we need to the getTable() call e.g
$table = $this->getTable(‘newsletter/subscribe’);
_getReadAdapter() function
Next we have: $where = $this->_getReadAdapter()->quoteInto(“$field = ?”, $value);
Here the first function too see is the $this->_getReadAdapter() function. This function return an object which has function to perform database query, like fetch(), fetchAll(), query(), etc.
Next, in read adapter, we can perform operations like:
- fetchAll() : returns entire database table in multiple dimensional array as per the select query. e.g if we are executing an sql like “select * from table_name”, we would use the fetchAll() function to get all the values.
- fetchRow(): returns a single row of the database table as per the select query. e.g if we are executing sql like “select * from table where id = ’1′” would use fetchRow() to get the single row.
- fetchCol(): returns single column of a database table as per the select query. e.g if query is a select name from table” we would use fetchCol() function.
- fetchOne(): return since value, i.e single row and single column. e.g if sql query “select count(*) from table” then we would use fetchOne()
The read adapter has many other functions as well, but above are the important functions used.
_quoteInfo() function
Another function we have used is quoteInto(): This function is used to create our where conditions. In this the actual value is substituted into the question mark we have written. For e.g $this->_getReadAdapter()->quoteInto(“user_id = ?”, 3); translates to
“user_id = 3″. Another frequently used variation of quoteInfo() is
$where = $this->_getReadAdapter()->quoteInto("$field IN(?)", array(1,2,3));
this translates to “field in (1,2,3)”
Getting deeper into the quoteInto() function: If we have multiple where conditions we can use
$where = $this->_getReadAdapter()->quoteInto("$field = ? AND ", $value).$this->_getReadAdapter()->quoteInto("$field1 = ? OR ", $value1).$this->_getReadAdapter()->quoteInto("$field2 = ?", $value2);
So this way, we can have multiple where conditions.
Continuing on the loadByField function in our resource model, next we have
$select = $this->_getReadAdapter()->select()->from($table,array(‘test_id’))->where($where);
Here we have created the select query using the select(), and on that called the from() function.
from() function
The from() function takes many different parameters, if you want to fire a simple select * query, you need to only pass the table name like from($table).
But right now, I wanted to select just a single column that is test_id, so I passed an array with column name to select. i.e array(‘test_id’). If we want to select multiple column, we need to array(‘test_id’,’col1’,’col2’). This will create a sql like
“select test_id,col1,col2 from $table”. But support we want a sql query like
“select test_id as id,col1 as column1 from $table” , i would call
from($table,array('id'=>'test_id','column1'=>'col1'));
Note:
If you want to see the exact sql that is generated by your function, you can any time do this
<?php echo $select; ?>
Again, back to the loadByField() function. The last line
<?php $id = $this->_getReadAdapter()->fetchOne($sql); ?>
This is already explained, above.
Select ObjectThe select() function we used above return a select object which provides us with many more functions to perform all operations on a sql query. The class for the select object is Varien_Db_Select, where you can look into more details for all functions. Let look at a sample php code below.
public function getAll(){ $table = $this->getMainTable(); $where = $this->_getReadAdapter()->quoteInto("id = ?", 123); $select = $this->_getReadAdapter()->select()->from($table)->columns(array('test_id'))->where($where)->limit(10,5)->order('created_time')->group('list_id')->having('list_id > ?',10); echo $select; }
As we can see all function in the select object, return the select object itself. Due to this we are able to chain the functions.
In this example, I have used almost all the sql select parameters you might require expect joins, which will be covered later.
Let’s take each function one at a time.
- select() : used to initialize the sql query. This returns the Select object, which is the object on which we do all our operations.
- from(): table name on which select operation is done. we have seen this in detail above.
- columns() : here we can specify exactly which columns to select in the query
- where() : used to give the where condition
- limit(): takes to parameters. First are how many rows to return and second is offset from where to start. So in current case, it means return 10rows, leaving first 5rows.this uses the LIMIT 10 OFFSET 5 syntax in sql query, rather than LIMIT 10,5
- order(): you can set how you want to order the result set. Default is ascending order. But if you want to mentioned descending order you do order(array(‘created_time Zend_Db_Select::SQL_DESC))
- group(): put group by clause in your select query in the specified field.Having(): put having condition for group by clause.
JOINS
Let look at sample function.
public function joinUs() { $table = $this->getMainTable(); $table2 = $this->getTable('customer/entity'); $cond = $this->_getReadAdapter()->quoteInto('t1.id = t2.customer_id',''); $where = $this->_getReadAdapter()->quoteInto('t1.list_id = "?"',123); $select = $this->_getReadAdapter()->select()->from(array('t1'=>$table))->join(array('t2'=>$table2), $cond)->where($where); echo $select."<br/>"; $select = $this->_getReadAdapter()->select()->from(array('t1'=>$table))->joinLeft(array('t2'=>$table2), $cond)->where($where); echo $select."<br/>"; $select = $this->_getReadAdapter()->select()->from(array('t1'=>$table))->joinRight(array('t2'=>$table2), $cond)->where($where); echo $select."<br/>"; echo $select."<br/>"; }
This is the output I got in the my pc
SELECT `t1`.*, `t2`.* FROM `aws` AS `t1` INNER JOIN `customer_entity` AS `t2` ON t1.id = t2.customer_id WHERE (t1.list_id = "123") SELECT `t1`.*, `t2`.* FROM `aws` AS `t1` LEFT JOIN `customer_entity` AS `t2` ON t1.id = t2.customer_id WHERE (t1.list_id = "123") SELECT `t1`.*, `t2`.* FROM `aws` AS `t1` RIGHT JOIN `customer_entity` AS `t2` ON t1.id = t2.customer_id WHERE (t1.list_id = "123")
So, here you can see clearly how to use joins. I don’t think much explanation is required, the function call are self-explanatory. We can also use joinCross, joinFull, joinNatural as well, if you require it in any query. Please look at Varien_Db_Select class for details.
COUNT,MAX
Again, lets take another sample code
public function countUs(){ $table = $this->getMainTable(); $where = $this->_getReadAdapter()->quoteInto("id = ?", 123); $select = $this->_getReadAdapter()->select()->from($table)->reset('columns')->columns(new Zend_Db_Expr('count(*)')); echo $select.'<br>'; $select = $this->_getReadAdapter()->select()->from($table)->reset('columns')->columns(new Zend_Db_Expr('max(list_id)')); echo $select.'<br>'; }
This is the output.
SELECT count(*) FROM `aws` SELECT max("list_id") FROM `aws`
As you can see here, using Expr classes, we do mysql averaging functions.
query() function
In the end, if you have a very complex sql query, you want to execute you can simple use the query function.
$sql = ‘…complex sql…’;
$this->_getReadAdapter()->query($sql);
UPDATE, DELETE Querypublic function updateUs(){ $table = $this->getMainTable(); $where = $this->_getWriteAdapter()->quoteInto('id = ?', 1); $query = $this->_getWriteAdapter()->update($table, array('product_id'=>2,'file_id'=>3),$where); }
Here you can see how to execute the update query.
UPDATE `aws` SET `product_id` = ?, `file_id` = ? WHERE (id = 1)
For delete query, it’s very simple
$this->_getWriteAdapter()->delete($table,$where)->limit(1);
Important Note: Its considered good practice in magento, to execute these sql query in the resource files only. You can get the read adaptor object in model, phtml or any other files and do the above operations in any file. But as good practices, always try to do the query in resource/mysql4 files only.
Exercise:Well, it would best if can try out all the queries mentioned above yourself, to get a hold on all the syntax. -
Aw Blog User visitor Report Generation
AW Blog Report Generation extends used to generate user view AW Blog result count . Following
type of report you can see- Report displayed by Days .
- Report displayed by Month .
- Report displayed by Year .
Features- AW Blog User Visit Report .
- Used to Customer visting interest .
- Help to improve SEO of your Blog post .
Recomented
- Magento 1.7.x or Magento 1.8.x .
- AW Blog Magento Extension .