Brought to you by
2BlueSolutions Creative Web Design

Friday, February 8, 2013

YiiFramework - Check If User Is Logged In (couponic)

So, I was doing a bit of customization of a Couponic template where I wanted to add a squeeze box (a future post!), but I first needed to check if a user was logged in or not. I didn't want a logged in user to see the squeeze box so I needed to figure out how the framework checked if a user is logged in. Well, it's pretty simple (I've included a quick and dirty write to the browser console log for quick debugging)
 <?php $isUser = Yii::app()->user->checkAccess('user');
  if(!$isUser){ ?>
   <script>
    console.log("NOT A USER!!!!!!!!!!!!");
   </script>
  <?php }else{ ?>
   <script>
    console.log("IS A USER!!!!!!!!!!!!");
   </script> 
  <?php } ?>

Monday, February 4, 2013

Virtuemart: Different Free Shipping Amount For Different Countries

How to adapt Virtuemart's Minimum Amount For Free Shipping so it can handle different amounts for different countries:

Now, before we begin, the usual warning:  Backup the files you are going to be working with.  This is a hack of the global.php file to allow different free shipping amounts for different countries.

The file you'll be working with:  /administrator/components/com_virtuemart/global.php

First, in the Virtuemart administration page, go to the Store -> Edit Store page and set the base amount you want to use for 'free shipping'.  Usually, this should be the value you set for the most commonly used free amount you want to use (ie. your home country).

Now, open up global.php, and search for:

$vendor_freeshipping = $db->f("vendor_freeshipping");
The example will show how to detect for a country and hard-code in a new value for free-shipping. Ie. The amount set in the VM Admin page will be the base amount for free shipping in Canada. First, I'll show what to do when you want to eliminate free shipping to all countries, but one.

if ($_SESSION['auth']["country"] != "CAN") {
$vendor_freeshipping = "0"; } else { $vendor_freeshipping = $db->f("vendor_freeshipping"); }

So, what happens is the script checks to see what country it is.  If it is not Canada, then free shipping is negated (set to zero).  If it is Canada, then free shipping is set to whatever is in the VM admin backend.

Now, say you want the USA to have a different value before free shipping applies.  This is what that code would look like:

if ($_SESSION['auth']["country"] == "USA") {
$vendor_freeshipping = "75"; } else { $vendor_freeshipping = $db->f("vendor_freeshipping"); }

That's it.  Now, in the above example, if the country being shipped to is the USA, then the free shipping minimum is set to $75.  Otherwise, it is set to whatever you set in the Virtuemart backend.