问题描述
当管理员将订单状态更改为“已发货”时,我需要获取订单详细信息,以便将它们发布到带有 api 的第三方应用程序。 我正在使用 Prestashop V 1.7.7.0 我需要帮助。谢谢
$city_cl = $_GET['????????'];
$state_cl = $_GET['????????'];
$address_cl = $_GET['????????'];
$tel_2_cl = $_GET['????????'];
$products = $_GET['????????'];
$Quantity = $_GET['????????'];
$cod = $_GET['????????'];
$note = $_GET['????????'];
$Url_str = 'http://example.com/api/set_parcel_post.PHP?id=123&tel_cl='.$tel_cl.'&name_lastname_cl='.$name_lastname_cl.'&city_cl='.$city_cl.'&state_cl='.$state_cl.'&address_cl='.$address_cl.'&tel_2_cl='.$tel_2_cl.'&products='.$products.'&cod='.$cod.'&Quantity='.$Quantity.'¬e='.$note;
$json = file_get_contents($Url_str);
$result = json_decode($json);
我需要帮助。谢谢
解决方法
这是一个超级简单的模块,可以根据需要运行,当订单状态改变时(保存过程后)调用最后一个方法。 您必须遵循有关如何创建和安装模块的指南 (here) 并调用适当的钩子 (list here)
<?php
if (!defined('_PS_VERSION_'))
exit;
class OrderChanger extends Module
{
public function __construct()
{
$this->name = 'orderchanger';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'Stackoverflow user';
$this->need_instance = 0;
$this->ps_versions_compliancy = array('min' => '1.7','max' => _PS_VERSION_);
parent::__construct();
$this->displayName = $this->l('Order changer');
$this->description = $this->l('a description');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
}
public function install()
{
if (Shop::isFeatureActive())
Shop::setContext(Shop::CONTEXT_ALL);
if (!parent::install() ||
!$this->registerHook('actionOrderStatusPostUpdate')
)
return false;
return true;
}
public function uninstall()
{
if (!parent::uninstall())
return false;
return true;
}
public function hookActionOrderStatusPostUpdate($params)
{
$order = new Order((int)$params['id_order']);
//do the stuff
}
}
,
我的代码正确吗?我需要获得国家和州名、产品和订单信息。 请问我该怎么做? 此外,该模块无法安装在 prestashop 中。 需要帮助。谢谢
public function hookActionOrderStatusPostUpdate($params)
{
if($params['newOrderStatus']->id == 13)
{
$order = new Order((int)$params['id_order']);
$address = new Address((int)$order->id_address_delivery);
$customer = new Customer((int)($address->id_customer));
$country = new Country((int)($address->id_country));
$state = new Country((int)($address->id_state));
$tel_cl = $address->phone;
$name_lastname_cl = $address->lastname . ' ' . $address->firstname;
$country_cl = **Not yet**;
$state_cl = **Not yet**;
$adress_cl = $address->address1 . ' ' . $address->address2;
$tel_2_cl = $address->phone_mobile
$products = **Not yet**;
$quantity = "1"
$cod = $order->total_paid
$note = **Not yet(order message)**;
$Url_str = 'http://example.com/api/set_parcel_post.php?id=123&tel_cl='.$tel_cl.'&name_lastname_cl='.$name_lastname_cl.'&city_cl='.$country_cl.'&state_cl='.$state_cl.'&address_cl='.$address_cl.'&tel_2_cl='.$tel_2_cl.'&products='.$products.'&cod='.$cod.'&Quantity='.$Quantity.'¬e='.$note;
$json = file_get_contents($Url_str);
$result = json_decode($json);
return false;
}
}
需要帮助。谢谢