Prestashop 1.7 模块:需要获取“国家”和“州”名称、“产品”和“订单消息”

问题描述

我正在开发一个模块,当管理员将订单状态更改为“已发货”时,它会获取订单详细信息,以便将它们发布到带有 api 的第三方应用程序。我使用的是 Prestashop V 1.7.7.0。

我仍然需要获得“国家/地区”“州”名称“产品”“订单信息”。请问我该怎么做?

此外,该模块无法安装在 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.'&country_cl='.$country_cl.'&state_cl='.$state_cl.'&address_cl='.$address_cl.'&tel_2_cl='.$tel_2_cl.'&products='.$products.'&cod='.$cod.'&Quantity='.$Quantity.'&note='.$note;

    $json = file_get_contents($Url_str);
    $result = json_decode($json);
        }
    }

解决方法

您不能使用 id_state 实例化 Country 对象,因此:

 $state = new Country((int)($address->id_state));

是错误的,应该是

 $state = new State((int) $address->id_state);

所以你可以得到像 $state->name 这样的州名, 要获取产品订单,您可以使用 $order->getProducts();,它将返回一个填充了订单产品及其信息(名称、价格等)的数组