Pages

Showing posts with label add. Show all posts
Showing posts with label add. Show all posts

Friday, October 4, 2013

HTACCESS-Add MIME Type

Sometimes some MIME types are not present in default Apache Server configurations.But we may need to add them to our server so that we can perform operation's such as gzip compression,add them to browser caching etc

Recently I came across one such issue where I had to add a font type called "woff" to the same i added the same as follows

 <IfModule mod_mime.c>  
   AddType application/x-font-woff woff  
 </Ifmodule>  

Wednesday, October 2, 2013

PHP-Version Check code

 if (version_compare(phpversion(), '5.0.0', '>=') !== true) {  
   exit('This website runs with PHP5... You version is <b>' . phpversion() . '</b>.Please upgrade');  
 }  

Tuesday, December 11, 2012

Oscommerce Add products to cart manually

In order to add products manually by Id or customize cart manually in OSCommerce

we need to first include the following file

require("includes/application_top.php")

What  this does is automatically includes the following class

require(DIR_WS_CLASSES . 'shopping_cart.php');(line 126)

and instantiates an object of class

if (!tep_session_is_registered('cart') || !is_object($cart)) {
    tep_session_register('cart');
    $cart = new shoppingCart; 
} 
or you can yourself include these files and create an object
But for any action in oscommerce I prefer to include application_top.php
If you are building up a new cart add
$cart->reset();
This will reset your cart which is only required if you are planning to add a new cart in my case I was sending all Items from another website to my oscommerce website so I decided to reset cart first

Now let us suppose we have item information in an array $items

foreach($items as $item)
{
       $attributes = isset($HTTP_POST_VARS['id']) ? $HTTP_POST_VARS['id'] : '';
       $cart->add_cart($item['id'],$item['quant'],$attributes);
      //In case cart is not empty and you want to add quantity to an item
      $cart->add_cart(
$item['id'], $cart->get_quantity('$item['id']')+1);
}

Then add the following lines
//Cleans any product with quantity zero
$cart->cleanup();
//Calculates the weight and total cost in all finalizes your cart
$cart->calculate();

That's All

Thursday, November 8, 2012

Add Metaboxes and Metafields to your wordpress posts

Add Metaboxes and metafields to your wordpress posts


 add_action('add_meta_boxes','mypost_add_custom_box');  
 add_action('save_post','myplugin_save_postdata');  
 function mypost_add_custom_box() {  
   add_meta_box(  
     'myplugin_sectionid',  
     __('Post Type Selection','myplugin_textdomain'),  
     'myplugin_inner_custom_box',  
     'post'  
   );  
 }  
 function myplugin_inner_custom_box( $post ) {  
  wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );  
  // The actual fields for data entry  
  $scheckval=esc_attr(get_post_meta($post->ID,'slider_post',true));  
  $pcheckval=esc_attr(get_post_meta($post->ID,'popular_post',true));  
  if($scheckval=='on')  
  echo '<input type="checkbox" id="myplugin_slider_field" name="myplugin_slider_field" checked="checked"/>';  
  else  
  echo '<input type="checkbox" id="myplugin_slider_field" name="myplugin_slider_field"/>';  
  echo '<label for="myplugin_slider_field">';  
     _e("Slider Post", 'myplugin_sdomain' );  
  echo '</label> ';  
  if($pcheckval=='on')  
  echo '<input type="checkbox" id="myplugin_popular_field" name="myplugin_popular_field" checked="checked"/>';  
  else  
  echo '<input type="checkbox" id="myplugin_popular_field" name="myplugin_popular_field"/>';  
  echo '<label for="myplugin_popular_field">';  
     _e("Popular Post", 'myplugin_pdomain' );  
  echo '</label>';  
 }  
 /* When the post is saved, saves our custom data */  
 function myplugin_save_postdata( $post_id ) {  
  // verify if this is an auto save routine.  
  // If it is our form has not been submitted, so we dont want to do anything  
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )  
    return;  
  // verify this came from the our screen and with proper authorization,  
  // because save_post can be triggered at other times  
  if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) )  
    return;  
  // Check permissions  
  if ( 'page' == $_POST['post_type'] )  
  {  
   if ( !current_user_can( 'edit_page', $post_id ) )  
     return;  
  }  
  else  
  {  
   if ( !current_user_can( 'edit_post', $post_id ) )  
     return;  
  }  
  // OK, we're authenticated: we need to find and save the data  
  if($_POST['myplugin_slider_field']=='on')  
  $smydata=$_POST['myplugin_slider_field'];  
  else  
  $smydata='off';  
  if($_POST['myplugin_popular_field']=='on')  
  $pmydata=$_POST['myplugin_popular_field'];  
  else  
  $pmydata='off';  
  update_post_meta($post_id,'slider_post',$smydata);  
  update_post_meta($post_id,'popular_post',$pmydata);  
 }