Skip to main content

Posts

Showing posts with the label PHP

PHP Issue - A non-numeric value encountered

This error is encountered when we are going to do addition with different types of variables. See following example $a = ""; $b = 3; try{ $c = $a + $b; }catch(\Exception $e){ var_dump($e->getMessage()); } Exception is occurred. Error is " A non-numeric value encountered " There are two solutions  Solution 1 Change the value of variable $a into zero (0). So, both variables are getting the same type of value now.  $a = 0; $b = 3; try{        $c = $a + $b;         echo $c; }catch(\Exception $e){ var_dump($e->getMessage()); } Solution 2  You can simply cast $a when doing addition $a = ""; $b = 3; try{         $c =  (int) $a  + $b;         echo $c; }catch(\Exception $e){ var_dump($e->getMessage()); } Enjoy..

Magento 2 : Less variable issue

If you get variable issue when running  grunt exec:themename  or when deploying theme using php bin/magento setup:static-content:deploy First delete var/*  Then run following commands php bin/magento setup:upgrade php bin/magento setup:static-content:deploy If doesn't solve your problem check your parent theme name in your theme.xml. If it is not luma then change back to luma and run following commands again. php bin/magento setup:upgrade php bin/magento setup:static-content:deploy

How to point Magento multi websites to domains

Backend configurations Add secure and unsecure domain urls for websites Add default domain url default config Index.php changes You need edit index.php file as follows switch($_SERVER['HTTP_HOST']) {     case ' domain.co.uk ':     case 'www. domain.co.uk ':         $mageRunCode = 'base';         $mageRunType = 'website';     break;     case ' domain.eu ':     case 'www. domain.eu ':         $mageRunCode = 'euwebsite';         $mageRunType = 'website';     break; } Comment following lines if you have /* Run store or run website */ $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';   Point main domain by adding your hosting server dns in domain registrar                 It will take some time to resolve DNS settings. Use intodns.com to check dns of a domain.   Then you need to poin

How to retrieve data from another table while retrieving data from a table in loadFormData function in Joomla 2.5

I have to show data from two different tables. Therefore I had to change 'loadFormData' function to satisfy that. Current implementation was as follows. /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * @since 1.6 */ protected function loadFormData()  { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_speakee.edit.batchofcard.data', array()); if (empty($data))  { $data = $this->getItem();                         }                          return $data; } Then I changed it to get data from another table called 'Discount' by calling table of 'Discount' and got table properties by primary key.  /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * @since 1.6 */ protected function loadFormDat

Convert date from one timezone to another timezone PHP

This example is from phone call history  //set default time zone date_default_timezone_set('America/New_York'); //Set call date and time $call_date = new DateTime(date("d-m-Y H:i:s", strtotime($call['calldate']." ".$call['calltime']))); //Create new time zone object $la_time = new DateTimeZone('Europe/London'); //Set time zone to date $call_date->setTimezone($la_time); //show new date and time echo $call_date->format('d-m-Y'); echo $call_date->format("H:i:s"); Chamath Gunasekara

How to add Google fonts to select in TinyMCE editor in Joomla backend

There was a requirement from one of our customers to select Google fonts which we were using in front end pages in Tiny mice editors in Joomla 2.5 back end. I couldn't find a plug-in which provides this functionality from the back end. There are few plug-ins which can be used to enable Google fonts or font.com fonts by selectors (like class or ids).   Then I went through the source code of tiny mice editor plug-in found a way add new fonts. It was a bad thing when we think about joomla updates. But with client perspective it was a good solution I think. You are welcome to discuss with regards pros and cons.  Add new fonts here Edit editor_template.js file in  media\editors\ tinymce\ jscripts\ tiny_mce\ themes\ advanced\ editor_template.js Search for 'theme_advanced_fonts' or 'Arial' or 'georgia'. There are few places of 'theme_advanced_fonts'. You need to find correct place.  theme_advanced_fonts:"Andale Mono=andale mono,times;Arial=aria

PHP :: How to request Webservice using PHP CURL

I had a problem when requesting webservice. My solution as follows.         $url = " https://path_to_service.asp " ; //setting the curl parameters.   $headers = array ( "Content-type: text/xml;charset=\"utf-8\"" ,     "Accept: text/xml" , "Cache-Control: no-cache" ,   "Pragma: no-cache" ,   "SOAPAction: \"run\""   );   try { $ch = curl_init ();   curl_setopt ( $ch , CURLOPT_URL , $url ); curl_setopt ( $ch , CURLOPT_POST , 1 );     // send xml request to a server   curl_setopt ( $ch , CURLOPT_SSL_VERIFYHOST , 0 );   curl_setopt ( $ch , CURLOPT_SSL_VERIFYPEER , 0 ); curl_setopt ( $ch , CURLOPT_POSTFIELDS , $xmlRequest );   curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 ); c

Joomla 2.5 :: Redirects Error 500 (Internal server Error) page when loging with invalid username and password

I faced this issue when migrating my local joomla 2.5 installation to test server. It works fine when logging with correct username and passwords. Then I have checked in error_log and found issue. PHP Warning:  fopen(path_to_log/logs/error.php): failed to open stream: No such file or directory in  new_server_path/libraries/joomla/log/loggers/formattedtext.php on line 248 Then I have checked in back end and changed path to log folder as follows.

Magento :: Fatal error: Declaration of Zend_Pdf_FileParserDataSource_File::__construct() must be compatible with Zend_Pdf_FileParserDataSource::__construct()

I got this fatal error when I'm going to print shipment. There are two solutions given by community. First Solution: Comment out __construct and __destruct methods in lib/Zend/Pdf/FileParserDataSource.php as follows //    abstract public function __construct();     /**      * Object destructor. Closes the data source.      *      * May also perform cleanup tasks such as deleting temporary files.      */ //    abstract public function __destruct(); Second Solution: simply change the constructor function of lib/Zend/Pdf/FileParserDataSource.php         abstract public function __construct(); TO     abstract public function __construct($filePath);

Magento :: How to update products' attributes correctly without affecting tier prices

I use following code to update magento products without effecting tier prices. Because my earlier code cleared all tier prices after run code. Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);     $id = Mage::getModel('catalog/product')->getIdBySku($prod_sku);     $product = Mage::getModel('catalog/product')->load($id);     if ($product) {       $product->setBarcode($bar_code);       if(! $product->save()){                 $productId = $product->getId();                 echo "product_Id :: ".$productId." - Product sku :: ".$product->getSku()."<br />";             }else{                 echo "not saved";             }      }

Magento :: Inline Translations - How to edit text field using in line translations

To enable inline translations, go to System -> Configurations Go to Advanced section Enable inline translation for front end Refresh page and see dashed boxes to change text as follows Click on the highlighted icon in above images. Following window will appear. Change and submit.

Magento : Password encryption for customer data import

I had to transfer k-ecommerce customer data to magento. I created csv file according to magento customer data upload csv that I got from data profile -> export customer profile. But there was a problem to encrypt password to match with magento. I googled and found this. I will share with others for their reference. Thanks Edward // Change the paths according to your environment require_once 'app/Mage.php'; umask(0); $app = Mage::app('default'); // Instantiate the core encryption model $obj = Mage::getModel('core/encryption'); // Instantiate the core helper $helper = Mage::helper('core'); //Set the encryptions helper $obj->setHelper($helper); // Get the password's hash $enc_pwd = $obj->getHash($pwd, 2); // To validate password, use this. It will return 1 if it is correct echo $obj->validateHash($pwd, $enc_pwd);

Magento - Dataflow - Profiles : How to check failed products in import all product

I have created CSV file and run profile. Some products failed due to image not found issue. I wanted to find out which products have failed in the process. I googled but not found a solution. Finally I used firebug and found failed row number as follows

Magento - Tier Prices on Cart page

Add following after $_item = $this->getItem() ; in checkout/cart/item/default.phtml $_tierPricing = $this->getLayout()->createBlock('catalog/product_view', 'product.tierprices', array( 'product_id' => $_item->getProductId())); $_tierPricing->setTemplate('catalog/product/view/tierprices.phtml'); To print price info: <?php echo $_tierPricing->getTierPriceHtml();?> OR If you want retrieve tier prices for any other purposes, just for show discounts etc. Use followings. $custom = Mage::getModel('catalog/product')->load($_item->getProductId());  var_dump($custom->getTierPrice());