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, ...

Magento product search by name

<form action="" method="post">
<input class="postcode" name="postcode" type="text" id="" placeholder="Plaatsnaam + Postcode" />
<input class="aantal" name="name" type="text" id="" placeholder="Aantal m2"/>
<input type="submit" name="searchdata" value="submit" >
</form>
<?php
function getProductIdsBySearch($searchstring, $storeId) {
     $ids = array();  
     // Code to Search Product by $searchstring and get Product IDs
     $product_collection = Mage::getResourceModel('catalog/product_collection')
                  ->addAttributeToSelect('*')
                  ->addAttributeToFilter('postcode', array('like' => '%'.$searchstring.'%'))
 ->addAttributeToFilter('name', array('like' => '%'.$storeId.'%'))
                  ->load();

     foreach ($product_collection as $product) {
          $ids[] = $product->getId();

     }
    //return array of product ids
    return $ids;
}

if(isset($_POST['postcode']))
{
$cc=getProductIdsBySearch($_POST['postcode'],$_POST['name']);
$arrlength=count($cc);
 for($x=0;$x<$arrlength;$x++)
{
$model = Mage::getModel('catalog/product'); //getting product model
$_products = $model->load($cc[$x]); //getting product object for particular product id
echo $_products->getShortDescription()."<br>"; //product's short description
echo $_products->getDescription()."<br>"; // product's long description
echo $_products->getName()."<br>"; //product name
echo $_products->getPrice()."<br>";//product's regular Price
echo $_products->getSpecialPrice()."<br>"; //product's special Price
echo $_products->getProductUrl()."<br>"; //product url
echo $_products->getImageUrl()."<br>"; //product's image url
echo $_products->getSmallImageUrl()."<br>"; //product's small image url
echo $_products->getThumbnailUrl()."<br>"; //product's thumbnail image url  
}
}
?>


or

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addFieldToFilter(array(
        array('attribute'=>'postcode','like'=>$searchstring),
array('attribute'=>'area','lteq'=>$storeId),
));



Use the below code to instantiate the product collection.

$collection = Mage::getModel('catalog/product')->getCollection();

Magento products are EAV style model. So we need to add additional attributes that you want to return. Use the below codes.

$collection = Mage::getModel('catalog/product')->getCollection();
//fetch name and size into data
$collection->addAttributeToSelect('name');
$collection->addAttributeToSelect('size');

We can select the attributes as like the below code.

$collection->addAttributeToSelect('*')

There are multiple syntax for setting filters on collections:

//filter for products whose orig_price is greater than (gt) 100
$collection->addFieldToFilter(array(
        array('attribute'=>'price','gt'=>'100'),
));     

//AND filter for products whose orig_price is greater than (lt) 130
$collection->addFieldToFilter(array(
        array('attribute'=>'price','lt'=>'130'),
));

//filter for products who name is equal (eq) to Widget A, or equal (eq) to Widget B
$collection->addFieldToFilter(array(
array('attribute'=>'name','eq'=>'Widget A'),
array('attribute'=>'name','eq'=>'Widget B'),
));

foreach ($collection as $product)
{
        //var_dump($product);
        var_dump($product->getData());
}

Below are the list of some most used short conditionals:

eq – equal
neq – not equal
like – %like%
nlike – not %like%
in – in(array…)
nin – not in(array…)
notnull
null
moreq – >=
gt – >
lt – <
gteq – >=
lteq – <=

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...