woocommerce: detecting order complete / on order completion

woocommerce: detecting order complete / on order completion

How to programmatically detect that a WooCommerce order has completed. In essence, “On order complete”. Easily detect all the status changes an order can go through with actions.

I’ve spent half a day trying to get this working properly. If you want to detect a WooCommerce order being completed in your plugin or theme so as to take an action, you can do so using the woocommerce_order_status_completed action. On order complete I want to change some metadata on some posts automatically, here’s how it’s done:

function mysite_woocommerce_order_status_completed( $order_id ) {
error_log( "Order complete for order $order_id", 0 );
}
add_action( 'woocommerce_order_status_completed',
'mysite_woocommerce_order_status_completed' );

WooCommerce do make available a list of all WooCommerce actions, filters and hooks. However, it’s slightly obscure the way that this part is explained on that page; It’s shown as “woocommerce_order_status_.$new_status->slug“. So what it means is there’s an action for each of the order statuses:

  • woocommerce_order_status_pending
  • woocommerce_order_status_failed
  • woocommerce_order_status_on-hold
  • woocommerce_order_status_processing
  • woocommerce_order_status_completed
  • woocommerce_order_status_refunded
  • woocommerce_order_status_cancelled

Here they are again as actions:

function mysite_pending($order_id) {
error_log("$order_id set to PENDING", 0);
}
function mysite_failed($order_id) {
error_log("$order_id set to FAILED", 0);
}
function mysite_hold($order_id) {
error_log("$order_id set to ON HOLD", 0);
}
function mysite_processing($order_id) {
error_log("$order_id set to PROCESSING", 0);
}
function mysite_completed($order_id) {
error_log("$order_id set to COMPLETED", 0);
}
function mysite_refunded($order_id) {
error_log("$order_id set to REFUNDED", 0);
}
function mysite_cancelled($order_id) {
error_log("$order_id set to CANCELLED", 0);
}

add_action( ‘woocommerce_order_status_pending’, ‘mysite_pending’);
add_action( ‘woocommerce_order_status_failed’, ‘mysite_failed’);
add_action( ‘woocommerce_order_status_on-hold’, ‘mysite_hold’);
// Note that it’s woocommerce_order_status_on-hold, not on_hold.
add_action( ‘woocommerce_order_status_processing’, ‘mysite_processing’);
add_action( ‘woocommerce_order_status_completed’, ‘mysite_completed’);
add_action( ‘woocommerce_order_status_refunded’, ‘mysite_refunded’);
add_action( ‘woocommerce_order_status_cancelled’, ‘mysite_cancelled’);

Another useful action is woocommerce_payment_complete, called after the payment has been taken for an order. This is useful if you want to perform some automated task after payment has been taken:

function mysite_woocommerce_payment_complete( $order_id ) {
error_log( "Payment has been received for order $order_id", 0 );
}
add_action( 'woocommerce_payment_complete',
'mysite_woocommerce_payment_complete' );

I hope this saves someone some time!

Mac – Useful Shortcodes

The Go to Folder feature
The Finder has its Go to Folder feature, which can be used for accessing hidden directories, but similar to the Terminal, you can drag a file or folder here to reveal its full path.

To do this, open a new Finder window by pressing Command-N, and then press Shift-Command-G to reveal the Go to Folder panel for the new window. Then drag a target file from another window to the Go to Folder text field, where it will be converted to a full text path that you can select and copy. Unfortunately you cannot drag a file from the same window once the Go to Folder panel is open, but you can drag from the desktop or another Finder window.

Abri.fr

Real Estate in France.
http://www.abri.fr
Responsive Design

Ales

Web app Project for ALES Group.

Drive Sales representative

Reporting to the Group

List products or the group

alesreps
alespassword
aleslogs
ales

Scrap all emails with eMacros from a website

This page is to explain how to scrap all emails from many pages.
Lets take this website as example: www.immostreet.com

This a french website with a plenty of email I would like to scrap using iMacros.

First install iMacros for Firefox https://addons.mozilla.org/fr/firefox/addon/imacros-for-firefox/

Then Create a new Macro in Javascript.

 

The code is here:

 

// settings
var pageBegin = 1;
var pageEnd = 10;
var user = "alan";

//var folderName = "/Users/alan/GoogleDrive/Projets/GooPlus/Projetsencours/agence_immo";
var folderName = "*";
var fileName = pageBegin+"_to_"+pageEnd+"_"+user+"_email_immos.txt";
var urlToGo = "http://www.immostreet.com/Agency/Search?place=%C3%8Ele-de-France&place_id=4832011&currentPage=";



//code
for (var page = pageBegin; page < pageEnd; page++) {
  var macro = "CODE:";
  macro += "URL GOTO=" + urlToGo+page+"\n";
  iimPlay(macro);

  for (var i = 1; i < 11; i++) {
    var macro = "CODE:";
         macro += "TAG POS="+i+" TYPE=A ATTR=CLASS:mailto&&TXT:* EXTRACT=TXT"+"\n";
         macro += "SAVEAS TYPE=EXTRACT FOLDER="+folderName+" FILE=" + fileName;
    iimPlay(macro);
  }
}

The iMacro is set as javaScript

Demo:

test

Les nouvelles régions de france

Voici les nouvelles régions de France au format excel.

Les données sous forme de tableau sont ici.

Numéro Nom Ancienne Région Nouvelle région
67 Bas-Rhin Alsace Grand est
68 Haut-Rhin Alsace Grand est
24 Dordogne Aquitaine Nouvelle Aquitaine
33 Gironde Aquitaine Nouvelle Aquitaine
40 Landes Aquitaine Nouvelle Aquitaine
47 Lot-et-Garonne Aquitaine Nouvelle Aquitaine
64 Pyrénées-Atlantiques Aquitaine Nouvelle Aquitaine
3 Allier Auvergne Auvergne Rhones alpes
15 Cantal Auvergne Auvergne Rhones alpes
43 Haute-Loire Auvergne Auvergne Rhones alpes
63 Puy-de-Dôme Auvergne Auvergne Rhones alpes
14 Calvados Basse-Normandie Normandie
61 Orne Basse-Normandie Normandie
21 Côte d’Or Bourgogne Bourgogne Franche-Compté
58 Nièvre Bourgogne Bourgogne Franche-Compté
71 Saône-et-Loire Bourgogne Bourgogne Franche-Compté
89 Yonne Bourgogne Bourgogne Franche-Compté
22 Côtes d’Armor Bretagne Bretagne
29 Finistère Bretagne Bretagne
35 Ille-et-Vilaine Bretagne Bretagne
56 Morbihan Bretagne Bretagne
18 Cher Centre Centre-Val de Loire
28 Eure-et-Loir Centre Centre-Val de Loire
36 Indre Centre Centre-Val de Loire
37 Indre-et-Loire Centre Centre-Val de Loire
45 Loiret Centre Centre-Val de Loire
41 Loir-et-Cher Centre Centre-Val de Loire
8 Ardennes Champagne Grand EST
10 Aube Champagne Grand EST
52 Haute-Marne Champagne Grand EST
51 Marne Champagne Grand EST
2A Corse du Sud Corse Corse
2B Haute-Corse Corse Corse
25 Doubs Franche-Comté Bourgogne Franche-Compté
70 Haute-Saône Franche-Comté Bourgogne Franche-Compté
39 Jura Franche-Comté Bourgogne Franche-Compté
90 Territoire-de-Belfort Franche-Comté Bourgogne Franche-Compté
27 Eure Haute-Normandie Normandie
76 Seine-Maritime Haute-Normandie Normandie
91 Essonne Ile-de-France Ile-de-France
92 Hauts-de-Seine Ile-de-France Ile-de-France
75 Paris Ile-de-France Ile-de-France
77 Seine-et-Marne Ile-de-France Ile-de-France
93 Seine-St-Denis Ile-de-France Ile-de-France
94 Val-de-Marne Ile-de-France Ile-de-France
95 Val-d’Oise Ile-de-France Ile-de-France
78 Yvelines Ile-de-France Ile-de-France
11 Aude Languedoc Occitanie
30 Gard Languedoc Occitanie
34 Hérault Languedoc Occitanie
48 Lozère Languedoc Occitanie
66 Pyrénées-Orientales Languedoc Occitanie
19 Corrèze Limousin Nouvelle Aquitaine
23 Creuse Limousin Nouvelle Aquitaine
87 Haute-Vienne Limousin Nouvelle Aquitaine
54 Meurthe-et-Moselle Lorraine Grand EST
55 Meuse Lorraine Grand EST
57 Moselle Lorraine Grand EST
88 Vosges Lorraine Grand EST
9 Ariège Midi-Pyrénées Occitanie
12 Aveyron Midi-Pyrénées Occitanie
32 Gers Midi-Pyrénées Occitanie
31 Haute-Garonne Midi-Pyrénées Occitanie
65 Hautes-Pyrénées Midi-Pyrénées Occitanie
46 Lot Midi-Pyrénées Occitanie
81 Tarn Midi-Pyrénées Occitanie
82 Tarn-et-Garonne Midi-Pyrénées Occitanie
59 Nord Nord Hauts-de-France
62 Pas-de-Calais Nord Hauts-de-France
50 Manche Normandie Normandie
44 Loire-Atlantique Pays-de-la-Loire Pays-de-la-Loire
49 Maine-et-Loire Pays-de-la-Loire Pays-de-la-Loire
53 Mayenne Pays-de-la-Loire Pays-de-la-Loire
72 Sarthe Pays-de-la-Loire Pays-de-la-Loire
85 Vendée Pays-de-la-Loire Pays-de-la-Loire
2 Aisne Picardie Hauts-de-France
60 Oise Picardie Hauts-de-France
80 Somme Picardie Hauts-de-France
16 Charente Poitou-Charente Nouvelle Aquitaine
17 Charente Maritime Poitou-Charente Nouvelle Aquitaine
79 Deux-Sèvres Poitou-Charente Nouvelle Aquitaine
86 Vienne Poitou-Charente Nouvelle Aquitaine
4 Alpes de Haute-Provence Provence-Alpes-Côte d’Azur Provence-Alpes-Côte d’Azur
6 Alpes-Maritimes Provence-Alpes-Côte d’Azur Provence-Alpes-Côte d’Azur
13 Bouches du Rhône Provence-Alpes-Côte d’Azur Provence-Alpes-Côte d’Azur
5 Hautes-Alpes Provence-Alpes-Côte d’Azur Provence-Alpes-Côte d’Azur
83 Var Provence-Alpes-Côte d’Azur Provence-Alpes-Côte d’Azur
84 Vaucluse Provence-Alpes-Côte d’Azur Provence-Alpes-Côte d’Azur
1 Ain Rhône-Alpes Auvergne Rhones alpes
7 Ardèche Rhône-Alpes Auvergne Rhones alpes
26 Drôme Rhône-Alpes Auvergne Rhones alpes
74 Haute-Savoie Rhône-Alpes Auvergne Rhones alpes
38 Isère Rhône-Alpes Auvergne Rhones alpes
42 Loire Rhône-Alpes Auvergne Rhones alpes
69 Rhône Rhône-Alpes Auvergne Rhones alpes
73 Savoie Rhône-Alpes Auvergne Rhones alpes

asas

Magento vs Drupal

Cette impression d’écran remet en question la crédibilité du CMS Magento.

La page d’accueil du site de Magento a été mise en place grâce au CMS DRUPAL. Vous pouvez vérifiez par vous même sur le site officiel de Magento !

 

magento_drupal

Laravel 5.3 and AngularJS CRUD – Search and Pagination.

It is time to create a CRUD(Create, Read, Update, Delete) using AngularJS and Laravel 5. In Following step by step you can create web application of create, edit, delete, lists, search with pagination of items modules. In this post through you can make simple crud, search and pagination module and easily use in your laravel project. I am going to show preview of items module that we will do using angularJS and Laravel 5.3.

 

Preview

laravel-angular

 

Step 1: Create items table and module

In First step we have to create migration for items table using Laravel 5 php artisan command, so first fire bellow command:

In First step we have to create migration for items table using Laravel 5 php artisan command, so first fire bellow command:

php artisan make:migration create_items_table

After this command you will find one file in following path database/migrations and you have to put bellow code in your migration file for create items table.

 

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateItemsTable extends Migration
{
    public function up()
    {
        Schema::create('items', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->text('description');
            $table->timestamps();
        });
    }
    public function down()
    {
        Schema::drop("items");
    }
}

After craete “items” table you should craete Item model for items, so first create file in this path app/Item.php and put bellow content in item.php file:

app/Item.php

namespace App;
use Illuminate\Database\Eloquent\Model;
use DB;
class Item extends Model
{
    public $fillable = ['title','description'];
}

Step 2: Create controller

Ok, now we should create new controller as ItemController in this pathapp/Http/Controllers/ItemController.php. this controller will manage all lists, create, edit, delete ,search and pagination request and return json response, so put bellow content in controller file:

app/Http/Controllers/ItemController.php

 

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Item;
class ItemController extends Controller
{
    public function index(Request $request)
    {
        $input = $request->all();
        if($request->get('search')){
            $items = Item::where("title", "LIKE", "%{$request->get('search')}%")
                ->paginate(5);      
        }else{
		  $items = Item::paginate(5);
        }
        return response($items);
    }
    public function store(Request $request)
    {
    	$input = $request->all();
        $create = Item::create($input);
        return response($create);
    }
    public function edit($id)
    {
        $item = Item::find($id);
        return response($item);
    }
    public function update(Request $request,$id)
    {
    	$input = $request->all();
        Item::where("id",$id)->update($input);
        $item = Item::find($id);
        return response($item);
    }
    public function destroy($id)
    {
        return Item::where('id',$id)->delete();
    }
}

Step 3: Route file

In this step you have to add some route in your route file. so first we will add resource route for items module and another one for templates route. this templates route through we will get html template for our application, so put the bellow content in route file:

routes/web.php

Route::get('/', function () {
    return view('app');
});
Route::group(['middleware' => ['web']], function () {
    Route::resource('items', 'ItemController');
});
// Templates
Route::group(array('prefix'=>'/templates/'),function(){
    Route::get('{template}', array( function($template)
    {
        $template = str_replace(".html","",$template);
        View::addExtension('html','php');
        return View::make('templates.'.$template);
    }));
});

Step 4: use AngularJS

Now we will manage AngularJS route and controller, so first cretae “app” directory in your public folder(public/app) and create route.js(public/app/route.js) file for write all angular js. and put the bellow code in that file.

route.js

var app =  angular.module('main-App',['ngRoute','angularUtils.directives.dirPagination']);
app.config(['$routeProvider',
    function($routeProvider) {
        $routeProvider.
            when('/', {
                templateUrl: 'templates/home.html',
                controller: 'AdminController'
            }).
            when('/items', {
                templateUrl: 'templates/items.html',
                controller: 'ItemController'
            });
}]);

now we have to create one folder in your app folder “controllers” and create one file “ItemController.js”(public/app/controllers/ItemController.js) file in that folder.

ItemController.js

app.controller('AdminController', function($scope,$http){
  $scope.pools = [];
});
app.controller('ItemController', function(dataFactory,$scope,$http){
  $scope.data = [];
  $scope.libraryTemp = {};
  $scope.totalItemsTemp = {};
  $scope.totalItems = 0;
  $scope.pageChanged = function(newPage) {
    getResultsPage(newPage);
  };
  getResultsPage(1);
  function getResultsPage(pageNumber) {
      if(! $.isEmptyObject($scope.libraryTemp)){
          dataFactory.httpRequest('/items?search='+$scope.searchText+'&page='+pageNumber).then(function(data) {
            $scope.data = data.data;
            $scope.totalItems = data.total;
          });
      }else{
        dataFactory.httpRequest('/items?page='+pageNumber).then(function(data) {
          $scope.data = data.data;
          $scope.totalItems = data.total;
        });
      }
  }
  $scope.searchDB = function(){
      if($scope.searchText.length >= 3){
          if($.isEmptyObject($scope.libraryTemp)){
              $scope.libraryTemp = $scope.data;
              $scope.totalItemsTemp = $scope.totalItems;
              $scope.data = {};
          }
          getResultsPage(1);
      }else{
          if(! $.isEmptyObject($scope.libraryTemp)){
              $scope.data = $scope.libraryTemp ;
              $scope.totalItems = $scope.totalItemsTemp;
              $scope.libraryTemp = {};
          }
      }
  }
  $scope.saveAdd = function(){
    dataFactory.httpRequest('items','POST',{},$scope.form).then(function(data) {
      $scope.data.push(data);
      $(".modal").modal("hide");
    });
  }
  $scope.edit = function(id){
    dataFactory.httpRequest('items/'+id+'/edit').then(function(data) {
    	console.log(data);
      	$scope.form = data;
    });
  }
  $scope.saveEdit = function(){
    dataFactory.httpRequest('items/'+$scope.form.id,'PUT',{},$scope.form).then(function(data) {
      	$(".modal").modal("hide");
        $scope.data = apiModifyTable($scope.data,data.id,data);
    });
  }
  $scope.remove = function(item,index){
    var result = confirm("Are you sure delete this item?");
   	if (result) {
      dataFactory.httpRequest('items/'+item.id,'DELETE').then(function(data) {
          $scope.data.splice(index,1);
      });
    }
  }
});

we have to create another folder “helper” in app directory for myHelper.js(public/app/helper/myHelper.js)file because that file will help to define helper function.

myHelper.js

 

function apiModifyTable(originalData,id,response){
    angular.forEach(originalData, function (item,key) {
        if(item.id == id){
            originalData[key] = response;
        }
    });
    return originalData;
}

create one another folder “packages” and create file dirPagination.js(public/app/packages/dirPagination.js) and put code of following link:

dirPagination.js

Ok, at last you have create another one folder call “services” and create file myServices.js(public/app/services/myServices.js).

myServices.js

app.factory('dataFactory', function($http) {
  var myService = {
    httpRequest: function(url,method,params,dataPost,upload) {
      var passParameters = {};
      passParameters.url = url;
      if (typeof method == 'undefined'){
        passParameters.method = 'GET';
      }else{
        passParameters.method = method;
      }
      if (typeof params != 'undefined'){
        passParameters.params = params;
      }
      if (typeof dataPost != 'undefined'){
        passParameters.data = dataPost;
      }
      if (typeof upload != 'undefined'){
         passParameters.upload = upload;
      }
      var promise = $http(passParameters).then(function (response) {
        if(typeof response.data == 'string' && response.data != 1){
          if(response.data.substr('loginMark')){
              location.reload();
              return;
          }
          $.gritter.add({
            title: 'Application',
            text: response.data
          });
          return false;
        }
        if(response.data.jsMessage){
          $.gritter.add({
            title: response.data.jsTitle,
            text: response.data.jsMessage
          });
        }
        return response.data;
      },function(){
        $.gritter.add({
          title: 'Application',
          text: 'An error occured while processing your request.'
        });
      });
      return promise;
    }
  };
  return myService;
});

Step 5: Create View

This is a last step and you have to create first app.blade.php file for theme setting, so let’s create app.blade.php(resources/views/app.blade.php) and put following code :

app.blade.php

Get File.

Ok, now we need to create templates folder in views folder and need to add three html file, i am going to create that so give name properly and add that.

1.resources/views/templates/home.html

<h2>Welcome to Dashboard</h2>

2.resources/views/templates/items.html

Get File

3.resources/views/templates/dirPagination.html

Get File.

 

Step 6: File .env must be correctly setup

The data from database should be correctly set.

 

Step 6: Lauch Migration

We now need to load data into the database. Data & tables.

php artisan migrate