WordPress: Remove IP-Logging on WordPress Comments (Solution)

12. Dezember 2016 at 13:39

Wordpress logo

Add this to your functions.php:

add_filter('pre_comment_user_ip', 'no_ips');
function no_ips($comment_author_ip){
    return '';
}

You’ll still have the comment_author_IP field in the db, but it will be empty…

And to remove existing IP records from the db run this query:

UPDATE `wp_comments` SET `comment_author_IP` = ''

Please share this article von facebook & google plus or where you want, thank you!

 
GD Star Rating
loading...
GD Star Rating
loading...

(Solution): MDN CrmTicket Bug when searching for a name and go back to Grid View

23. August 2016 at 18:18

firebug

In function „getCondition“ in der class
app/code/community/MDN/CrmTicket/Block/Admin/Widget/Grid/Column/Filter/CustomerName.php

change this buggy part

        if ($customerIdsSelected && sizeof($customerIdsSelected)>0) {
            if((count($customerIdsSelected) == 1) && count($customerIdsSelected[0] > 0)) {
                return array('in' => $customerIdsSelected);
            } else {
                return null;
            }
        }
        else
          return null;
      }

to

        if ($customerIdsSelected && sizeof($customerIdsSelected)>0) {
            if(count($customerIdsSelected) == 1 && count($customerIdsSelected[0]) > 0) {
                return array('in' => $customerIdsSelected);
            } else {
                return null;
            }
        }
        else
          return null;
      }

BTW: The programmer from MDN-CrmTicket unfortunately disregard both Zend and Magento Coding Style Guide! 🙁

 

Please share this article von facebook & google plus or where you want, thank you!

GD Star Rating
loading...
GD Star Rating
loading...

Sending json data to a remote server – howto

21. April 2016 at 14:00

firebug

If you’re sending json requests there are different possible solutions on programming with php. Here some different explained:

1. Using Streams

‚method‘ => ‚POST‘,
‚content‘ => json_encode( $data ),
‚header’=> „Content-Type: application/json\r\n“ .
„Accept: application/json\r\n“
)
);

$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result);
var_dump($response);

2. Raw HTTP Post

Using Zend Framework’s HTTP client: http://framework.zend.com/manual/en/zend.http.client.advanced.html#zend.http.client.raw_post_data

$json = json_encode($data);
$client = new Zend_Http_Client($url);
$client->setRawData($json, ‚application/json‘)->request(‚POST‘);
var_dump($client->request()->getBody());

3. Using Curl

<?php
$content = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
        array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //curl error SSL certificate problem, verify that the CA cert is OK
$result     = curl_exec($curl);
$response   = json_decode($result);
var_dump($response);
curl_close($curl);
?>

4. Using Ajax

var data = <?php echo json_encode($data) ?>;
var url  = '<?php echo $url ?>';
jQuery.ajax({
    type: "POST",
    url: url,
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(data){
        var jsonObj = jQuery.parseJSON(data);
        alert(jsonObj.encPassword);
    },
    failure: function(errorMsg) {
        alert(errorMsg);
    }
});

Please share this article von facebook & google plus or where you want, thank you!

GD Star Rating
loading...
GD Star Rating
loading...

Magento: Delete all categories with sql

23. März 2016 at 10:44

magento-sql-query-to-delete-the-categories

To delete all categories in Magento about sql you can use the following query.

If you has more than 3 stores, you must extend the entry „catalog_product_flat_1;“ with your store-id, e.g.:

DELETE FROM catalog_product_flat_3;
DELETE FROM catalog_product_flat_4;

and so on …

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `catalog_category_entity`;
TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_product_entity`;
TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_entity`;
TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `catalog_category_product`;
DELETE FROM catalog_product_flat_1;
DELETE FROM catalog_product_flat_2;
DELETE FROM catalog_product_flat_3;
SET FOREIGN_KEY_CHECKS = 1;
insert  into `catalog_product_link_type`(`link_type_id`,`code`) values (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
insert  into `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) values (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
insert  into `cataloginventory_stock`(`stock_id`,`stock_name`) values (1,'Default');

Please share this article von facebook & google plus or where you want, thank you!

GD Star Rating
loading...
GD Star Rating
loading...

Magento: How to easily Debug Layout Xml Warning/Error?

16. März 2016 at 16:30

magento-xml-config-xml

If you get an error like „Warning: simplexml_load_string(): Entity: line 46: parser error : Comment not terminated in */lib/Varien/Simplexml/Config.php on line 510

in Magento you can do one of the following solution to solve this XML error.

This warning is related to some config.xml error, so a possible workaround to find out the exact file is to mod. the /lib/Varien/Simplexml/Config.php class.

You should modify Varien_Simplexml_Config::loadString() method:

public function loadString($string)
{
if (is_string($string)) {
// Enable internal errors
libxml_use_internal_errors(true);
$xml = simplexml_load_string($string, $this->_elementClass);
if (false === $xml) {
// Put breakpoint here
$errors = libxml_get_errors();
}
if ($xml instanceof Varien_Simplexml_Element) {
$this->_xml = $xml;
return true;
}
} else {
Mage::logException(new Exception('"$string" parameter for simplexml_load_string is not a string'));
}
return false;
}

In case the error is related to some Layout file ( Update.php line 444 warning )

You should modify Mage_Core_Model_Layout_Update::getFileLayoutUpdatesXml() method in a similar way:

public function getFileLayoutUpdatesXml($area, $package, $theme, $storeId = null)
{
if (null === $storeId) {
$storeId = Mage::app()->getStore()->getId();
}
/* @var $design Mage_Core_Model_Design_Package */
$design = Mage::getSingleton('core/design_package');
$layoutXml = null;
$elementClass = $this->getElementClass();
$updatesRoot = Mage::app()->getConfig()->getNode($area.'/layout/updates');
Mage::dispatchEvent('core_layout_update_updates_get_after', array('updates' => $updatesRoot));
$updateFiles = array();
foreach ($updatesRoot->children() as $updateNode) {
if ($updateNode->file) {
$module = $updateNode->getAttribute('module');
if ($module && Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $module, $storeId)) {
continue;
}
$updateFiles[] = (string)$updateNode->file;
}
}
// custom local layout updates file - load always last
$updateFiles[] = 'local.xml';
$layoutStr = '';
foreach ($updateFiles as $file) {
$filename = $design->getLayoutFilename($file, array(
'_area'    => $area,
'_package' => $package,
'_theme'   => $theme
));
if (!is_readable($filename)) {
continue;
}
$fileStr = file_get_contents($filename);
$fileStr = str_replace($this->_subst['from'], $this->_subst['to'], $fileStr);
libxml_use_internal_errors(true);
$fileXml = simplexml_load_string($fileStr, $elementClass);
if (false === $fileXml) {
// Put breakpoint here
$errors = libxml_get_errors();
$err = array($filename, $errors);
// error detail and file name will be printed
Zend_Debug::dump($err);
die();
}
if (!$fileXml instanceof SimpleXMLElement) {
continue;
}
$layoutStr .= $fileXml->innerXml();
}
$layoutXml = simplexml_load_string('<layouts>'.$layoutStr.'</layouts>', $elementClass);
return $layoutXml;
}

Now just reload the page a read the error info.

Please share this article von facebook & google plus or where you want, thank you!

GD Star Rating
loading...
GD Star Rating
loading...

Magento 1.9.2.2 Upgrade Conflict issue / SUPEE-6788 security patch – Solution for this problem

10. November 2015 at 11:25

db

Magento has released a new upgrade for Magento which includes the SUPEE-6788 Patch Bundle. Note that this upgrade can break some modules which are not correctly coded.

I have tested the upgrade thru Magento Connect Manager but it failed.

I am testing in Linux Bash / Windows CLI:

chmod 755 mage
sudo -u www-data ./mage list-upgrades
sudo -u www-data ./mage upgrade-all

I have the same error in command line

Error:
upgrade-all: Failed to delete files: /home/data/www/magento_dev/./pkginfo/Mage_All_Latest.txt
Check permissions
Error:
upgrade-all: Package community/Interface_Adminhtml_Default 1.9.2.2 conflicts with: community/Mage_All_Latest 1.9.2.1
Error:
upgrade-all: Package community/Interface_Frontend_Default 1.9.2.2 conflicts with: community/Mage_All_Latest 1.9.2.1
Error:
upgrade-all: Package community/Interface_Install_Default 1.9.2.2 conflicts with: community/Mage_All_Latest 1.9.2.1
Error:
upgrade-all: Package community/Mage_Downloader 1.9.2.2 conflicts with: community/Mage_All_Latest 1.9.2.1
Error:
upgrade-all: Package community/Mage_Centinel 1.9.2.2 conflicts with: community/Mage_All_Latest 1.9.2.1
...

On stack exchange, there are some idea how to proceed.

Solution – First Step

cd pkginfo
# rm -Rf Mage_All_Latest.txt Mage_All.txt
# cd ..
# sudo -u www-data ./mage upgrade-all
Installing package community/Mage_All_Latest 1.9.2.2
Package community/Mage_All_Latest 1.9.2.2 installed successfully
Starting to download Interface_Adminhtml_Default-1.9.2.2.tgz ...
...done: 1,014,275 bytes
Installing package community/Interface_Adminhtml_Default 1.9.2.2
Package community/Interface_Adminhtml_Default 1.9.2.2 installed successfully
Starting to download Interface_Frontend_Default-1.9.2.2.tgz ...
...done: 747,738 bytes
Installing package community/Interface_Frontend_Default 1.9.2.2
...

Now delete the maintenance.flag file and your shop is updated and online! 🙂

Please share this article von facebook & google plus or where you want, thank you!

GD Star Rating
loading...
GD Star Rating
loading...

Fix: TypeError: jQuery(.sf-menu).superfish is not a function

14. September 2015 at 15:40

XHTML

If you’re working with the superfish drop down menu and you’re getting the error message „TypeError: jQuery(.sf-menu).superfish is not a function“ it is possible that you’re loading the jquery script twice, e.g.:

<script type="text/javascript" src="/assets/js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="/skin/frontend/default/default/js/jquery-1.11.1.min.js"></script>

Solution 1

Remove the dublicated js-implementation (remove one of this lines)

Solution 2

If you need to include two versions of jquery on the same page because of plugin support or so …
Change the lines

jQuery(function(){
	jQuery('.sf-menu').superfish()
})

to

jQuery(function(){
	$(document).ready(function(){
		jQuery('.sf-menu').superfish()
	});
})

if you get an error like „$(document).ready is not a function“
use:

(function($){
	$(document).ready(function(){
		$('.sf-menu').superfish()
	});
})(jQuery);

Please share this article von facebook & google plus or where you want, thank you!

GD Star Rating
loading...
GD Star Rating
loading...

Magento: Access Denied errors after installing SUPEE-6285 or since Magento 1.9.2.1 – ACL Error – Solution

13. August 2015 at 15:06

If you use restricted admin accounts, some menus of third party extensions might not work anymore for them. The reason is that the default return value of Mage_Adminhtml_Controller_Action::_isAllowed() has been changed from true to Mage::getSingleton(‚admin/session‘)->isAllowed(‚admin‘). Extensions that do not override this method in their admin controllers because they don’t use the ACL, now need the „ALL“ privilege.

The only solution is to patch the extensions and add this method to all their admin controllers:

protected function _isAllowed()
{
  return true;
}

Or if they actually have an ACL resource defined in etc/adminhtml.xml:

protected function _isAllowed()
{
  return Mage::getSingleton('admin/session')->isAllowed('ENTER RESOURCE IDENTIFIER HERE'); //e.g. 'admin/sales/productreturn'</pre>
} 

 

Please share this article von facebook & google plus or where you want, thank you!

GD Star Rating
loading...
GD Star Rating
loading...

Magento: Product options are wrong if order edit in admin and last order article is taken

15. Juli 2015 at 12:48

php code

If you edit an order and take over last article it is possible that the wrong product options are mapped.

The reason is that the wrong options are taken – not the „options“ taken – magento get the „info_buyRequest“-options from the database, but sometimes the „options“ array has the options data that you need.

You can solve this problem with overwriting the „getBuyRequest()“ function in app/code/local/Mage/Sales/Model/Order/Item.php with this php code:

/**
 * Returns formatted buy request - object, holding request received from
 * product view page with keys and options for configured product
 *
 * @return Varien_Object
 */
public function getBuyRequest()
{
    $option = $this-&gt;getProductOptionByCode('info_buyRequest');   // this get the wrong options
    $option2 = $this-&gt;getProductOptionByCode('options');
    foreach($option2 as $option_tmp) {
        if($option_tmp['option_type'] == 'area'
            || $option_tmp['option_type'] == 'file'
            || $option_tmp['option_type'] == 'field'
            || $option_tmp['option_type'] == 'date'
            || $option_tmp['option_type'] == 'date_time'
            || $option_tmp['option_type'] == 'time'
        ) {
            $option['options'][$option_tmp['option_id']] = $option_tmp['value'];
        } elseif($option_tmp['option_type'] == 'drop_down'
            &amp;&amp; $option_tmp['label'] == 'Farbe'
            &amp;&amp; $productOptions = $this-&gt;getProduct()-&gt;getOptions()[$option_tmp['option_id']]-&gt;getValues()
        ) {
            foreach($productOptions as $productOption) {
                if($productOption-&gt;getData('title') == $option_tmp['value']) {
                    $option['options'][$option_tmp['option_id']] = $productOption-&gt;getData('option_type_id');
                }
            }
        } else {
            $option['options'][$option_tmp['option_id']][0] = $option_tmp['option_value'];
        }
    }
    unset($option2, $option_tmp, $productModel, $attr);
    if (!$option) {
        $option = array();
    }
    $buyRequest = new Varien_Object($option);
    $buyRequest-&gt;setQty($this-&gt;getQtyOrdered() * 1);
    return $buyRequest;
}

 

Please share this article von facebook & google plus or where you want, thank you!

GD Star Rating
loading...
GD Star Rating
loading...

Magento: Save admin name to order_status change using an Observer

28. April 2015 at 15:24

php code

config.xml:

<adminhtml>
  <events>
    <sales_order_status_history_save_before>
      <observers>
        <module_status_history_save_before>
          <class>module/observer</class>
          <method>addUserNameBeforeComment</method>
        </module_status_history_save_before>
      </observers>
    </sales_order_status_history_save_before>
  </events>
</adminhtml>

Observer.php:

public function addUserNameBeforeComment($observer)
{
        $data = '<strong>' . Mage::getSingleton('admin/session')->getUser()->getFirstname() . ' ' . Mage::getSingleton('admin/session')->getUser()->getLastname() . ': </strong>';
        $history = Mage::app()->getRequest()->getPost('history');
        if ($history && isset($history['comment']) && $history['comment'] != '') {
            $history['comment'] = $data . $history['comment'];
            Mage::app()->getRequest()->setPost('history', $history);
        }
}

 

Please share this article von facebook & google plus or where you want, thank you!

GD Star Rating
loading...
GD Star Rating
loading...