News:

Support the VirtueMart project and become a member

Main Menu

Cart Page Fields & Modifications

Started by PRO, August 15, 2012, 15:10:06 PM

Previous topic - Next topic

PRO

Here are some fields for modifying the cart page to make it more user friendly.

I use these fields to make my own "checkout steps"

<?php if (empty($this->cart->BT)){ ?> What you put here will be shown when NO billing address is completed<?php }?>

<?php if (!empty($this->cart->BT)){ ?> This shows AFTER the billing Address is completed <?php }?>

<?php if ($this->cart->cartData['paymentName'] == 'No payment selected') {?> This shows when the payment has NOT been selected<?php }?>
^^^ "No payment selected" is English, so change it to suit your language

<?php if ($this->cart->cartData['paymentName'] != 'No payment selected') {?> AFTER Payment Has Been Selected<?php }?>
^^ Same language applies here.


This code will change the text from "Add Your Billing" to Edit Your Billing, if the billing is already filled in.
      <?php if (empty($this->cart->BT)){ ?>
      <a class="details bold font14 m4" href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=BT',$this->useXHTML,$this->useSSL) ?>">
      Add Your Billing Address
      </a>   <?php } ?>
<?php if (!empty($this->cart->BT)){ ?>
      <a class="details bold font14 m4" href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=BT',$this->useXHTML,$this->useSSL) ?>">
      Edit Your Billing Address
      </a>   <?php } ?>

This Code will display "Shipping to a Different Address?"  when the billing is filled in, but NOT the shipping.

      <?php if ((!empty($this->cart->BT)) && (empty($this->cart->ST))){ ?>
      <a class="details bold font14 m4" href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=ST&virtuemart_user_id[]='.$this->cart->lists['current_id'],$this->useXHTML,$this->useSSL) ?>">
      Shipping to a different address? </a><?php } ?>

Displays "Edit Your Shipping Address" When its already filled in

      <?php if(!empty($this->cart->STaddress['fields'])){ ?>
      <a class="details bold font14 m4" href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=ST&virtuemart_user_id[]='.$this->cart->lists['current_id'],$this->useXHTML,$this->useSSL) ?>">
      Edit Your Shipping Address
      </a> <?php }?>


A couple ways of NOT displaying taxes & calculation rules when billing address is not filled in. BUT, the total will include the tax amount, but can also be wrapped.

<?php if (!empty($this->cart->BT)){ ?>
WRAP the calculation in this code
?>

OR: You can set the rule to 0 , if no billing address is filled in.

<?php foreach($this->cart->cartData['taxRulesBill'] as $rule){ ?>
      <?php if (empty($this->cart->BT)){ $rule=Null;}?>
         <tr class="sectiontableentry<?php $i ?>">
            <td colspan="4" align="right"><?php echo $rule['calc_name'] ?> </td>
            <?php if ( VmConfig::get('show_tax')) { ?>
            <td align="right"><?php echo $this->currencyDisplay->createPriceDiv($rule['virtuemart_calc_id'].'Diff','', $this->cart->pricesUnformatted[$rule['virtuemart_calc_id'].'Diff'],false); ?> </td>
             <?php } ?>
            <td align="right"><?php ?> </td>
            <td align="right"><?php echo $this->currencyDisplay->createPriceDiv($rule['virtuemart_calc_id'].'Diff','', $this->cart->pricesUnformatted[$rule['virtuemart_calc_id'].'Diff'],false); ?> </td>
         </tr>
         <?php
         if($i) $i=1; else $i=0;
      }
?>

This code <?php if (empty($this->cart->BT)){ $rule=Null;}?>   sets the rule to Null if the billing is not filled in



If the billing address is not filled in, you can subtract the tax from the total. To show the total without tax.
<?php if (empty($this->cart->BT)){$this->cart->pricesUnformatted['billTotal']=$this->cart->pricesUnformatted['billTotal']-$this->cart->pricesUnformatted['billTaxAmount'];}?> <?php echo $this->currencyDisplay->createPriceDiv('billTotal','', $this->cart->pricesUnformatted['billTotal'],false); ?>

THIS code will display the "Confirm order button" where you want it. ONLY when the billing & payment has been filled in
<?php if ((!empty($this->cart->BT))&& ($this->cart->cartData['paymentName'] != 'No payment selected') ){
echo '<h1 class="bottom10 border" style="width:180px;">';
         echo $this->checkout_link_html;
         $text = JText::_('COM_VIRTUEMART_ORDER_CONFIRM_MNU');
         echo '</h1>';

}?>

Same code as above, but checks if "terms of service are checked"
<?php if (((!empty($this->cart->BT))&& ($this->cart->cartData['paymentName'] != 'No payment selected') )&& ($this->cart->tosAccepted)){
echo '<h1 class="bottom10 border" style="width:180px;">';
         echo $this->checkout_link_html;
         $text = JText::_('COM_VIRTUEMART_ORDER_CONFIRM_MNU');
         echo '</h1>';



Choose Payment Page
Auto select payment method.
http://forum.virtuemart.net/index.php?topic=108974


UPDATED::: still working
Code below will be for improvements while using the native "1 page checkout" 


To hide the payment form when a payment has already been set. It will also display the "edit payment" link

cart/default_pricelist.php
change this
<?php if (!empty($this->layoutName) && $this->layoutName == 'default') {
if (VmConfig::get('oncheckout_opc', 0))) {

to this
<?php if (!empty($this->layoutName) && $this->layoutName == 'default') {
if ((VmConfig::get('oncheckout_opc', 0))&& ($this->cart->cartData['paymentName'] == 'No payment selected')) {

I was getting problems with checking for billing address when default country is set.
So I wrote this function

<?php function valBT($items){
      foreach($items['fields'] as $item){
      if ($item['name']!='address_1') continue;
      if ($item['name']=='address_1' && !empty($item['value']) ){return true;}
      else return false;
      }} ?>

Then you can check if the billing is empty like this
<?php if (!valBT($this->cart->BTaddress)){ ?>This is when it is empty<?php }?>
& when it is not empty
<?php if (valBT($this->cart->BTaddress)){ ?>This is when billing is filled in <?php }?>

You can also use this native function to test if all is filled in, billing, shipment method, and payment method
<?php  if ($this->cart->getDataValidated()){ ?> This is when its all selected <?php }?>
or
<?php  if (!$this->cart->getDataValidated()){ ?> This is when it's missing something<?php }?>

Test if the billing & shipping address is the same
<?php if ($this->cart->ST==$this->cart->BT) { ?> This is when they are the same <?php } ?>

or if different
<?php if ($this->cart->ST!=$this->cart->BT) { ?> This is when they are the same <?php } ?>













Ffragrances

#1


You seem to have an excellent grasp on the PHP required to make very important corrections on the cart page. I would say this would cross over to just about any other page as well, as long as you  know what and where the "params" are. I was wondering if you might be kind enough to assist me with this one. I am just learning PHP and some Javascript, but slowly as I am very busy with many other things.

I have a test upgrade site that I am close to finishing in a sub directory while my old site runs live until I can finally get this one dialed in. Here is what I am trying to do.

I migrated the old site to the latest versions of both Joomla 2.5 and VM2. Server PHP 5.3+. I have purchased the USPS module that was developed by members of the VM team and it seems to be functioning well. I also setup, as I was advised to do, the generic shipping module for free shipping which also works, except that the customer still has too go to the select shipment page in order to select the Free Shipping option. In previous versions of VM the core setup under Shop Configuration had the option to set up free shipping and so no matter what modules you run, or how many (I have 3 total), the core would automatically halt the output of the other modules and auto select the Free Shipping option for the customer once they had purchased the correct preset amount of product. I will also have a copy of the generic shipping module setup just to list Local Pick or Delivery for my local customers in my zip code to select.

It seems that is not possible with the current version unless the output of all but the free module setup is running. So, the USPS module does not have a Max. dollar amount param. that you can set so the auto function will not work. So yes the customer can indeed go to the next page and select free shipping, but I would like to make it at least echo some text in the cart that their order now qualified for the free shipping, and if they would please go and select it, since I cannot set it to auto select until either the developers add that older function to VM2, or they add a max param. to the USPS module to stop it's output when that max is met, and leaving the other remaining module to be auto selected by VM2's core settings.

So essentially I need an IF "freeshipping" is active, echo or post the a message on the cart that their "Order Has Qualified for Free Shipping but need to select it", so as to cut back on any confusion and potential loss of business when people do not see the Free Shipping immediately and decide to just leave the cart and the site.

I have a basic understanding of what your code means and how it works but not exactly where or what "params" to use etc.. I thought you might be kind enough to share your more advanced knowledge and help a brother out... It never hurts to ask.

Current setup:

Shipping Modules;


USPS Module Settings;


Free Shipping Module Settings;


Current Cart Summary Output;


What I would like to get until maybe someone fixes the core code or makes additional code changes to the plugins;


Gave as much detail as I thought someone might need. Hopefully you or someone will be kind enough to assist or point me in the right direction to repair this missing setup feature form the older version of VM.

Thanks in advance, :)

PRO

<?php if ($this->cart->pricesUnformatted['salesPrice']>=60){echo 'Your Order Qualifies for Free Shipping';}?>

szbstvn

It s great!

I would like the BT and ST address add/mod on the cart page but without button! Only two form and the shoppers can save these data togheter with all page. This way maybe easier than click to buttons step the other page and back.

Somebody can help me?


Ffragrances

#4
Quote from: PRO on October 10, 2012, 17:18:40 PM
<?php if ($this->cart->pricesUnformatted['salesPrice']>=60){echo 'Your Order Qualifies for Free Shipping';}?>

That is awesome, and worked great! Thank you so much. SO now I just have to get rid of that text once they have selected the Free Shipping. So far I have tried this, but I believe I am using it incorrectly:

I put this in the line below the code that you gave me to use...

<?php if ($this->cart->cartData['shipmentName']=='Free Shipping')echo str_replace("Your Order Qualifies for Free Shipping. Please Select Free Shipping using the link on the left."," ","Your Order Qualifies for Free Shipping. Please Select Free Shipping using the link on the left.") ?>

Of course it is not working.. LOL. Or should I use something like this in the default.php instead of the default_pricelist.php. I guess I am looking to scan the page for that string of text and remove it. I am trying to learn slowly. Working on this is helping me pick up on a few things. Especially when breaking down what code snippets you have provided. One day I will learn all of this.... :)

I also tried this  to test but it of course does not work either. Obviously I am a bit off here.. hmmmm ...LOL

<?php
$oldphrase = "Your Order Qualifies for Free Shipping. Please Select Free Shipping using the link on the left";
$newphrase = ("Test");
                if ($this->cart->cartData['shipmentName']=='Free Shipping') echo str_replace($oldphrase,$newphrase,$oldphrase) ?>

PRO

Quote from: Ffragrances on October 10, 2012, 23:45:05 PM
Quote from: PRO on October 10, 2012, 17:18:40 PM
<?php if ($this->cart->pricesUnformatted['salesPrice']>=60){echo 'Your Order Qualifies for Free Shipping';}?>

That is awesome, and worked great! Thank you so much. SO now I just have to get rid of that text once they have selected the Free Shipping. So far I have tried this, but I believe I am using it incorrectly:

I put this in the line below the code that you gave me to use...

<?php if ($this->cart->cartData['shipmentName']=='Free Shipping')echo str_replace("Your Order Qualifies for Free Shipping. Please Select Free Shipping using the link on the left."," ","Your Order Qualifies for Free Shipping. Please Select Free Shipping using the link on the left.") ?>

Of course it is not working.. LOL. Or should I use something like this in the default.php instead of the default_pricelist.php. I guess I am looking to scan the page for that string of text and remove it. I am trying to learn slowly. Working on this is helping me pick up on a few things. Especially when breaking down what code snippets you have provided. One day I will learn all of this.... :)

I also tried this  to test but it of course does not work either. Obviously I am a bit off here.. hmmmm ...LOL

<?php
$oldphrase = "Your Order Qualifies for Free Shipping. Please Select Free Shipping using the link on the left";
$newphrase = ("Test");
                if ($this->cart->cartData['shipmentName']=='Free Shipping') echo str_replace($oldphrase,$newphrase,$oldphrase) ?>


I THINK

this will make it NOT display when they have selected it, and shipment fee is 0

<?php if (($this->cart->pricesUnformatted['salesPrice']>=60) && (!empty($this->cart->pricesUnformatted['salesPriceShipment']))){echo 'Your Order Qualifies for Free Shipping';}?>

Ffragrances

#6
Quote from: PRO on October 11, 2012, 14:11:54 PM
Quote from: Ffragrances on October 10, 2012, 23:45:05 PM
Quote from: PRO on October 10, 2012, 17:18:40 PM
<?php if ($this->cart->pricesUnformatted['salesPrice']>=60){echo 'Your Order Qualifies for Free Shipping';}?>

That is awesome, and worked great! Thank you so much. SO now I just have to get rid of that text once they have selected the Free Shipping. So far I have tried this, but I believe I am using it incorrectly:

I put this in the line below the code that you gave me to use...

<?php if ($this->cart->cartData['shipmentName']=='Free Shipping')echo str_replace("Your Order Qualifies for Free Shipping. Please Select Free Shipping using the link on the left."," ","Your Order Qualifies for Free Shipping. Please Select Free Shipping using the link on the left.") ?>

Of course it is not working.. LOL. Or should I use something like this in the default.php instead of the default_pricelist.php. I guess I am looking to scan the page for that string of text and remove it. I am trying to learn slowly. Working on this is helping me pick up on a few things. Especially when breaking down what code snippets you have provided. One day I will learn all of this.... :)

I also tried this  to test but it of course does not work either. Obviously I am a bit off here.. hmmmm ...LOL

<?php
$oldphrase = "Your Order Qualifies for Free Shipping. Please Select Free Shipping using the link on the left";
$newphrase = ("Test");
                if ($this->cart->cartData['shipmentName']=='Free Shipping') echo str_replace($oldphrase,$newphrase,$oldphrase) ?>


I THINK

this will make it NOT display when they have selected it, and shipment fee is 0

<?php if (($this->cart->pricesUnformatted['salesPrice']>=60) && (!empty($this->cart->pricesUnformatted['salesPriceShipment']))){echo 'Your Order Qualifies for Free Shipping';}?>



Nope,, Hmmmm. Excellent attempt though. Would it help if I gave you a link to the site and page?

Well I have been using basic PHP as I could put it together, and yours which obviously works for most of this is structured differently. But excellent try, and I appreciate it very much. I am sure that you are very busy with many things. I am still learning of course but what Framework are we working in here? This is not covered in the basic tutorials and sets that I have been using to learn.. LOL. I am still trying to figure out the structure of your codes.... 

Alas the hunt continues for the proper instruction code..... LOL Thanks again for your assistance....

PRO

try this
<?php if (($this->cart->pricesUnformatted['salesPrice']>=60) && ($this->cart->pricesUnformatted['salesPriceShipment']<=1)){echo 'Your Order Qualifies for Free Shipping';}?>

or

<?php if (($this->cart->pricesUnformatted['salesPrice']>=60) && (empty($this->cart->pricesUnformatted['salesPriceShipment']))){echo 'Your Order Qualifies for Free Shipping';}?>

Ffragrances

Quote from: PRO on October 11, 2012, 21:37:51 PM
try this
<?php if (($this->cart->pricesUnformatted['salesPrice']>=60) && ($this->cart->pricesUnformatted['salesPriceShipment']<=1)){echo 'Your Order Qualifies for Free Shipping';}?>

or

<?php if (($this->cart->pricesUnformatted['salesPrice']>=60) && (empty($this->cart->pricesUnformatted['salesPriceShipment']))){echo 'Your Order Qualifies for Free Shipping';}?>


Ok, well neither of these work either but, here is what I have noticed.

The second one adds the echo to the other echo you gave me the first time. SO on the screen you see two of them right next to each other. So, I put together this statement just to test and play around with.

<?php if ($this->cart->pricesUnformatted['salesPrice']>=60)
               {
               echo ('Your Order Qualifies for Free Shipping.');
               }
            elseif   ($this->cart->pricesUnformatted['salesPriceShipment']<=1)
               {
            echo ('This Is a Test');
               }
            else
               {
            echo ('nothing');
               }
               ?>

And here is what happens...

If the price is below $60 this returns " This is a Test"
Once the price hits >60 it returns "Your Order Qualifies for Free Shipping"
If you select Free Shipping from the shipment selection this also returns "Your Order Qualifies for Free Shipping"
And of course if I select a normal paid shipping method it also returns "Your Order Qualifies for Free Shipping"

Now If I change the quantities of product so that the price drops below the 60 and I select  a paid shipping option this returns "nothing"

SO. I am still working on this, and it seems that which ever one of these triggers first it sticks. Also I have been inserting all of these lines above these lines:

<?php if ( VmConfig::get('show_tax')) { ?>
            <td align="right"><?php echo "<span  class='priceColor2'>".$this->currencyDisplay->createPriceDiv('shipmentTax','', $this->cart->pricesUnformatted['shipmentTax'],false)."</span>"; ?> </td>
                                <?php } ?>
            <td></td>
            <td align="right"><?php echo $this->currencyDisplay->createPriceDiv('salesPriceShipment','', $this->cart->pricesUnformatted['salesPriceShipment'],false); ?> </td>
      </tr>

Question, This last section of code defines the div 'salesPriceShipment'

Is it an issue that that gets defined after we are calling for it in your codes???

I do not know of course, I am still learning, but this does give me more of a clue as to how all of this stuff works.
Also, it seems that essentially both sides of the && are being satisfied and therefore it will return the string "Your Order Qualifies for Free Shipping", I believe because(and I could be wrong), an empty location at 'salesPriceShipment is the same as 0. Am I incorrect in that thinking?

Anyhow I very much appreciate your assistance so far, and I continue to learn and try to get something that can work. If what I said is correct we will not be able to use the
'salesPriceShipment' because the code returns the same. That is why I am wondering if we can use the shipment name of "Free Shipping" to trigger not showing so that it is from someplace different than 'salesPriceShipment".. Hope that makes sense...

Also, so I can be less of a burden on you and others, it would be greatly helpful to me if you could maybe explain if there is a way and how, that I can get all of the tags or variables from any of these pages to work with. ie. 'salesPriceShipment', 'shipmentName', etc......

Thanks again,

<<<<<Learning :)

PRO

You might can go by the ID

I just tested this on mine (you need to find out the ID of your free shipment)

if ($this->cart->virtuemart_shipmentmethod_id==8)



and to get all the variables, AS LONG as you are NOT live


<?php print_r($this->cart)?>

Ffragrances

Quote from: PRO on October 12, 2012, 22:19:30 PM
You might can go by the ID

I just tested this on mine (you need to find out the ID of your free shipment)

if ($this->cart->virtuemart_shipmentmethod_id==8)

and to get all the variables, AS LONG as you are NOT live

<?php print_r($this->cart)?>


Ok, After all of that I am much more confident and learning more and more. Thanks so much Pro. Of course I would have been happy if the VM team would have just left that option from the earlier versions in there to begin with, but I would not be much closer to learning all of this, which is my ultimate goal anyhow. So this is the final code that worked and what it did. This will help for those customers we all get that sometimes get confused at the cart and give up. You can never make it too easy, or else risk loosing sales. Thanks again for your assistance Pro. I will try and not take too much of your time in the future. I am glad that there are a few of you around that don't mind helping those that truly want to learn.
:)

Code Snippet:

     <?php if (($this->cart->pricesUnformatted['salesPrice']>=60)&&(empty($this->cart->virtuemart_shipmentmethod_id)))
         {
         echo ('<< Your Order Qualifies for Free Shipping.Please Select Free Shipping Using The Link On The Left ');
         }
         elseif (($this->cart->virtuemart_shipmentmethod_id==3)&&($this->cart->pricesUnformatted['salesPrice']>=60))
         {
         echo (' ');
             }
     ?>

You may know of a way that does this in a shorter method or shorthand that saves more white space , but this works great. Now I move on to getting this site live..... and Learning More...................................................


Free Shipping Level Met


After Customer Selects Free Shipping


Thanks again for your assistance....





blacksheep

Quote from: PRO on August 15, 2012, 15:10:06 PM
Here are some fields for modifying the cart page to make it more user friendly.

I use these fields to make my own "checkout steps"



Sorry Pro, can you explain which code have to change in my cart default.php ?
I don't know PHP therefore need more details.
It' not that simple to me, for example I don't know how to move "save" button below the text after selecting shipping or payment methods. By default they're before the the text and it's not the best.
Many thanks

PRO

Yes, that's true. for usability, bottom is better

<div class="buttonBar-right">
<button class="<?php echo $buttonclass ?>" type="submit"><?php echo JText::_('COM_VIRTUEMART_SAVE'); ?></button>
     &nbsp;
<button class="<?php echo $buttonclass ?>" type="reset" onClick="window.location.href='<?php echo JRoute::_('index.php?option=com_virtuemart&view=cart'); ?>'" ><?php echo JText::_('COM_VIRTUEMART_CANCEL'); ?></button>
    </div>


RIGHT BEFORE
<input type="hidden" name="controller" value="cart" />

blacksheep


aeiweb

This is awesome!

THIS code will display the "Confirm order button" where you want it. ONLY when the billing & payment has been filled in
<?php if ((!empty($this->cart->BT))&& ($this->cart->cartData['paymentName'] != 'No payment selected') ){
echo '<h1 class="bottom10 border" style="width:180px;">';
         echo $this->checkout_link_html;
         $text = JText::_('COM_VIRTUEMART_ORDER_CONFIRM_MNU');
         echo '</h1>';

}?>

So this code will replace the ORDER button once the billing and shipping addy are in? SO GOOD. However, for those of us that are less brilliant at PHP, where abouts could I put this code for it to do its thing?

Thanks so much!