Thursday, August 22, 2013

Magento abandoned cart for guest/unconfirmed users

http://stackoverflow.com/questions/13584054/magento-abandoned-cart-for-guest-unconfirmed-users



SELECT entity_id, customer_firstname, customer_email, items_count, grand_total, created_at
FROM sales_flat_quote
WHERE entity_id NOT IN (SELECT quote_item_id AS quote_id FROM sales_flat_order_item) 
AND items_count >0
AND customer_email IS NOT NULL
ORDER BY `sales_flat_quote`.`created_at` DESC

http://stackoverflow.com/questions/15148275/when-does-magento-consider-a-cart-to-be-abandoned-wheres-that-time-limit-set
As you probably know the setting is located here:
Admin => system => Configuration => Sales => Checkout => Quote Lifetime (days)
This will add the setting to the database (core_config_data table) with path:
checkout/cart/delete_quote_after
This path is used in the code on:
app/code/core/Mage/Sales/Model/Observer.php line 54
So when someone is adding something to a cart it will be updated. When a customer logs in and his cart is there it will be updated. When a cart is not updated for the last 30 days. It will be removed.
Extra information:
In case you wonder when this code is used, It is used by the cronjob of magento.
check: App/code/core/Mage/Sales/etc/config.xml line 1732

    
        
            
                0 0 * * *
sales/observer::cleanExpiredQuotes
Hope this helps.

Magento Shopping Cart Abandonment



All this can be done using Magento, but as you said, this is a very broad question. I'll give answers to the specific topics, but I suggest you take time to study the fundamentals of Magento module development. Here is an excellent tutorial by Alan Storm (read the whole series).

Get list of abandoned carts

In Magento, the cart is simply a wrapper for the sales/quote object, so that is the entity you will be working with.
Instead of adding increments to a abandoned_duration attribute, I suggest simply checking against the updated_at field.

$adapter = Mage::getSingleton('core/resource')->getConnection('sales_read');
$minutes = 15;
$from = $adapter->getDateSubSql(
    $adapter->quote(now()), 
    $minutes, 
    Varien_Db_Adapter_Interface::INTERVAL_MINUTE
);
$quotes = Mage::getResourceModel('sales/quote_collection')
    ->addFieldToFilter('converted_at', $adapter->getSuggestedZeroDate())
    ->addFieldToFilter('updated_at', array('to' => $from));
This will give you a collection (think of it as an array with methods) of all quotes that haven't been updated for 15 minutes. You can iterate over them like an array
foreach ($quotes as $quote) {
    /* @var $quote Mage_Sales_Model_Quote */
}

Magento Cronjobs

In Magento, all cron jobs are listed in the configuration structure. So first you need to add it to the config.xml of your module (refer to the linked tutorial for more information on Magento configuration).
This XML registers a cronjob with Magento.

    
        
            
                */15 * * * *
your_module/observer::processAbandonedCarts Now, whenever Magento runs the cronjob, it will instantiate the class your_module/observer and call the processAbandonedCarts() method.
In order for Magento to process configured cronjobs, you need to set the system up to do so. This consists of two parts: the system configuration and the triggering of the cron jobs.
The system configuration is done in the administrative interface under System > Configuration > System > Cron (Scheduled Tasks)
The triggering consists of setting up a way to periodically execute the cron.php (or cron.sh) script in the Magento root directory. This can be done using a regular crontab entry (man 5 crontab on any decent unix system for more information). Another option preferred by many is to execute the cron.php script through a curl or wget call so the processing user ID matches the regular Magento user ID (i.e. the Apache user). This might be important if APC caching is configured, but this is getting off topic.
However, on topic is that you need to call it often enough so it matches the settings you specify in the administrative interface!
I generally recommend executing the cron.php script every 5 minutes. If there is nothing scheduled it will simply exit.
One really useful extension for Magento when working with cronjobs is Aoe_Scheduler. It adds much of the user interfaces for cronjobs and interactive functionality that should be part of the core system.

Other

Sending the data to a web service is not Magento specific, but rather regular PHP, so I'll wont go into more detail.
To delete a cart, simple call $quote->delete() on the loaded sales/quote instance.
Please ask mor specific questions for further information.



http://stackoverflow.com/questions/9223790/where-to-start-with-magento-shopping-cart-abandonment

Related Link
http://www.magentocommerce.com/magento-connect/anatta-design-abandoned-carts-2536.html


Monday, June 3, 2013

Creating a Downloadable Product in OpenCart

http://www.inmotionhosting.com/support/edu/opencart/303-creating-a-downloadable-product-in-opencart

http://www.opencarttutorial.com/how-to-setup-your-opencart-catalog/downloadable-products/
At times, you may want to sell a digital product such as an image, audio file, or e-book. This can be easily accomplished in OpenCart. To offer a downloadable product, you'll first have to upload the file within OpenCart and then you'll need to link the file to a product. 
Important! Remember to uncheck the "Requires Shipping" checkbox or your customers will be charged shipping fees by mistake.

Uploading Your Digital Product

  1. Log into your OpenCart Dashboard
  2. Go to Catalog > Downloads
  3. Click “Insert” in the upper right corner
  4. opencart_digital_1
  5. Fill in the fields with a download name, Select the file to upload on your local computer, and type in the number of downloads allowed per user purchase
  6. opencart_digital_2
  7. Click “Save”

Linking the download file to a product

  1. Log into your OpenCart Dashboard
  2. Go to Products
  3. Click “Insert” to create a new product or click “Edit” next to an existing product
  4. Click on the “links” tab
  5. Scroll towards the bottom of the page, go to the “Downloads” section and select the file you want to be made available on this product
  6. opencart_digital_3
  7. While still editing this product, click on the “Data” tab and scroll down to the section called “Weight”. Enter a weight of “0” (zero) in the field. This tells OpenCart it is a downloadable product
  8. Click on “Save” in the upper right corner
If you need further assistance please feel free to ask a question in our support center website.

Thursday, January 31, 2013

Google DFP setup

http://www.labnol.org/internet/google-dfp-tutorial/14099/


Friday, January 4, 2013

Compare directories via diff


diff -rq dirA dirB

diff -qr dirA dirB | grep -v -e 'DS_Store' -e 'Thumbs' | 
sort > diffs.txt


http://hints.macworld.com/article.php?story=20070408062023352

Wednesday, December 19, 2012

YII framework dynamic Table Model


/**
 * CActiveRecord implementation that allows specifying
 * DB table name instead of creating a class for each table.
 *
 * Usage (assuming table 'user' with columns 'id' and 'name'):
 *
 * $userModel = DynamicActiveRecord::forTable('user');
 * //list existing users
 * foreach ($userModel->findAll() as $user)
 * echo $user->id . ': ' . $user->name . '
';
 * //add new user
 * $userModel->name = 'Pavle Predic';
 * $userModel->save();
 *
 * @author Pavle Predic
 */
class DynamicActiveRecord extends CActiveRecord
{
/**
* Name of the DB table
* @var string
*/
protected $_tableName;

/**
* Table meta-data.
* Must redeclare, as parent::_md is private
* @var CActiveRecordMetaData
*/
protected $_md;

/**
* Constructor
* @param string $scenario (defaults to 'insert')
* @param string $tableName
*/
public function __construct($scenario = 'insert', $tableName = null)
{
$this->_tableName = $tableName;
parent::__construct($scenario);
}

/**
* Overrides default instantiation logic.
* Instantiates AR class by providing table name
* @see CActiveRecord::instantiate()
* @return DynamicActiveRecord
*/
protected function instantiate($attributes)
{
return new DynamicActiveRecord(null, $this->tableName());
}

/**
* Returns meta-data for this DB table
* @see CActiveRecord::getMetaData()
* @return CActiveRecordMetaData
*/
public function getMetaData()
{
if ($this->_md !== null)
return $this->_md;
else
return $this->_md = new CActiveRecordMetaData($this);
}

/**
* Returns table name
* @see CActiveRecord::tableName()
* @return string
*/
public function tableName()
{
if (!$this->_tableName)
$this->_tableName = parent::tableName();
return $this->_tableName;
}

/**
* Returns an instance of DynamicActiveRecord for the provided DB table.
* This is a helper method that may be used instead of constructor.
* @param string $tableName
* @param string $scenario
* @return DynamicActiveRecord
*/
public static function forTable($tableName, $scenario = 'insert')
{
return new DynamicActiveRecord($scenario, $tableName);
}
}

Thursday, December 6, 2012

YII Framework - Highcharts Extension - datetime issue Resolved


$this->Widget('ext.highcharts.HighchartsWidget', array(
   'options'=>'{
      "title": { "text": "MYSQL Replication" },
      "xAxis": {
      "title": { "text": "Month" },
"type": "datetime",
            "dateTimeLabelFormats": {
                "day": "%e"  
            }
      },
      "yAxis": {
         "title": { "text": "Time" },
"type": "datetime",
        "dateTimeLabelFormats": {
                "hour": "%H"
            }
      },
      "tooltip": {
            "xDateFormat": "%Y-%m-%d"
        },      
      "series": [
{ "name": "success", "data": [[x_ms,y_ms],[x_ms,y_ms]],"pointStart": utc_ms, "pointInterval": date_ms},
         { "name": "failure", "data": [[x_ms,y_ms],[x_ms,y_ms]],"pointStart": utc_ms, "pointInterval": date_ms}
      ]
   }'
));

<script src="http://code.highcharts.com/highcharts.js"></script>

Tuesday, December 4, 2012

SoapUI for ubuntu

http://askubuntu.com/questions/198896/what-is-a-simple-free-soap-client-gui


You can still use SOAPUI
download the script from here and save it on the disk.
then from a terminal
cd /path-to-directory-where-you-downlaod-it
sudo chmod +x soapUI-x32-4_0_0.sh
sudo ./soapUI-x32-4_0_0.sh

Monday, November 5, 2012

Install and configure OAuth in Ubuntu

http://djpate.com/2010/10/07/how-to-install-oauth-support-for-php-on-ubuntu/



First of all you need to make sure you already have php-pear and php5-dev.
If you are unsure just run
1sudo apt-get install php-pear php5-dev make
now run
1sudo pecl install oauth
Personnaly I had an error while compiling
1/usr/include/php5/ext/pcre/php_pcre.h:29: fatal error: pcre.h:
To fix that just install : libpcre3-dev
1sudo apt-get install libpcre3-dev
Once it’s done just add extension=oauth.so at the end of your php.ini (located in /etc/php5/apache2/php.ini) file and restart Apache.

Wednesday, September 26, 2012

Drupal Blog Page Not Found

If you have the problem of not being able to see the Blog Module page after enabling it, and you are using Clean URL for your site, then it's *probably* because you have accidentally created a subdomain with the name 'blog' (e.g. http://blog.example.com), or you have a subdirectory named 'blog' on your website's root folder (www, htdocs or public_html). You should be able to see Drupal's Blog Module after you remove the subdomain / subdirectory with that same name.

The reason you cannot view the Blog Module at your website's URL (e.g. http://www.example.com/blog) when you have a subdomain / subdirectory with the same name is because when using Clean URL, Drupal rewrites the Blog Module address (http://www.example.com/?q=blog to http://www.example.com/blog) using .htaccess file. This causes confusion on the webserver, because when we try to access http://www.example.com/blog, it doesn't know which URL it is suppose to display. It could be the URL that Drupal has rewritten, or it could also be the subdirectory that you have in your web root folder.

The same concept also apply with all the URL Aliases that you have created with your Drupal. Make sure you don't have a folder with the same name as your aliases, or else you will get a Page Not Found error.



Thursday, September 6, 2012

Wordpress - Exclude images from showing in the_content() - Resolved

<?php
   ob_start();
   the_content('Read the full post',true);
   $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
   ob_end_clean();
   echo $postOutput;
?>

Ref. Link: http://wordpress.org/support/topic/exclude-images-from-showing-in-the_content

Wednesday, September 5, 2012

XML Sitemap generation with php and mysql


<?php
$host = "localhost"; // host name
$user = "user"; // database user name
$pass = "password"; // database password
$database = "dbname"; // database name
// connecting to database
$connect = @mysql_connect($host,$user,$pass)or die (@mysql_error());
// selecting database
@mysql_select_db($database,$connect) or die (@mysql_error());

// default header(don't delete)
header("Content-Type: text/xml;charset=iso-8859-1");
echo '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

// mytable = your content table name
$query = @mysql_query("SELECT * FROM mytable");
while($row = @mysql_fetch_array($query)){
// [url] = content url
$url = $row['url'];
// [time] = content date
$date = date("Y-m-d", $row['time']);

// NO CHANGES BELOW
echo
    '<url>
     <loc>' . $url .'</loc>
     <lastmod>'. $date .'</lastmod>
     <changefreq>daily</changefreq>
     <priority>0.8</priority>
     </url>
    ';
}
echo '</urlset>';?>



.htaccess code ( Optional )


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*)\.xml(.*) $1.php$2 [nocase]
</IfModule>



Tuesday, August 21, 2012

Reset Mysql Root Password in Xampp -- Resolved


  • Go to your xampp\mysql\bin\ folder
  • Edit my.ini and insert skip-grant-tables below [mysqld]
  • Restart MySQL
  • Set new password for your root user by running UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root' in phpMyAdmin in the mysql database (or just leave it like this if MySQL cannot be accessed from remote hosts)

Tuesday, July 17, 2012

XAMPP Apache server not working on internal network


The problem was that the Windows Firewall had port 80 blocked. To fix this, I opened Windows Firewall, clicked Change Settings, went to the Exceptions tab, and then "Add Port". I set Name to "Web Server (TCP 80)", Port Number to 80, and Protocol to TCP and that was it.

Thursday, June 28, 2012

Theming the contact form in Drupal 6


3 Different Ways

1)So I copy page.tpl.php to page-contact.tpl.php and did changes

2)A different method would be to theme the contact form not the whole page.

function YOURTHEMENAME_theme() {
  return array(
    
'contact_mail_page' => array(
      
'arguments' => array('form' => $form),
    ),         
  );
}function
YOURTHEMENAME_contact_mail_page($form) {
  
$output = drupal_render($form);
  
$output .= '
'. t('Text to add to bottom of form') .'
'
;
  return 
$output;
}

?>
 

Saturday, June 16, 2012

PHP Mail Function header to avoid spam issue


$headers = "From: \"".$from_name."\" <".$from_email.">\n";
$headers .= "To: \"".$to_name."\" <".$to_email.">\n";
$headers .= "Return-Path: <".$from_email.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/HTML; charset=ISO-8859-1\n";

mail($to, $subject, $message, $headers);

Thursday, June 14, 2012

editor auto adds

paragraph tag after save article or mod

In the administrator, go to Extentsions -> Plugin Manager -> Editor-TinyMCE
In "Parameters" panel, find "New Lines"
Change it to "BR Elements"

Sunday, June 3, 2012

Web Application Development Process

Ref: http://www.comentum.com/web-application-development-process.html


Requirements for Developing Web Applications

by Bernard Kohan

1. Roadmap Document: Defining Web Application, Purpose, Goals and Direction

(Performed by client / project owner)
This initial task is an important part of the process. It requires putting together the Web Application project goals and purpose.
This step establishes your project's clear direction and helps you focus on setting and achieving your goal.
The Roadmap Document will specify the Web Application's future plan and objectives with approximate timelines.

2. Researching and Defining Audience Scope and Security Documents

(Performed by client / project owner, or by Comentum, as a fee service)
This task requires researching the audience/users, and prospective clients (if any), and creating an Analytic Report which includes the following approximate assessments:
- Type of audience for usability purposes:
Creating Statistic Reports on the percentage of users: elementary, average, advanced, the audience ages, and gender
- Type and level of access:
Creating an Access Report, specifying users' access of Intranet, Internet, Extranet - single-level, multi-level
- Type of audience for planning the security level:
Creating a Risk Statistical Document based on users' characteristics, zone's fraud level, application's industry security breaches, and history of the audience's security breaches
- Quantitative statistics on audience:
Creating a Potential Visitors Report, broken down by reasonable periodic time frames

3. Creating Functional Specifications or Feature Summary Document

(Performed by client / project owner)
A Web Application Functionality Specifications Document is the key document in any Web Application project. This document will list all of the functionalities and technical specifications that a web application will require to accomplish. Technically, this document can become overwhelming if one has to follow the Functional Specifications rule and detail out each type of user's behavior on a very large project. However, it is worth putting forth the effort to create this document which will help prevent any future confusion or misunderstanding of the project features and functionalities, by both the project owner and developer. A typical functional specification will list every user's behavior, for example:
  • When a visitor clicks on the "Add to Cart" button from the Product Showcase page, the item is added to the visitor's shopping cart, the Product Showcase page closes and the user is taken to the Shopping Cart page which shows the new item in the cart.

If creating a functional specification document is overwhelming to you, I recommend starting out by creating a Specification Document or Feature Summary Document by either creating the sample screen shots of the web application screens or creating a document that includes a summary list of the application's features, for example:
  • Product / Inventory Summary Showcase: displays a summary of items for sale, stock number, item name, short description, one photo, price, and Add to Cart button.
  • Product / Inventory One Item Showcase: displays the detail of one inventory item: stock number, item name, long description, multiple photos (up to 10 photos), price, and Add to Cart button.

4. Third Party Vendors Identification, Analysis and Selection

(Performed by client / project owner)
This task requires researching, identifying and selection of third party vendors, products and services such as:

5. Technology Selection, Technical Specifications, Web Application Structure and Timelines

(Performed by Comentum)
This document is the blueprint of the technology and platform selection, development environment, web application development structure and framework.
The Technical Specifications Document will detail out the technology used, licenses, versions and forecasts.
The Timeline Document will identify the completion dates for the Web Application's features or modules.

6. Application Visual Guide, Design Layout, Interface Design, Wire framing

(Created by the collaboration of the project owner and Comentum)
One of the main ingredients to a successful project is to put together a web application that utilizes a user's interactions, interface and elements that have a proven record for ease of use, and provide the best user experience.
This process starts out by creating the visual guide, wire framing or simply sketching out the user interface and interactions of the web applications by Comentum's Creative and Usability teams of experts.
Once the Application Interface and Interaction Models are approved, Comentum's creative team design the interface for the web application.

7. Web Application Development

(Executed by Comentum's Development Team)
The application's Design Interface is turned over to Comentum's Development Team who take the following steps to develop the project:
  • Create the Web Application Architecture and Framework
  • Design the Database Structure
  • Develop / Customize the Web Application Module, Libraries and Classes
  • Complete the Development and Implement all Functionalities - Version 1.0

8. Beta Testing and Bug Fixing

(Executed by Comentum's Beta Testers)
Comentum's vigorous quality assurance testing help produce the most secure and reliable web applications.
Version 1.0 of the Web Application is thoroughly tested and any program bugs are addressed and fixed.

Monday, May 14, 2012

Security Checklist for PHP website - Input from $_GET, $_POST, $_COOKIE, and $_REQUEST is considered tainted.



http://markjaquith.wordpress.com/2009/09/21/php-server-vars-not-safe-in-forms-or-links/

Common example:

<form action="php echo $_SERVER['PHP_SELF']; ?>">

Another example:

<a href="php echo $_SERVER['PHP_SELF']' ?>?foo=bar">link titlea>

Here are my two rules regarding $_SERVER['PHP_SELF'] or $_SERVER['REQUEST_URI'] in forms:
  • Do not use them
  • If you use one of them, escape it with esc_url()