Search code examples
prestashopprestashop-1.6prestashop-1.7prestashop-1.5prestashop-modules

Prestashop 1.7 module : Need to get "Country" and "State" names, "Products" and "Order message"


I am developing a module, it gets order details when order statut is changed to "shipped" by admin, to post them to a third party application with api. I am using Prestashop V 1.7.7.0.

I still need to get "country" and "state" names, "products" and "order message". How can i do that please?

Also, the module can't be installed in prestashop. Is my code right?

Need help please. Thanks

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);
        }
    }

Solution

  • You can't instantiate a Country object using an id_state so this:

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

    is wrong and should be

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

    So you can get the state name like $state->name, To get the product orders you can use $order->getProducts(); which will return an array filled with the order products and its information(name,price,etc..)