Author Topic: How to read the zip variable from the addresses in the cart  (Read 717 times)

kumado

  • Beginner
  • *
  • Posts: 2
  • A beginner
How to read the zip variable from the addresses in the cart
« on: October 09, 2019, 18:42:57 pm »
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

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10375
  • VirtueMart Version: 3+
Re: How to read the zip variable from the addresses in the cart
« Reply #1 on: October 09, 2019, 20:15:22 pm »
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'] ;
                        }
                    }

J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

kumado

  • Beginner
  • *
  • Posts: 2
  • A beginner
Re: How to read the zip variable from the addresses in the cart
« Reply #2 on: October 10, 2019, 13:39:58 pm »
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

  • Global Moderator
  • Full Member
  • *
  • Posts: 2422
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: How to read the zip variable from the addresses in the cart
« Reply #3 on: October 10, 2019, 13:43:40 pm »
Insert some debug comments and see if the statements are reached.

Jörgen @ Kreativ Fotografi
Joomla 3.9.8
Virtuemart 3.4.x
Olympiantheme Hera (customized)

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9194
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: How to read the zip variable from the addresses in the cart
« Reply #4 on: October 10, 2019, 23:00:17 pm »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation