Trigger sms sending based on customized order status in woocommerce - sms

I am using woocommerce twilio extension which allow me to trigger sms based on order status changes in woocommerce. I have added 2 new customized order status - namely Shipping and Delivered. I would like to know what action hook that I can used to hook, to auto send out sms in Twilio.
// Customer order status change hooks
foreach( array( 'pending', 'failed', 'on-hold', 'processing', 'completed', 'refunded', 'cancelled' ) as $status ) {
add_action( 'woocommerce_order_status_' . $status, array( $this, 'send_customer_notification' ) );
}
Looking at the script of extension, it seems to me I am not able to do that because there is no woocommerce_order_statsus_shipping or woocommerce_order_statsus_delivered that I can hook to.
Any way to work around this limitation?

While I haven't worked with woocommerce specifically, I have done a lot with WP hooks in general. It looks like there are two different ways to catch this one:
woocommerce_order_status_.$new_status->slug
which looks like it gets fired when the order shifts into a particular status and
woocommerce_order_status_.$this->status._to_.$new_status->slug
which looks like it catches things moving from one specific status and into another specific status. Does that help?
Source: http://docs.woothemes.com/document/hooks/

Related

Laravel mailchimp event properties are empty in template

Did my research and found nothing about this topic.
In the docs: https://mailchimp.com/developer/marketing/guides/track-outside-activity-events/#create-an-event
Apparently said how to create an event with options, using the library that they said which in PHP is:
composer require mailchimp/transactional
I can ping, do all the simple requests without problem
but some options for events are not even avaliable, for example:
$options = new \MailchimpMarketing\Model\Events();
there is no 'Model' or Events in that namespace,
then of course I looked how this event is build in other languages and I give a try to pass parameters to the event like this:
$options = ["name" => "my-event-name", "properties" => ['PASSLINK' => 'test']];
$response = $mailchimp->lists->createListMemberEvent(
env('MC_AUDIENCE_ID'),
"somemember#gmail.com",
$options
);
200 status response, Event is trigger, mail received
but in the template used, nothing is passed:
I used in that template that event property like this:
*|EVENT:PASSLINK|*
also tried lowercase
*|EVENT:passlink|*
Same result
don't know what else to do
I had a similar issue. Seems that for a journey, the event property merge tag *|EVENT:PROPERTY|* does not work. They only work for classic automation. May be that is the issue.
Same issue here.
I tried all these combination of EVENT properties.
None of them works..
*|EVENT:name|*
*|EVENT:NAME|*
*|EVENT:PROPERTIES|*
*|EVENT:properties|*
*|EVENT:PROPERTIES:CODE|*
*|EVENT:properties:code|*

How to understand what message from the telegram bot answered the user?

I use Laravel Framework and Telegram Bot SDK. I looked at a lot of guides, and all say how easy it is to create a command and get an answer, but I can’t understand how to create dialogs between the user and the bot. In my webhook I can do for example:
$message = Telegram::getWebhookUpdates()->getMessage();
if ($message->getText() == 'something')
foreach (Service::get() as $item => $value){
if($value->name == $message->getText()) {
$credential = Credential::find($value->id);
if($credential) {
Telegram::sendMessage([
'chat_id' => $message->getChat()->getId(),
'text' => 'Enter the data'
]);
}
}
}
}
Telegram::commandsHandler(true);
And after the user sends the data (in numerical format) I need to process the response. But how can I check the message text with a conditional statement, to know that this is the answer to my previous message, if it is any number. For example:
$message = Telegram::getWebhookUpdates()->getMessage();
if($message->getText() == '/start'){
...
}
elseif($message->getText() == **HERE USER RESPONSE WITH DATA**){
...
}
This is only part of the functionality, there are still different commands, variations of keyboards, and therefore I need to understand how to correctly process incoming messages in order to know which particular question I received the answer.
P.S. I found solutions that say that you need to create a database table with message history and based on this do handlers. Are there any other ways?
You can do it by ForceReply in Telegram Bots API. If user's message is a reply, you should find out which message a user replied to. Just check message's text using it's message id. If it's the first question, it means it has been answered and now you can send the second question.
PS: The solutions that you found is probably the better way to do the job. Just create a database table with message history.

How to add / remove elements from array that is in Request

My request looks like this
Array
(
[name] => Eugene A
[address] => Array
(
[billing] => Array
(
[address] => aaa
)
[shipping] => Array
(
[address] => bbb
)
)
)
I need to delete the shipping address. But how?
I can only delete both addresses,
$request->request->remove('address');
but I don't want it.
I want to delete only shipping address, like so
$request->request->remove('address.shipping');
But it is not working for me
Laravel 5.6
Update
Why do I need it?
Easy. I have abstracted out my Form Request validation into a class that is a child to Illuminate\Foundation\Http\FormRequest.
I actually have few classes for validation. I call them one by one in a controller like so:
app()->make(CustomerPostRequest::class); // validate Customer information
app()->make(AddressSaveRequest::class); // validate Addresses
Why?
Now I can Mock this requests in unit-tests, and I can have my validation abstracted out. And I can use Address validation in many places.
But Now I need more flexibility. Why?
Because AddressSaveRequest rule looks like this
public function rules(): array
{
return [
'address.*.address' => [
'bail',
'required',
'string',
],
...
It validates all addresses.
But sometimes I don't want to validate shipping address, if the the chech_box - ship_to_the_same_address is ticked.
But I have my Address validator abstracted in separate file and it is used in many places. There are places where ship_to_the_same_address tick box is not presented.
Thus I cannot use 'required_unless:ship_to_same_address,yes',
And I cannot use
app()->makeWith(AddressSaveRequest::class, ['ship_to_the_same_address ' => 'yes']);
Because Taylor said ...when calling makeWith. In my opinion it should make a new instance each time this method is called because the given parameter array is dynamic.. And it does, and it does not work correctly with app()->instance(AddressSaveRequest::class, $addressSaveRequest); and cannot be mocked in unit tests.
Why Taylor decided it - I seriously don't know.
PS
And yes, I know that mocking requests is not recommended.
If you were trying to add or remove inputs from the Request itself:
You can add data to the request pretty easily by merging it in and letting Laravel handle which data source is being used:
$request->merge(['input' => 'value']);
That will merge in the input named input into the input source for the Request.
For removing inputs you could try to replace all the inputs without that particular input in the replacement:
$request->replace($request->except('address.shipping'));
Just one idea to try.
Try this:
$request->except(['address.shipping']);
Details: Laravel Request
Laravel has a helper method called array_forget, which does exactly what it sounds like:
$requestArray = $request->all();
$newArray = array_forget($requestArray, 'address.shipping')
Documentation
After the edit to the main question with why some inputs of the request are to be deleted, my main answer isn't correct anymore. User Lagbox has the correct answer for the question that was asked.
However, I would like to note that another solution would be to have seperate Request classes with validation. One for placing an order (assuming it is a system where someone can order stuff) where ship_to_same_address is present and another one for things like updating your account, like PlaceOrderRequest and UpdateAccountRequest classes.

Magento adding actions In orders

I'm using Magento Community 1.7. When I go to Sales-->Orders I see all the orders. Currently I can tick certain orders and, using the action dropdown, I can print invoices, cancel, hold etc. I'm wondering if there is anyway that I can add actions like "Requires Refund", "Fraud". The actions wouldn't neccessarily have to do anything just change the status so I can see clearly for later the status of these orders. Any ideas?
In order to add more actions you need to override this method Mage_Adminhtml_Block_Sales_Order_Grid::_prepareMassaction().
For each action you add, you will need a method in the controller you send it to.
Take for example the action Cancel. It is added to the mass action block like this:
$this->getMassactionBlock()->addItem('cancel_order', array(
'label'=> Mage::helper('sales')->__('Cancel'),
'url' => $this->getUrl('*/sales_order/massCancel'),
));
and the corresponding method is Mage_Adminhtml_Sales_OrderController::massCancelAction()

How to confirm an order in Magento using the SOAP webservice?

I'm trying to confirm an order using the Magento web-service. I can put an order on hold like this:
$result = $client->salesOrderHold( $sessionId, $order_id );
echo "Order on Hold: " . $result . "<br>";
or add a comment to the order, but I can't find the function to call to confirm an order.
NOTE: my orders are being confirmed manually, so, I need to do this using the web service.
any help is appreciated!
From Magento version 1.4.2, the status of an order can be customized. So now, you have two kind of value for a status order. Check this link to see what is possible and what are the differences between state and status. Magento state and status
I am not sure of what you are expecting by setting your order to "confirm". If it's just a display needs, you can create yours in backend menu System > Order Statuses. Then you can use the API to addComment with your customized status or an existing one but it won't change the state of the order. It will stay in "On Hold" if it is in this state.
If you want to change the state and not the status, you need to extend the api of the module Mage_Sales to allow to set a status to an order. Magento doesn't offer it by default. As it is written in the link provided in my comment, you cannot edit the status and a state of an order. The method addComment of the API doesn't change the state, it allows only to change the status in the comment. You have to create your method based on the class Mage_Sales_Model_Order_Api. See the following link to do it by yourself Create a custom API
Hope it helps

Resources