Magento: Send a mail directly to my supplier when payment is set to be received - email

I'd like to send an automatic email to my supplier, when the order is checked as payed. I've a external supplier that start to produce when i tell him, so when the payment is received, I can confirm to him the production. I'd like to automate this process and I like to use a similar confirmation order email, but adding a custom attribute instead of the sku.
Thank you!
--- EDIT ---
I'm reached my goal inserting those lines, but I've still some problem in the Observer line 24 at $result line, there's an error for one ",".
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Electricjesus_Notifyowner>
<version>0.1.0</version>
</Electricjesus_Notifyowner>
</modules>
<global>
<models>
<notifyowner>
<class>Electricjesus_Notifyowner_Model</class>
</notifyowner>
</models>
<events>
<sales_order_payment_pay>
<observers>
<notifyOwnerEvent>
<class>notifyowner/observer</class>
<method>notifyOwnerEvent</method>
</notifyOwnerEvent>
</observers>
</sales_order_payment_pay >
</events>
</global>
Electricjesus_Notifyowner.xml
<?xml version="1.0"?>
<config>
<modules>
<Electricjesus_Notifyowner>
<active>true</active>
<codePool>local</codePool>
</Electricjesus_Notifyowner >
</modules>
and Observer.php with the error
// parameters you can get from the $observer parameter:
// array(’payment’ ? $this, ‘invoice’ ? $invoice)
$payment = $observer->getPayment();
$invoice = $observer->getInvoice();
// derivative data
$order = $invoice->getOrder(); // Mage_Sales_Model_Order
$ownerEmail = 'test#gmail.com';
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('order_new');
$emailTemplate
->setSenderName(Mage::getStoreConfig('trans_email/ident_support/name'))
->setSenderEmail(Mage::getStoreConfig('trans_email/ident_support/email'))
->setTemplateSubject('Prova di Ordine Confermato dopo pagamento');
$result = $emailTemplate->send(Mage::getStoreConfig('trans_email/ident_general/email'),(Mage::getStoreConfig('trans_email/ident_general/name'), $observer->getCustomer()->getData());
/*
- build data
- build email structure
- send email via any php mailer method you want
*/
return $this; // always return $this.
}
}
Can you pls help me to undestand why the error for a comma? Thank you!

There in magento has two dispatch event
1.sales_order_payment_place_end
2. sales_order_payment_place_start.
As per your Please follow my below code. add observer
<global>
<events>
<sales_order_payment_place_end>
<observers>
<mymodule>
<type>singleton</type>
<class>mymodule/observer</class>
<method>handleOrder</method>
</mymodule>
</observers>
</sales_order_payment_place_end>
</events>
</global>
Then create observer.php under model directory
class Mycompany_Mymodule_Model_Observer
{
public function handlePayment($observer)
{
$order = $observer->getOrder();
$payment=$order->getPayment();
/// put logic as per your requirement.
}
}
I did not get time to test this code but i am sure logic is same like this. Thanks.

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.

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

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.

Magento2 Soap service not working

I tried to create a soap service but somehow its wsdl url is not working. Below is the code:-
Api/CustomapitInterface.php
namespace W3solver\Customapi\Api;
interface CustomapiInterface
{
/**
* Returns greeting message to user
*
* #api
* #param string $name Users name.
* #return string Greeting message with users name.
*/
public function name($name);
}
model/Customapi.php
<?php
namespace W3solver\Customapi\Model;
use W3solver\Customapi\Api\CustomapiInterface;
class Customapi implements CustomapiInterface
{
/**
* Returns greeting message to user
*
* #api
* #param string $name Users name.
* #return string Greeting message with users name.
*/
public function name($name) {
return "Hello, " . $name;
}
}
etc/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">
<preference for="W3solver\Customapi\Api\CustomapiInterface" type="W3solver\Customapi\Model\Customapi" />
</config>
etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="W3solver_Customapi" setup_version="1.0.0" />
</config>
etc/webapi.xml
<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/customapi/name/:name" method="GET">
<service class="W3solver\Customapi\Api\CustomapiInterface" method="name"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>
I have created this by using a refrence from http://inchoo.net/magento/api-magento/magento-2-custom-api/. I did not where this get wrong.
Below is the url i am trying to use:-
http://magento2.local/index.php/soap/default?wsdl&services=w3solverCustomapiV1
Magento 2 has API access to anonymous APIs disabled by default, you will need to enable this from the backend administration panel.
To disable this feature, log in to the Admin panel and select
Stores > Configuration > Services > Magento Web API > Web API Security.
Then select Yes from the Allow Anonymous Guest Access menu.
You can find more information on the dev guidelines here.

how to delete a scenario in atg through API methods

I have created a scenario by creating a myScenario.sdl in my local config folder /atg/registry/data/scenarios/myScenario.sdl
myScenario.sdl
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE process SYSTEM "dynamosystemresource:/atg/dtds/pdl/pdl_1.0.dtd">
<process author="admin" creation-time="1413804041263" enabled="false" last-modified-by="admin" modification-time="1413804191188">
<segment migrate-subjects="true">
<segment-name>ItemAddedToOrder</segment-name>
<!--================================-->
<!--== Item added to order Quantity with fraction is defined -->
<!--================================-->
<event id="1">
<event-name>atg.commerce.order.ItemAddedToOrder</event-name>
<filter construct="event-property-filter" operator="isNotNull">
<event-property construct="event-property">
<property-name>quantityWithFraction</property-name>
</event-property>
</filter>
</event>
<!--================================-->
<!--== Log a message message: Quantity With Fraction is Defines logTriggeringEvent: true -->
<!--================================-->
<action id="2">
<action-name>Log a message</action-name>
<action-param name="message">
<constant>Quantity With Fraction is Defines</constant>
</action-param>
<action-param name="logTriggeringEvent">
<constant type="java.lang.Boolean">true</constant>
</action-param>
</action>
</segment>
</process>
And enabled the scenario:
Registry scenarioRegistry = scenarioManager.getScenarioRegistry();
byte[] data = (byte[]) scenarioRegistry.getItem(pScenarioPath);
String xml = null;
if (data != null) {
xml = new String(data, "UTF-8");
} else {
Assert.fail("No scenario is existed to enable/disable");
}
String updatedXml;
if (scenarioState && xml != null) {
updatedXml = xml.replaceAll("enabled=\"false\"", "enabled=\"true\"");
} else {
updatedXml = xml.replaceAll("enabled=\"true\"", "enabled=\"false\"");
}
scenarioRegistry.putItem(pScenarioPath, updatedXml.getBytes("UTF-8"));
Now with this above written code, I can both disable or enable the scenario by changing the state as false and true respectively. But I want to delete the scenario(please remember, my requirement is DELETE not DISABLE SCENARIO). I know using scenarioManager.updateScenario() deleted the scenario. Is my understanding right?
One more thing, I know I can delete the scenario directly from ACC. But I need to code via code not manually from ACC.
Please share your thoughts!
Did you try scenarioRegistry.removeItem(path);

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.