【问题标题】:How to Get more order data as variables in prestashop如何在 prestashop 中获取更多订单数据作为变量
【发布时间】:2018-04-10 07:35:35
【问题描述】:

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

我正在使用下面的代码来获取 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);
        }
    }

如何获取其他订单详情。

#更新 除了带有以下代码的产品数据外,我已经获得了所有订单数据。

$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() 函数代码来获取所有产品详细信息。

【问题讨论】:

    标签: php arrays variables prestashop prestashop-1.6


    【解决方案1】:

    您可以获得如下代码的信息。如果您想了解任何其他信息,请告诉我,我会告诉您。

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

    【讨论】:

    • 我想要像 {first_name} 这样的变量中的这些数据。
    • 我想要这些详细信息 {first_name}{last_name}{shop_name}{id_order}{delivery_address}{items}{message}
    • 这些 {first_name} 不可变。这些是字符串,用变量替换,比如这个变量“$firstname”的值。
    • 我已经尝试过您的代码,但我无法将其放入 str_replace。另外,我已经编辑了我的问题。请检查最后一段。
    • 嘿@ravi2432,现在一切都很好,但我现在需要 getProducts() 代码。
    猜你喜欢
    • 2016-08-18
    • 2015-12-13
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多