Skip to main content

Get Google Calendar Event List in WordPress

<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function  get_calender_events() { $params = array(); /*Get current date*/ $current_date  = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key =  "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url, ...

How do I create an observer in Magento?

How do I create an observer in Magento?

my example below uses the sales_order_place_before event which is called just before the order is saved.

Step 1) Create main module xml file

We need to create a file called Samrat_Observerexample.xml in app/etc/modules.

<?xml version="1.0"?>
<config>
    <modules>
        <Samrat_Observerexample>
            <codePool>local</codePool>
            <active>true</active>
        </Samrat_Observerexample>
    </modules>
</config>

Step 2) Create folder structure for our module

We need to create the folders where our modules code will live. To do this create the following directories:

mkdir app/code/local/Samrat/
mkdir app/code/local/Samrat/Observerexample/
mkdir app/code/local/Samrat/Observerexample/etc
mkdir app/code/local/Samrat/Observerexample/Model

Quick explaination of the module folder structure. Samrat represents the company or group, then Observerexample is our actual module. etc will contain various configuration files which instructs Magento how to read/use our module. Model contains our various Model classes which our module might use (in this case we will have a Observer.php file in the Model folder).


Step 2) Create our module’s configuration file

Each module requires a file called config.xml this file lives in app/code/local/Samrat/Observerexample/etc

<?xml version="1.0"?>
<config>
    <modules>
        <Samrat_Observerexample>
            <version>0.0.1</version>
        </Samrat_Observerexample>
    </modules>
    <global>
        <models>
            <samratobserverexample>
                <class>Observerexample_Model</class>
            </samratobserverexample>
        </models>
        <events>
            <sales_order_place_before>
                <observers>
                    <Samrat_observerexample_model_observer>
                        <type>singleton</type>
                        <class>Samrat_Observerexample_Model_Observer</class>
                        <method>logobs</method>
                    </Samrat_observerexample_model_observer>
                </observers>
            </sales_order_place_before>
        </events>
    </global>
</config>

The above code is our basic config for our model. If you stick to similar naming conventions you’ll get on by fine here.

The main code I’d like to highlight here is contained between the <events> tags. The first tag in represents our event we decided to use earlier on sales_order_place_before, so within here we are defining what to do when that event is fired. Within the <observers> tag we have the set up for our Observer. The value within <class> represents the class name of our Observer, and then the value in <method> is the method (or function) we will run when that event is fired.



Step 4) Creating our Observer.php

Now we can create our Observer and place our code inside our method we will create. To do this create a file named Observer.php in app/code/local/Samrat/Observerexample/Model and place the following code:

<?php
class Samrat_Observerexample_Model_Observer {

    public function send_email($observer) {
        //$observer contains data passed from when the event was triggered.
        //You can use this data to manipulate the order data before it's saved.
        //Uncomment the line below to log what is contained here:
        //Mage::log($observer);

        Mage::log('We just made an Observer!');
    }

}
?>



Easy as that.

Now all you need to do is clear the cache, make sure log’s are enabled in System > Configuration > Advanced > Developer > Logging and then go through the checkout and then check the logs in var/log.



https://www.nicksays.co.uk/magento-events-cheat-sheet-1-8/


Comments

Popular posts from this blog

Create Signature pad with save on database in php

Create Signature pad with save on database in php 1.create a folder images index.php ============   <!DOCTYPE >     <head>     <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />     <title>Signature Pad</title>     <script type="text/javascript" src="jquery-1.8.0.min.js"></script>     <script type="text/javascript"> $(document).ready(function () {     /** Set Canvas Size **/     var canvasWidth = 400;     var canvasHeight = 100;     /** IE SUPPORT **/     var canvasDiv = document.getElementById('signaturePad');     canvas = document.createElement('canvas');     canvas.setAttribute('width', canvasWidth);     canvas.setAttribute('height', canvasHeight);     canvas.setAttribute('id', 'canvas');     canvasDiv.appendChild(canvas);    ...

Get Google Calendar Event List in WordPress

<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function  get_calender_events() { $params = array(); /*Get current date*/ $current_date  = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key =  "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url, ...

WooCommerce Mini cart With Ajax

WooCommerce Mini cart //MINI CART SECTION   <div class="productdiv rightcart">                                                         <?php if ( ! WC()->cart->is_empty() ) : ?>     <ul class="woocommerce-mini-cart cart_list product_list_widget <?php echo esc_attr( $args['list_class'] ); ?>">         <?php             do_action( 'woocommerce_before_mini_cart_contents' );             foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {                 $_product     = apply_filters( 'woocommerce_cart_item_pro...