INVALID_REQUEST: Field [order.avsDetails.billToFirstname] was not in charset [ISO-8859-1] - magento2

For some Reasons when I use OnTap MasterCard Extension, Any Arabic characters in shippment addresses throws an error:
INVALID_REQUEST: Field [order.avsDetails.billToFirstname] was not in charset [ISO-8859-1]
The extension link :
https://marketplace.magento.com/ontap-module-mastercard.html
Please help.

You can try encoding the data generated in the Builders (inside the Gateway/Request folder) by using plugins.
You can read more how to create plugins here that perform the encoding on all the fields in the builders when needed.
You will create a new module that is doing the modifications needed on the extension you took from the market.
To define your builder in this case your di.xml will look something like:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="\OnTap\MasterCard\Gateway\Request\ShippingDataBuilder">
<plugin name="jsparo_ontap_mastercard_gateway_request_shippingdatabuilder" type="Jsparo\MasterCard\Plugin\Gateway\Request\ShippingDataBuilder" sortOrder="1"/>
</type>
</config>
And the Plugin/Gateway/Request/ShippingDataBuilder.php that you will be something like:
<?php
namespace Jsparo\MasterCard\Plugin\Gateway\Request;
class ShippingDataBuilder {
public function afterBuild(array $subject, $result) {
array_walk_recursive($result, function(&$value) {
$value = mb_convert_encoding($value, 'ISO-8859-1', 'UTF-8');
}
return $result;
}
}
You will have to do this for all the builders that generate incorrect data.

Related

Change the product price after catalog price rules in Magento 2

I need to change the product price in all the pages, for all the operations... on catalog (product listing), cart, etc... after all the catalog rules are applied. I've created a plugin for Magento\Catalog\Pricing\Price\FinalPrice on frontend/di.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Pricing\Price\FinalPrice">
<plugin name="Pefsa_Redondeo_Plugin_Magento_Catalog_Pricing_Price_FinalPrice" type="Pefsa\Redondeo\Plugin\Magento\Catalog\Pricing\Price\FinalPrice" sortOrder="10" disabled="false"/>
</type>
</config>
And then I have the method
public function afterGetMinimalPrice(
\Magento\Catalog\Pricing\Price\FinalPrice $subject,
$result
) {
//Custom code here
return $result;
}
I'm able to get the value on $result only for product page but I can't change that value. Above all I need to change it every where else like the category pages and so on.
Changing the normal price is easy like this approach https://webkul.com/blog/set-custom-product-price-when-displaying-on-front-end-in-magento-2/#comment-44779 ... but when there are catalog rules applied the thing is different.

Magento getEvent()->getOrder empty

I'm trying to get an Observer working to see if a payment has been made via check/cheque, I know the Observer is being used as I have a log record to show. However when I try to access the Order it is either empty or will not print to the log file.
app/etc/modules/Foo_Bar.xml
<?xml version="1.0"?>
<config>
<modules>
<Foo_Bar>
<active>true</active>
<codePool>local</codePool>
</Foo_Bar>
</modules>
</config>
app/code/local/Foo/Bar/etc/config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<config>
<global>
<models>
<foo_bar>
<class>Foo_Bar_Model</class>
</foo_bar>
</models>
<events>
<sales_order_payment_place_end> <!-- event -->
<observers>
<foo_bar> <!-- unique for event -->
<!-- type: singleton | disable | model -->
<class>foo_bar/observer</class>
<method>SalesOrderPaymentPlaceEnd</method>
</foo_bar>
</observers>
</sales_order_payment_place_end>
</events>
</global>
</config>
app/code/local/Foo/Bar/Model/Observer.php
<?php
class Foo_Bar_Model_Observer
{
public function SalesOrderPaymentPlaceEnd(Varien_Event_Observer $observer)
{
Mage::log('Location: SalesOrderPaymentPlaceEnd');
$order = $observer->getEvent()->getOrder();
Mage::log('order: '.$order);
}
}
The first log works as expected, however I'm sure getOrder() isn't working as my second log entry just prints 'order: '.
Thanks
#James has already commented this..I am explaning
The event "sales_order_payment_place_end" located in "app\code\core\Mage\Sales\Model\Order\Payment.php" .
The event have only one parameter that is Payment. So
$order = $observer->getEvent()->getOrder();
will not work. You need to use
$orderPayment = $observer->getEvent()->getPayment();
What worked for me was below:
public function autoInvoiceForOfflinePayment(Varien_Event_Observer $observer)
{
$order = $observer->getEvent()->getPayment()->getOrder();
// In my case I was trying to get the payment method code, e.g.
$order->getPayment()->getMethodInstance()->getCode()
}
I hope this helps (Magento EE 1.14.2)
What I discovered, which I forget and often discover again when creating a hook is to look at the line in the file dispatching the event:
e.g. "app\code\core\Mage\Sales\Model\Order\Payment.php"
Mage::dispatchEvent('sales_order_payment_place_end', array('payment' => $this));
So you want to get the event first, then in the array the payment variable:
$order = $observer->getEvent()->getPayment();
From there you can get any public functions in that file, the same principle seems to apply throughout.

Magento: error for custom module (Class not found in Layout.php)

I tried to create a new custom module (block) in Magento which will show other products from manufacturer on product detail page. When I load product detail page I get:
Fatal error: Class 'AimIT_ManufacturerBlock_Block_Manufacturerblock' not found in ..\app\code\core\Mage\Core\Model\Layout.php on line 491
I have created:
1)\app\etc\modules\AimIT_ManufacturerBlock.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<AimIT_ManufacturerBlock>
<!-- Whether our module is active: true or false -->
<active>true</active>
<!-- Which code pool to use: core, community or local -->
<codePool>local</codePool>
</AimIT_ManufacturerBlock>
</modules>
</config>
2) \app\code\local\AimIT\ManufacturerBlock\etc\config.xml
<?xml version="1.0"?>
<config>
<global>
<blocks>
<aimitmanufacturerblock>
<class>AimIT_ManufacturerBlock_Block</class>
</aimitmanufacturerblock>
</blocks>
</global>
</config>
3) \app\code\local\AimIT\ManufacturerBlock\Block\Manufacturerblock.php
<?php
class AimIT_ManufacturerBlock_Block_Manufacturerblock extends Mage_Core_Block_Template
{
public function getManufacturerProducts($manufacturer)
{
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToFilter('manufacturer',$manufacturer);
$collection->addAttributeToSelect('manufacturer');
return $collection;
}
}
?>
4)\app\design\frontend\default\respond\template\aimit\manufacturerblock\manufacturerblock.phtml
<?php $_products = $this->getManufacturerProducts('cukrarna-u-vanku') ?>
<?php print_r($_products); ?>
5) in catalog\product\view.phtml I have placed this code:
<?php echo $this->getLayout()->createBlock('aimitmanufacturerblock/manufacturerblock')->setTemplate('aimitmanufacturerblock/manufacturerblock.phtml')->toHtml(); ?>
What did I omit while creating the module?
When translating 'aimitmanufacturerblock/manufacturerblock' into a class name Magento generates AimIT_ManufacturerBlock_Block_Manufacturerblock and can't find a class under such name because your block's class name is actually 'AimIT_ManufacturerBlock_Block_ManufacturerBlock' - which is wrongly cased.
Rename your class into
class AimIT_ManufacturerBlock_Block_Manufacturerblock extends Mage_Core_Block_Template
{
Rename your class file ManufacturerBlock.php into Manufacturerblock.php

Symfony Basic Translation Example

I am new to Symfony2. Trying to establish translation Service. I am following the steps given in the official documentation. But not successful.
Following are steps followed
In 'symfony/app/config/config.yml' translation service by defining locale "#translator:{ fallback: %locale% }"
In 'symfony/app/config/parameters.yml' defined locale parameter "locale:de"
In 'src/MyBundle/translateBundle/Resources/translations/messages.de.xlf' is created
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Symfony2 is great</source>
<target>J'aime Symfony2</target>
</trans-unit>
</body>
</file>
</xliff>
Now I hope with this coding now I should get: 'J'aime Symfony2' on execution of following code.
<?php
namespace MyDays\translateBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends Controller {
public function indexAction() {
$t = $this->get ( 'translator' )->trans ( 'Symfony2 is great' );
return new Response ( $t );
}
}
But still getting original text as 'Symfony2 is great'!
Is there anything I have to do apart from the steps given in documentation?
Have you removed # before translator... in config.yml?
Also you need to clear the cache after adding a new translation file.

Joomla 1.7: change meta tags from system plugin

Joomla version 1.7
Plugin enabled in admin part
Plugin code:
<?php
// no direct access
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
class plgSystemMetatags extends JPlugin
{
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
}
public function onBeforeRender()
{
$document =& JFactory::getDocument();
$document->setMetaData('keywords', 'test keywords');
}
}
But this doesn't work
Meta description renders value, which set in global configuration
plugin xml file
<?xml version="1.0" encoding="utf-8"?>
<extension version="1.7" type="plugin" group="system" method="upgrade" client="site">
<name>System - Metatags</name>
<author>Joomla! Project</author>
<creationDate>November 2005</creationDate>
<copyright>Copyright (C) 2005 - 2011 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>admin#joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>1.7.0</version>
<description></description>
<files>
<filename plugin="metatags">metatags.php</filename>
<filename>index.html</filename>
</files>
</extension>
use onBeforeRender instead of onAfterRender.
When onAfterRender event is triggered the output of the application is already available in the response buffer.