如何在prestashop中获取更多订单数据作为变量

时间:2018-04-10 07:35:36

标签: php arrays variables prestashop prestashop-1.6

我想发送一条包含完整订单详细信息的消息,例如名字,姓氏,shop_name,order_id,delivery_address,mobile_number,消息。

我使用下面的代码来获取first_name,last_name,order_reference。

$id_order_state = Tools::getValue('id_order_state');
    if ($id_order_state == 122 && Configuration::get('122') != '') //Configuration::get('Sendin_Api_Sms_shipment_Status') == 1 && 
    {
        $order = new Order(Tools::getValue('id_order'));
        $address = new Address((int)$order->id_address_delivery);
        $customer_civility_result = Db::getInstance()->ExecuteS('SELECT id_gender,firstname,lastname FROM '._DB_PREFIX_.'customer WHERE `id_customer` = '.(int)$order->id_customer);
        $firstname = (isset($address->firstname)) ? $address->firstname : '';
        $lastname  = (isset($address->lastname)) ? $address->lastname : '';

        if (Tools::strtolower($firstname) === Tools::strtolower($customer_civility_result[0]['firstname']) && Tools::strtolower
        ($lastname) === Tools::strtolower($customer_civility_result[0]['lastname']))
            $civility_value = (isset($customer_civility_result['0']['id_gender'])) ? $customer_civility_result['0']['id_gender'] : '';
        else
            $civility_value = '';

        if ($civility_value == 1)
            $civility = 'Mr.';
        else if ($civility_value == 2)
            $civility = 'Ms.';
        else if ($civility_value == 3)
            $civility = 'Miss.';
        else
            $civility = '';

        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
            SELECT `call_prefix`
            FROM `'._DB_PREFIX_.'country`
            WHERE `id_country` = '.(int)$address->id_country);

        if (isset($address->phone_mobile) && !empty($address->phone_mobile))
        {
            $order_date = (isset($order->date_upd)) ? $order->date_upd : 0;
            if ($this->context->language->id == 1)
                $ord_date = date('m/d/Y', strtotime($order_date));
            else
                $ord_date = date('d/m/Y', strtotime($order_date));

            $msgbody =  Configuration::get('122');
            $total_pay = (isset($order->total_paid)) ? $order->total_paid : 0;
            $total_pay = $total_pay.''.$this->context->currency->iso_code;
            if (_PS_VERSION_ < '1.5.0.0')
                $ref_num = (isset($order->id)) ? $order->id : '';
            else
                $ref_num = (isset($order->reference)) ? $order->reference : '';

            $civility_data = str_replace('{civility}', $civility, $msgbody);
            $fname = str_replace('{first_name}', $firstname, $civility_data);
            $lname = str_replace('{last_name}', $lastname."\r\n", $fname);
            $product_price = str_replace('{order_price}', $total_pay, $lname);
            $order_date = str_replace('{order_date}', $ord_date."\r\n", $product_price);
            $msgbody = str_replace('{order_reference}', $ref_num, $order_date);
            $arr = array();
            $arr['to'] = $this->checkMobileNumber($address->phone_mobile, $result['call_prefix']);
            $arr['text'] = $msgbody;

            $this->sendSmsApi($arr);
        }
    }

如何获取其他订单详情。

#UPDATE 我有以下代码的产品数据以外的所有订单数据。

$id_order_state = Tools::getValue('id_order_state');
    if ($id_order_state == 122 && Configuration::get('122') != '') //Configuration::get('Sendin_Api_Sms_shipment_Status') == 1 && 
    {
        $configuration = Configuration::getMultiple(
        array(
            'PS_SHOP_EMAIL',
            'PS_MAIL_METHOD',
            'PS_MAIL_SERVER',
            'PS_MAIL_USER',
            'PS_MAIL_PASSWD',
            'PS_SHOP_NAME',
            'PS_MAIL_COLOR'
        ), $id_lang, null, $id_shop
    );

        $order = new Order(Tools::getValue('id_order'));
        $address = new Address((int)$order->id_address_delivery);
        $dlv_adr_fields = AddressFormat::getOrderedAddressFields($address->id_country);
        $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($address, $dlv_adr_fields);
        $city = $address->city;
        $address2 = $address->address1;
        $number = $address->phone_mobile;
        $payment = $order->payment;
        $orderid = $order->id;
        $shop_name = $configuration['PS_SHOP_NAME'];
        $message = $this->getAllMessages($order->id);

    if (!$message || empty($message))
        $message = $this->l('No message');



        $customer_civility_result = Db::getInstance()->ExecuteS('SELECT id_gender,firstname,lastname FROM '._DB_PREFIX_.'customer WHERE `id_customer` = '.(int)$order->id_customer);
        $firstname = (isset($address->firstname)) ? $address->firstname : '';
        $lastname  = (isset($address->lastname)) ? $address->lastname : '';

        if (Tools::strtolower($firstname) === Tools::strtolower($customer_civility_result[0]['firstname']) && Tools::strtolower
        ($lastname) === Tools::strtolower($customer_civility_result[0]['lastname']))
            $civility_value = (isset($customer_civility_result['0']['id_gender'])) ? $customer_civility_result['0']['id_gender'] : '';
        else
            $civility_value = '';

        if ($civility_value == 1)
            $civility = 'Mr.';
        else if ($civility_value == 2)
            $civility = 'Ms.';
        else if ($civility_value == 3)
            $civility = 'Miss.';
        else
            $civility = '';

        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
            SELECT `call_prefix`
            FROM `'._DB_PREFIX_.'country`
            WHERE `id_country` = '.(int)$address->id_country);

        if (isset($address->phone_mobile) && !empty($address->phone_mobile))
        {
            $order_date = (isset($order->date_upd)) ? $order->date_upd : 0;
            if ($this->context->language->id == 1)
                $ord_date = date('m/d/Y', strtotime($order_date));
            else
                $ord_date = date('d/m/Y', strtotime($order_date));

            $msgbody =  Configuration::get('122');
            $total_pay = (isset($order->total_paid)) ? $order->total_paid : 0;
            $total_pay = $total_pay.''.$this->context->currency->iso_code;
            if (_PS_VERSION_ < '1.5.0.0')
                $ref_num = (isset($order->id)) ? $order->id : '';
            else
                $ref_num = (isset($order->reference)) ? $order->reference : '';

            $civility_data = str_replace('{civility}', $civility, $msgbody);
            $cit = str_replace('{city}', $city, $civility_data);
            $addr1= str_replace('{addr1}', $address2, $cit);
            $mobi= str_replace('{mobi}', $number, $addr1);
            $pay= str_replace('{pay}', $payment, $mobi);
            $oid= str_replace('{oid}', $orderid, $pay);
            $sname = str_replace('{sname}', $shop_name, $oid);
            $itms = str_replace('{itms}', $items_table2, $sname);
            $msg= str_replace('{msg}', $message, $itms);
            $fname = str_replace('{first_name}', $firstname, $msg);
            $lname = str_replace('{last_name}', $lastname."\r\n", $fname);
            $product_price = str_replace('{order_price}', $total_pay, $lname);
            $order_date = str_replace('{order_date}', $ord_date."\r\n", $product_price);
            $msgbody = str_replace('{order_reference}', $ref_num, $order_date);
            $arr = array();
            $arr['to'] = '$mobile';
            $arr['text'] = $msgbody;

            $this->sendSmsApi($arr);
        }
    }

现在我需要getProducts()函数代码来获取所有产品详细信息。

1 个答案:

答案 0 :(得分:0)

您可以获取以下代码等信息。如果您需要任何其他信息,请告诉我。

 $id_order_state = (int)$order->getCurrentState();
            $carrier = new Carrier((int)$order->id_carrier, (int)$order->id_lang);
            $addressInvoice = new Address((int)$order->id_address_invoice);
            $addressDelivery = new Address((int)$order->id_address_delivery);

            $inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country);
            $dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country);

            $invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressInvoice, $inv_adr_fields);
            $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields);

            if ($order->total_discounts > 0) {
                $this->context->smarty->assign('total_old', (float)$order->total_paid - $order->total_discounts);
            }
            $products = $order->getProducts();

            /* DEPRECATED: customizedDatas @since 1.5 */
            $customizedDatas = Product::getAllCustomizedDatas((int)$order->id_cart);
            Product::addCustomizationPrice($products, $customizedDatas);

            OrderReturn::addReturnedQuantity($products, $order->id);
            $order_status = new OrderState((int)$id_order_state, (int)$order->id_lang);

            $customer = new Customer($order->id_customer);