News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

How to read the zip variable from the addresses in the cart

Started by kumado, October 09, 2019, 18:42:57 PM

Previous topic - Next topic

kumado

Hallo,

am just setting up a webshop with Vituemart 3 and joomla 3.9.12. I try to read out the "zip" variable within the current selected address (BT and ST) in the cart . The shopper can select per radio button in the cart between his billing address or a 1 or more further shipping adresses. Each line contains the name of the shipping address, and behind it the zip code. Once the radio button is sleetced the whole address appears underneath the the options. I now need only the zip code of this address and not the full address. I need the zip code to assign it to a new php variable which then will processed further in another skript.
This shall list all availabvle installers in the zip area

The file default_adress.php im com_viruemart/cart/ lists only the whole address .

How do i read the zip variable only out ?


line11:

echo $this->cart->lists['shipTo'];


from the file


<div class="output-shipto">
            <?php
            if (!class_exists ('VmHtml')) {
                require(VMPATH_ADMIN . DS . 'helpers' . DS . 'html.php');
            }
            if($this->cart->user->virtuemart_user_id==0){

                echo vmText::_ ('COM_VIRTUEMART_USER_FORM_ST_SAME_AS_BT');
                echo VmHtml::checkbox ('STsameAsBT', $this->cart->STsameAsBT,1,0,'id="STsameAsBTjs" data-dynamic-update=1') . '<br />';
            } else if(!empty($this->cart->lists['shipTo'])){
                echo $this->cart->lists['shipTo'];
            }

            if(empty($this->cart->STsameAsBT) and !empty($this->cart->ST) and !empty($this->cart->STaddress['fields'])){ ?>
                <div id="output-shipto-display">
                    <?php
                    foreach ($this->cart->STaddress['fields'] as $item) {
                        if($item['name']=='shipto_address_type_name') continue;
                        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 $item['value'] ?></span>
                            <?php                         
                            } else { ?>
                                <span class="values"><?php echo $item['value'] ?></span>
                                <br class="clear"/>
                            <?php
                            }
                        }
                    }
                    ?>
                </div>
            <?php
            }

or ist it here : ??

$this->cart->STaddress['fields']

Have tried various things but did not succeed  :-\

:/

PRO

depends WHERE

this below will assign a $my_new_variable to the zip.

foreach ($this->cart->STaddress['fields'] as $item) {
                        if($item['name']!='zip') continue;
                        if($item['name']=='zip'){
                        $my_new_variable=$item['value'] ;
                        }
                    }


kumado

Hi, tried it out, but doesn't work
Put it right under the if clause to check the item [name] in the foreach loopAnd should echo at least some text, if assigned. On the webiste it doesn't show anything

if(empty($this->cart->STsameAsBT) and !empty($this->cart->ST) and !empty($this->cart->STaddress['fields'])){ ?>
                <div id="output-shipto-display">
                    <?php                       
                    foreach ($this->cart->STaddress['fields'] as $item) {
                        if($item['name']!='zip') continue;
                        if($item['name']=='zip'){ $zip_var1=$item['value']; echo "zip var1: ".$zip_var1."<br>";};
                    }                       
                   

                    foreach ($this->cart->STaddress['fields'] as $item) {               
                                           
                        if($item['name']=='shipto_address_type_name') continue;
                        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 $item['value'] ?></span>
                            <?php                         
                            } else { ?>
                                <span class="values"><?php echo $item['value'];
                               
                                ?></span>
                                <br class="clear"/>
                            <?php
                            }
                        }
                    }  // endof foreach
           

Jörgen

Insert some debug comments and see if the statements are reached.

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

GJC Web Design

yes -- check u are in the correct file..

add <!--- I AM HERE --> in the html and check u can see it
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation