Dirty Butter Posted May 26, 2013 Share Posted May 26, 2013 Current code on orders.print.php: <b>Delivery Address:</b> <br/> {$order.title_d} {$order.first_name_d} {$order.last_name_d}<br /> {if !empty($order.company_name_d)}{$order.company_name_d}<br />{/if} {$order.line1_d} <br /> {if !empty($order.line2_d)}{$order.line2_d}<br />{/if} {$order.town_d}<br /> {if !empty($order.state_d)}{$order.state_d}, {/if}{$order.postcode_d}<br /> {$order.country_d} I'd like to have the postal abbreviation for USA States show on the printed packing slip where applicable, instead of the written out name of the state. Obviously not every country has Zone abbreviations, so I only want this for the USA, if possible. Any suggestions? Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 27, 2013 Share Posted May 27, 2013 In the file /admin/sources/orders.index.inc.php, there are two places where the template orders.print.php is called, near line 475 and near line 635 (near depending if this is CC514 or CC522 - if there is, in fact, a difference). Near line 451, $summary['state_d'] is built. A test is made to determine if this record from the CC_order_summary table holds the state id code (id column in CC_geo_zone), or has something else from a legacy CC4 order. At any rate, let's leave this as is so anything else that may want to use the $summary['state_d'] can do so. Let's add another statement: $summary['state_abbrev_d'] = (is_numeric($summary['state_d'])) ? getStateFormat($summary['state_d'],'id','abbrev') : $summary['state_d']; This again asks if the state_id value is the numeric id code for the state, but this time, if it is, fetch the value in the abbrev column. Then, in the skin file, use {$order.state_abbrev_d}. Near line 599, a collection of records from the CC_order_summary table is fetched. What's odd here (at least up to CC521) is that no test is made like there is in line 451, nor is the ['country_d'] key resolved. The key ['date'] is created when it should be ['order_date']. At any rate, I suggest adding a $order['state_abbrev_d'] statement near line 620. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 27, 2013 Author Share Posted May 27, 2013 Thanks for weighing in on this one, Bsmither. But, as usual, I'm having trouble following your directions - as it is not working for me with the following changes: I now have this as the section in orders.index.inc.php: // Price Formatting $summary['percent'] = ''; if ($summary['discount_type'] == 'p') { $summary['percent'] = number_format(($summary['discount']/$summary['subtotal'])*100) . '%'; } $format = array('discount','shipping','subtotal','total_tax','total'); foreach ($format as $field) { if (isset($summary[$field])) $summary[$field] = Tax::getInstance()->priceFormat($summary[$field]); } $summary['state_d'] = (is_numeric($summary['state_d'])) ? getStateFormat($summary['state_d']) : $summary['state_d']; $summary['state_abbrev_d'] = (is_numeric($summary['state_d'])) ? getStateFormat($summary['state_d'],'id','abbrev') : $summary['state_d']; And in orders.print.php I have this: <b>Delivery Address:</b> <br/> {$order.title_d} {$order.first_name_d} {$order.last_name_d}<br /> {if !empty($order.company_name_d)}{$order.company_name_d}<br />{/if} {$order.line1_d} <br /> {if !empty($order.line2_d)}{$order.line2_d}<br />{/if} {$order.town_d}<br /> {if !empty($order.state_d)}{$order.state_abbrev_d}, {/if}{$order.postcode_d}<br /> {$order.country_d} And I didn't understand what to do here: Near line 599, a collection of records from the CC_order_summary table is fetched. What's odd here (at least up to CC521) is that no test is made like there is in line 451, nor is the ['country_d'] key resolved. The key ['date'] is created when it should be ['order_date']. At any rate, I suggest adding a $order['state_abbrev_d'] statement near line 620. Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 27, 2013 Share Posted May 27, 2013 Since both of the two locations in the orders.index.inc.php file send it's output to the orders.print.php template, and I can't reliably determine which of the two locations are used under what circumstances, I suggest adding a new statement at both locations. You have added the new statement for the area of code near line 451 correctly. Now, add near line 620, this:$order['state_abbrev_d'] = (is_numeric($order['state_d'])) ? getStateFormat($order['state_d'],'id','abbrev') : $order['state_d']; This statement added near line 620 is an appropriate variant of the statement added near line 451. If you have CaubeCart's cache enabled, did you clear the cache after making the edits to your skin file? Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 27, 2013 Author Share Posted May 27, 2013 I did clear CC and browser cache. I added the second code here: foreach ($orders as $order) { $order['name'] = (isset($order['name']) && !empty($order['name'])) ? $order['name'] : sprintf('%s %s %s', $order['title'], $order['first_name'], $order['last_name']); $order['icon'] = ($order['type']==2 || empty($order['customer_id'])) ? 'user_ghost' : 'user_registered'; $order['link_edit'] = currentPage(array('print_hash'), array('action' => 'edit', 'order_id' => $order['cart_order_id'])); $order['link_customer'] = ($order['customer_id']) ? "?_g=customers&action=edit&customer_id=".$order['customer_id'] : "#"; $order['link_delete'] = currentPage(array('print_hash'), array('delete' => $order['cart_order_id'])); // Link needs to be an array with one key $order['link_print'] = currentPage(array('print_hash'), array('print[0]' => $order['cart_order_id'])); $order['status'] = $lang['order_state']['name_'.$order['status']]; $order['date'] = formatTime($order['order_date']); $order['prod_total'] = Tax::getInstance()->priceFormat($order['total']); $order['state_abbrev_d'] = (is_numeric($order['state_d'])) ? getStateFormat($order['state_d'],'id','abbrev') : $order['state_d']; Hopefully that was the right location for it, but the printout still shows the state word, not abbreviation. Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 27, 2013 Share Posted May 27, 2013 Double-check the database table CC_order_summary for that cart_order_id and see if the state_d column is holding a number, or the actual name of the state. If a number, then we need to double-check a few things. If the name of an actual state, we need to discover why the name is getting recorded instead of the state id code. Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 27, 2013 Share Posted May 27, 2013 And please confirm that you are rebuilding the orders.print.php file. I don't recognize the specific code you posted at the start. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 27, 2013 Author Share Posted May 27, 2013 Yes, the state_d column has the correct number, not the name. I use a modified Packing Slip. Here's the whole orders.print.php file: <!DOCTYPE html> <!--Plush Catalog--> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>{$PAGE_TITLE}</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="../admin/styles/print.css" media="screen,print" /> </head> <body onload="window.print();"> {if isset($ORDER_LIST)} {foreach from=$ORDER_LIST item=order} <div> <br/> <center><img src="{$STORE_LOGO}" alt="{$META_TITLE}" /></center> </div> <br/> <div class="info"> <strong>{$LANG.common.order_id}</strong> {$order.cart_order_id} {$order.ship_method} <br/><br/><strong>{$LANG.orders.title_receipt_for}</strong> {$order.order_date} </div> <b>Delivery Address:</b> <br/> {$order.title_d} {$order.first_name_d} {$order.last_name_d}<br /> {if !empty($order.company_name_d)}{$order.company_name_d}<br />{/if} {$order.line1_d} <br /> {if !empty($order.line2_d)}{$order.line2_d}<br />{/if} {$order.town_d}<br /> {if !empty($order.state_d)}{$order.state_abbrev_d}, {/if}{$order.postcode_d}<br /> {$order.country_d} <div class="product"> <span class="price">{$LANG.common.price}</span> <strong>{$LANG.common.product}</strong> </div> {foreach from=$order.items item=item} <div class="product"> <span class="price">{$item.price}</span>{$item.quantity} × {$item.name} {if !empty($item.product_code)}({$item.product_code}){/if} {if isset($item.options)} <br />{$LANG.catalogue.title_options} {foreach from=$item.options item=option}» {$option}{/foreach} {/if} {if isset($item.prodDesc)} <br /><div>{$item.prodDesc}</div> {/if} </div> {/foreach} <div id="totals"> <div class="total">{$LANG.basket.total_sub} <strong>{$order.subtotal}</strong></div> <div class="total">{$LANG.basket.total_discount} {if !empty($order.percent)}({$order.percent}){/if} <strong>{$order.discount}</strong></div> <div class="total">{$LANG.basket.shipping} <strong>{$order.shipping}</strong></div> {if isset($order.taxes)} {foreach from=$order.taxes item=tax} <div class="total">{$tax.name} <strong>{$tax.value}</strong></div> {/foreach}{/if} <br /> <div class="total"><strong>{$LANG.basket.total_grand} {$order.total}</strong></div> </div> <div> <p><center>Thank you for buying from us!</center></p> <p> If there are any problems with your shipment, please let us know within three (3) days of receipt, and we will work with you to resolve the situation. We want you to be happy with your purchase.</p> <p>Please bookmark our site at <a href="{$STORE_URL} ">{$STORE_URL}</a> and tell your friends and family about us.</p><p> We also run a free Plush Memories Lost Toy Search Service at <a href="http://plushmemories.com/">http://plushmemories.com</a> . If you, or anyone you know, are looking for a lovie we will be glad to help you find it.</p> <p align="center"><i>"Jesus saith unto him, I am the way, the truth, and the life: no man cometh unto the Father, but by me."</i></p> <p align="center">John 14:6 KJV</p> </div> <div id="footer"> <br/> <p><b>{$STORE.address}</b></p> </div> {/foreach} {/if} </body> </html> Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 27, 2013 Share Posted May 27, 2013 After the </html> tag in this skin file, add {debug}. Then have CubeCart deliver a page to print. There should now be a pop-up with all the stuff CubeCart has sent to Smarty. There should be $ORDER_LIST (as well as $order at the bottom). Verify that ['state_abbrev_d'] is a key in that array. We are wanting the abbreviation to the state. However, the routine that looks for and returns that will give the whole name if there is no abbreviation available. So, just to confirm that variable, are you sure the state of which you are wanting its abbreviation actually has an abbreviation? Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 27, 2013 Author Share Posted May 27, 2013 OK - debug complete. As you said, if abbreviation does not exist it shows the name. Well, here's what I get in both places: state_abbrev_d => "Alabama" But I DO have AL in the abbrev column for Alabama in the _geo_zone table. In fact, EVERY state/province in geo_zone has an abbreviation. Is this the wrong table to be looking in for the abbrev column? Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 27, 2013 Share Posted May 27, 2013 I see what the problem is: $summary['state_d'] = (is_numeric($summary['state_d'])) ? getStateFormat($summary['state_d']) : $summary['state_d']; $summary['state_abbrev_d'] = (is_numeric($summary['state_d'])) ? getStateFormat($summary['state_d'],'id','abbrev') : $summary['state_d']; Switch the order of these two statements. As it is, the first statement resets $summary['state_d'] to be the state name. Then comes the second statement asking if $summary['state_d'] looks to be numeric -- which it isn't anymore. Quote Link to comment Share on other sites More sharing options...
Dirty Butter Posted May 27, 2013 Author Share Posted May 27, 2013 THAT DID IT! Thank you so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.