News:

Support the VirtueMart project and become a member

Main Menu

Make the ShipTo default to BillTo unless ShipTo exist!

Started by Stonedfury, October 28, 2013, 20:31:54 PM

Previous topic - Next topic

Stonedfury

Hello!  :o
For those with customers who get confused at the Bill to and Ship to fields because the ST is empty. Here's a work around that to help remove the confusion. I would love to see this as part of the next update in VM. Tell me how to send it in or put in myself so you guys can just run with it.

Create your override folder yoursite.net\templates\yourtemplate\html\com_virtuemart\cart and copy the files from yoursite.net\components\com_virtuemart\views\cart\tpl

Open default_pricelist.php and find

<div class="output-shipto">

<?php 

if (empty($this->cart->STaddress['fields'])) {

echo JText::sprintf ('COM_VIRTUEMART_USER_FORM_EDIT_BILLTO_EXPLAIN'JText::('COM_VIRTUEMART_USER_FORM_ADD_SHIPTO_LBL'));

} else {

if (!class_exists ('VmHtml')) {

require(JPATH_VM_ADMINISTRATOR DS 'helpers' DS 'html.php');

}

echo JText::('COM_VIRTUEMART_USER_FORM_ST_SAME_AS_BT');

echo VmHtml::checkbox ('STsameAsBTjs'$this->cart->STsameAsBT) . '<br />';

?>


<div id="output-shipto-display">

<?php

foreach ($this->cart->STaddress['fields'] as $item) {

if (!empty($item['value'])) {

?>


<!-- <span class="titles"><?php echo $item['title'?></span> -->

<?php

if ($item['name'] == 'first_name' || $item['name'] == 'middle_name' || $item['name'] == 'zip') {

?>


<span class="values<?php echo '-' $item['name'?>"><?php echo $this->escape ($item['value']) ?></span>

<?php } else { ?>

<span class="values"><?php echo $this->escape ($item['value']) ?></span>

<br class="clear"/>

<?php

}

}

}

?>

Replace with
<!-- adding code to change ship to to bill to and back -->
<div class="output-shipto">

<?php if (empty($this->cart->STaddress)){ 

foreach($this->cart->BTaddress['fields'] as $item){

if(!empty($item['value'])){

if($item['name']==='agreed'){

$item['value'] =  ($item['value']===0) ? JText::_('COM_VIRTUEMART_USER_FORM_BILLTO_TOS_NO'):JText::_('COM_VIRTUEMART_USER_FORM_BILLTO_TOS_YES');

}

?>
<!-- span class="titles"><?php echo $item['title'?></span -->

<span class="values vm2<?php echo '-'.$item['name'?>" ><?php echo $this->escape($item['value']) ?></span>

<?php if ($item['name'] != 'title' and $item['name'] != 'first_name' and $item['name'] != 'middle_name' and $item['name'] != 'zip') { ?>

<br class="clear" />

<?php

}

}


 } else { 
if(!class_exists('VmHtml'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'html.php');

echo JText::_('COM_VIRTUEMART_USER_FORM_ST_SAME_AS_BT');

echo VmHtml::checkbox('STsameAsBT',$this->cart->STsameAsBT).'<br />';

foreach($this->cart->STaddress['fields'] as $item){

if(!empty($item['value'])){ ?>


<!-- <span class="titles"><?php echo $item['title'?></span> -->

<?php

if ($item['name'] == 'first_name' || $item['name'] == 'middle_name' || $item['name'] == 'zip') { ?>


<span class="values<?php echo '-'.$item['name'?>" ><?php echo $this->escape($item['value']) ?></span>

<?php } else { ?>

<span class="values" ><?php echo $this->escape($item['value']) ?></span>

<br class="clear" />

<?php

}

}

}


 
?>

       
        <!-- Ending replacement code here -->

NOTE: I originally posted this on the VP_Promart forum as an edit in their template. This is NOT their template being displayed and the file include in the zip file is from stock VM copied into beez_20 template. I have been using this edit since I shared it with Virtueplanet and I have had no issues with orders getting wrong address beyond what the user messes up.


[attachment cleanup by admin]
No such thing as a stupid question, only a stupid answer. I won't ask if I know the answer or found it using the search as you suggested.

AH

Stoned

I too had some fun with the checkout section. I saw no point in having a separate OPC component that relies totally on JS and lags behind VM releases.

Maybe I can add some additional ideas.  I doubt they will make the VM code cut though (LOL)

I modified the section relating to bill to and ship to details so that the section determines if a billing address has been entered, before showing you the option of setting a shipping address.

It also adjusts the button text to show add or edit depending on whether the relevant address has been added.

You need to override the "default button text" to get rid of the add/edit as this is controlled by the status of the address.
I also override the language variable COM_VIRTUEMART_USER_FORM_EDIT_BILLTO_EXPLAIN="<strong>Same as Billing Address<br/></strong>"

You can add the additional styling for the BT address button as the class is changed when the BT details have not been entered.

$q_step = "q_continue";
$q_step = "details";


Option below:-


  <div class="width70 floatleft billto-shipto">
        <div class="width60 floatleft">
<span><span class="vmicon vm2-billto-icon"></span>
            <?php echo JText::('COM_VIRTUEMART_USER_FORM_BILLTO_LBL'); ?></span>
            <?php // Output Bill To Address ?>
            <div class="output-billto">
                <?php
// checks to see if BT has been added
                
if (empty($this->cart->BT)) {
                   echo 
"Please add your billing details";
// changes the css class of the button so I can highlight the action I want them to perform
                    
$q_step "q_continue";
// changes the button text of BT address does not exist
                    
$q_button_text "Add ";
                } else {
                    
$q_step "details";
                    
$q_button_text "Edit ";
                            foreach (
$this->cart->BTaddress['fields'] as $item) {
                            if (!empty(
$item['value'])) {
                                if (
$item['name'] === 'agreed') {
                                   
// $item['value'] = ($item['value'] === 0) ? JText::_ ('COM_VIRTUEMART_USER_FORM_BILLTO_TOS_NO') : JText::_ ('COM_VIRTUEMART_USER_FORM_BILLTO_TOS_YES');
                                    
$item['value'] = "";
                                }
                                
?>

                                <!--span class="titles"><?php echo $item['title'?></span-->

                                <span class="values vm2<?php echo '-' $item['name'?>"><?php echo $this->escape ($item['value']) ?></span>
                                <?php if ($item['name'] != 'title' and $item['name'] != 'first_name' and $item['name'] != 'middle_name' and $item['name'] != 'agreed') { ?>
                                    <br class="clear"/>
                                <?php
                                
}
                            }
                        }
                }   
?>

                <br/>
                <a class="<?php echo $q_step ?>" href="<?php echo JRoute::('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=BT'$this->useXHTML$this->useSSL?>" rel="nofollow">
                    <?php echo $q_button_text JText::('COM_VIRTUEMART_USER_FORM_EDIT_BILLTO_LBL'); ?>
                </a>
                <input type="hidden" name="billto" value="<?php echo $this->cart->lists['billTo']; ?>"/>

            </div>

        </div>
        <div class="width40 floatleft">
<span><span class="vmicon vm2-shipto-icon"></span>
            <?php echo JText::('COM_VIRTUEMART_USER_FORM_SHIPTO_LBL'); ?></span>
            <div class="output-shipto">
                <?php

                
if (empty($this->cart->BT)) {

                    echo 
"Please add your billing information first";
                } else {
                    
// Output Bill To Address ?>


                        <?php
                        
if (empty($this->cart->STaddress['fields'])) {
                            echo 
JText::sprintf ('COM_VIRTUEMART_USER_FORM_EDIT_BILLTO_EXPLAIN'JText::('COM_VIRTUEMART_USER_FORM_ADD_SHIPTO_LBL'));
                        } else {
                            if (!
class_exists ('VmHtml')) {
                                require(
JPATH_VM_ADMINISTRATOR DS 'helpers' DS 'html.php');
                            }
                            echo 
JText::('COM_VIRTUEMART_USER_FORM_ST_SAME_AS_BT');
                            echo 
VmHtml::checkbox ('STsameAsBTjs'$this->cart->STsameAsBT) . '<br />';
                            
?>

                            <div id="output-shipto-display">
                                <?php
                                
foreach ($this->cart->STaddress['fields'] as $item) {
                                    if (!empty(
$item['value'])) {
                                        
?>

                                        <!-- <span class="titles"><?php echo $item['title'?></span> -->
                                        <?php
                                        
if ($item['name'] == 'first_name' || $item['name'] == 'middle_name' || $item['name'] == 'zip') {
                                            
?>

                                            <span class="values<?php echo '-' $item['name'?>"><?php echo $this->escape ($item['value']) ?></span>
                                        <?php } else { ?>
                                            <span class="values"><?php echo $this->escape ($item['value']) ?></span>
                                            <br class="clear"/>
                                        <?php
                                        
}
                                    }
                                }
                                
?>

                            </div>
                        <?php
                        
}
                        
?>


                    <?php if (!isset($this->cart->lists['current_id'])) {
                        
$this->cart->lists['current_id'] = 0;
                    } 
?>

                    <br/>
                    <a class="details" 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?>" rel="nofollow">
                        <?php echo JText::('COM_VIRTUEMART_USER_FORM_ADD_SHIPTO_LBL'); ?>
                    </a>
                <?php }

                
?>

            </div>


Regards
A

Joomla 3.10.11
php 8.0

Stonedfury

Right on Hutson! I think that some of these could be put into VM. The buttons should change if you have BT and ST details. I totally agree.
No such thing as a stupid question, only a stupid answer. I won't ask if I know the answer or found it using the search as you suggested.

AH

Regards
A

Joomla 3.10.11
php 8.0