Jump to content



Photo
* * * * * 3 votes

Useful Snippets of Code


  • Please log in to reply
49 replies to this topic

#41   burt

burt

    I drink and I know things

  • Community Team
  • 12,504 posts
  • Real Name:G Burton
  • Gender:Male
  • Location:UK/DEV/on

Posted 15 April 2013 - 18:04

UPDATE `orders` SET `customers_postcode` = UPPER(`customers_postcode`);


This will update all your postcodes to upper case.
There are a few other places where postcodes are stored.

You might also want to enforce a strtoupper($postcode) on the DB inserts in create_account and address_book_process

This is a signature that appears on all my posts.  It is not specifically aimed at you.

 

IF YOU MAKE A POST REQUESTING HELP...please state the exact version of osCommerce that you are using. THANKS
 
If you are still on the old style osCommerce, it is time to move to Responsive.

 


#42   Harald Ponce de Leon

Harald Ponce de Leon

    Healthy Giraffe

  • Core Team
  • 5,349 posts
  • Real Name:Harald Ponce de Leon
  • Gender:Male
  • Location:Solingen, Germany

Posted 02 May 2013 - 09:33

Pages loading slow under your Windows development environment? I just experienced load times of around 2-3 seconds and discovered changing the database server address from:

localhost

to:

127.0.0.1

fixes the problem. Pages now load lightning fast!

This can be done in includes/configure.php and admin/includes/configure.php, for the DB_SERVER value.

Edited by Harald Ponce de Leon, 02 May 2013 - 09:34.

:heart: , osCommerce


#43   foxp2

foxp2

    strong as a Twig

  • Banned
  • 310 posts
  • Real Name:Laurent
  • Gender:Male
  • Location:France

Posted 02 May 2013 - 10:00

for System & Network which support IPV6 protocol, add in your [Drive Letter]:\Windows\System32\Drivers\etc\hosts* :
::1			 localhost

* administrator rights required.
-------------------

#44   GLWalker

GLWalker

    ıllıllı < /> ıllıllı

  • Members
  • 864 posts
  • Real Name:G.L.Walker
  • Gender:Male
  • Location:Texas

Posted 28 May 2014 - 16:45

Ive found some older databases may have orphaned address_book entries due to not properly removing customers or whatever reasons - here are some snippets to clean up the address_book table.

First, run this query and if you have any records returned, create a view
SELECT * FROM address_book a WHERE NOT EXISTS (SELECT 1 FROM customers c WHERE c.customers_id = a.customers_id)
ORDER BY a.customers_id;

~Do a google for creating a view in phpMyAdmin ~ lots of info exist, but you'll find the create view button at bottom of the page; name it something like orphaned_address_books.

It is now up to you to confirm the integrity of the data returned, look at some of the customers_id's in the view, check to see if the same customers_id exist in the customers table - if they DO NOT exist in the customers table then you may proceed. You don't really want to waste time checking each of them if you have a high return, just randomly select a handful to ensure the query returned as expected.

Now, using the view you should be able to delete the orphaned rows.

By the way ~ YOU did backup the address_book table, right?

Follow the community build:

BS3 to osCommerce Responsive from the Get Go!

Check out the new construction:

Admin Gone to Total BS!


#45   Gergely

Gergely

    Json Juggler

  • Community Team
  • 2,125 posts
  • Real Name:Gergely Tóth
  • Gender:Male
  • Location:Budapest

Posted 22 February 2015 - 08:03

When feeling myself in a development enviroment as a blind man running in the city.

 

I use this minimal function in catalog/iincludes/local/configure.php so no conflict with github
 

 // my debug functions
 // display values & exit
 //
 function de($v = array('exit')) { echo '<pre>'; print_r($v); echo '</pre>'; exit; }
 
 // only display values
 function d($v = array('exit')) { echo '<pre>'; print_r($v); echo '</pre>'; }

Next PHP changes will kill the current codes on the following years. We should do programing for the future and never stick in the present.

My addons: Conversion Tools::Hungarian Translation::Email Templates::URL redirection
 
Development Works: Setup Languages::Email Templates::Languages from ini files::Parcel Shops::Facebook App
 
What core codes have been complained?

In orders table payment_methods value would be better if payment class name used than payment's language name.
In the orders class we found order status does not contains $order->info['orders_status'] but instead there is $order->info['orders_status_name'], and that property is language dependant.
We can not identify in order the customer language.


#46   Hotclutch

Hotclutch
  • Members
  • 1,739 posts
  • Real Name:Ashley
  • Gender:Male
  • Location:Cape Town, SA

Posted 13 July 2015 - 22:22

I am using Cache, and notice that my bestsellers boxes disappear every once in a while. When the cache files are deleted, the pages work fine again. Came across this useful piece of code in the add-on section. Create a script in the root directory with the following contents and then create a cron job to execute every few hours.

<?php

	$files = glob("includes/work/bm_best_sellers_box-*");
	
	if (!count($files)) { die('No files in cache'); }
	
	foreach ($files as $filename) {
	
		unlink($filename);
	
	}
	
	echo 'Cleared cache';
	
?>


#47   Gergely

Gergely

    Json Juggler

  • Community Team
  • 2,125 posts
  • Real Name:Gergely Tóth
  • Gender:Male
  • Location:Budapest

Posted 01 August 2015 - 09:13

Bootstrap Core Memory Usage

add on the top in application_top:
 

  // ini_set('memory_limit', '4M');
  $memory_start = memory_get_usage(false);

Find at the bottom of application_bottom:

?>


Change to:

  $memory_end = memory_get_peak_usage(false);
  $valuemax = (int)ini_get('memory_limit');
  $valuenow = round(($memory_end-$memory_start)/1024/1024/$valuemax, 3)*100;

?>
<div class="progress">
  <div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $valuenow; ?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $valuenow; ?>%;">
    <?php echo $valuenow; ?>%
  </div>
</div>

 


Next PHP changes will kill the current codes on the following years. We should do programing for the future and never stick in the present.

My addons: Conversion Tools::Hungarian Translation::Email Templates::URL redirection
 
Development Works: Setup Languages::Email Templates::Languages from ini files::Parcel Shops::Facebook App
 
What core codes have been complained?

In orders table payment_methods value would be better if payment class name used than payment's language name.
In the orders class we found order status does not contains $order->info['orders_status'] but instead there is $order->info['orders_status_name'], and that property is language dependant.
We can not identify in order the customer language.


#48   bruyndoncx

bruyndoncx

    osCommerce Teenager

  • Members
  • 3,786 posts
  • Real Name:Carine Bruyndoncx
  • Gender:Female
  • Location:Belgium/ Antwerp/ Turnhout/ Arendonk

Posted 01 August 2015 - 22:08

I was looking for a way to inspect the microdata using some javascript on page.

This page shows a solution in action, that you can add to your codebase,
http://krofdrakula.g...microdata-tool/

but even better, it is also avalable as a bookmarklet
https://gist.github.com/1397528
for your use without having to modify your page's source code!
Simply visit this page
http://jsfiddle.net/...mbedded/result/
and drag the link to your bookmark bar and you're set to go.

Edited by burt, 02 August 2015 - 18:13.
corrected link

KEEP CALM AND CARRY ON
FYI Upgrade to the highest PHP version you can( PHP 5.5/5.6 or 7.1  and get big performance improvements for free)

But be aware php 5.5 is more strict about things.
UTF8-without BOM, no extra spaces allowed at the beginning or end of your php file, or your redirects wont work.
No double declarations of functions allowed - used to slip through the cracks ...

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt


#49   bonbec

bonbec
  • Members
  • 65 posts
  • Real Name:Fred
  • Gender:Male
  • Location:Vichy - France

Posted 02 August 2015 - 05:53

Thank's Carine,

 

For the link #2, remove the  )f  at the end and it will work fine ;)


Live   : OsC 2.2, php 5.2 & UTF-8

Local : OsC 234BS for future shop


#50   bruyndoncx

bruyndoncx

    osCommerce Teenager

  • Members
  • 3,786 posts
  • Real Name:Carine Bruyndoncx
  • Gender:Female
  • Location:Belgium/ Antwerp/ Turnhout/ Arendonk

Posted 02 August 2015 - 20:28

Thank's Carine,

 

For the link #2, remove the  )f  at the end and it will work fine ;)

Thanks for the heads up, burt corrected the original post for me.


KEEP CALM AND CARRY ON
FYI Upgrade to the highest PHP version you can( PHP 5.5/5.6 or 7.1  and get big performance improvements for free)

But be aware php 5.5 is more strict about things.
UTF8-without BOM, no extra spaces allowed at the beginning or end of your php file, or your redirects wont work.
No double declarations of functions allowed - used to slip through the cracks ...

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt