问题描述
我有这段代码
$collection->getSelect()
->reset(\Zend_Db_Select::COLUMNS)
->columns(["driver_name" => new \Zend_Db_expr("CONCAT(driver.first_name,driver.last_name)")])
->columns(["delivery_date" => 'order.cedDeliveryDate'])
->columns(["delivery_timeslot" => 'order.cedTimestamp'])
->join(
['driver' => $collection->getTable('magenative_mobidelivery_driver')],'main_table.driver_id = driver.id'
)
->join(
['order' => $collection->getTable('sales_order')],'main_table.increment_id = order.increment_id'
);
我正在尝试仅选择特定字段,即驱动程序名称,交货日期和订单时间段。但是当我尝试使用此代码进行打印时
echo "<pre>";print_r($collection->getData()[0]);die;
它仍然打印所有字段,而不是上面提到的特定字段。
Array
(
[driver_name] => NayminSoe
[delivery_date] => 2019-12-12 00:00:00
[delivery_timeslot] => 14:00 - 18:00
[id] => 3
[role] => driver
[first_name] => Naymin
[last_name] => Soe
[password] => naymin123
[user_name] => naymin
[email] => naymin@wine.delivery
[store_id] => 1
[status] => out_for_delivery
[mobile_number] => 456
[image] =>
[is_do] =>
[entity_id] => 2115
[state] => complete
[coupon_code] =>
[protect_code] => 04bf460b05586d0a4ce695facb1e0b89
[shipping_description] => Marketplace Rates
[is_virtual] => 0
[customer_id] => 1738
[base_discount_amount] => 0.0000
[base_discount_canceled] =>
[base_discount_invoiced] => 0.0000
[base_discount_refunded] =>
[base_grand_total] => 116.0000
[base_shipping_amount] => 0.0000
[base_shipping_canceled] =>
[base_shipping_invoiced] => 0.0000
[base_shipping_refunded] =>
[base_shipping_tax_amount] => 0.0000
[base_shipping_tax_refunded] =>
[base_subtotal] => 99.0700
[base_subtotal_canceled] =>
[base_subtotal_invoiced] => 99.0700
[base_subtotal_refunded] =>
[base_tax_amount] => 6.9300
[base_tax_canceled] =>
[base_tax_invoiced] => 6.9300
[base_tax_refunded] =>
[base_to_global_rate] => 1.0000
[base_to_order_rate] => 1.0000
[base_total_canceled] =>
[base_total_invoiced] => 116.0000
[base_total_invoiced_cost] => 0.0000
[base_total_offline_refunded] =>
[base_total_online_refunded] =>
[base_total_paid] => 116.0000
[base_total_qty_ordered] =>
[base_total_refunded] =>
[discount_amount] => 0.0000
[discount_canceled] =>
[discount_invoiced] => 0.0000
[discount_refunded] =>
[grand_total] => 116.0000
[shipping_amount] => 0.0000
[shipping_canceled] =>
[shipping_invoiced] => 0.0000
[shipping_refunded] =>
[shipping_tax_amount] => 0.0000
[shipping_tax_refunded] =>
[store_to_base_rate] => 0.0000
[store_to_order_rate] => 0.0000
[subtotal] => 99.0700
[subtotal_canceled] =>
[subtotal_invoiced] => 99.0700
[subtotal_refunded] =>
[tax_amount] => 6.9300
[tax_canceled] =>
[tax_invoiced] => 6.9300
[tax_refunded] =>
[total_canceled] =>
[total_invoiced] => 116.0000
[total_offline_refunded] =>
[total_online_refunded] =>
[total_paid] => 116.0000
[total_qty_ordered] => 2.0000
[total_refunded] =>
[can_ship_partially] =>
[can_ship_partially_item] =>
[customer_is_guest] => 0
[customer_note_notify] => 1
[billing_address_id] => 3580
[customer_group_id] => 1
[edit_increment] =>
[email_sent] => 1
[send_email] => 1
[forced_shipment_with_invoice] =>
[payment_auth_expiration] =>
[quote_address_id] =>
[quote_id] => 3308
[shipping_address_id] => 3579
[adjustment_negative] =>
[adjustment_positive] =>
[base_adjustment_negative] =>
[base_adjustment_positive] =>
[base_shipping_discount_amount] => 0.0000
[base_subtotal_incl_tax] => 106.0000
[base_total_due] => 0.0000
[payment_authorization_amount] =>
[shipping_discount_amount] => 0.0000
[subtotal_incl_tax] => 106.0000
[total_due] => 0.0000
[weight] => 0.8000
[customer_dob] =>
[increment_id] => SOSG19121115183791
[applied_rule_ids] =>
[base_currency_code] => SGD
[customer_email] => mark.457240@gmail.com
[customer_firstname] => Mark
[customer_lastname] => Lauw
[customer_middlename] =>
[customer_prefix] =>
[customer_suffix] =>
[customer_taxvat] =>
[discount_description] =>
[ext_customer_id] =>
[ext_order_id] =>
[global_currency_code] => SGD
[hold_before_state] =>
[hold_before_status] =>
[order_currency_code] => SGD
[original_increment_id] =>
[relation_child_id] =>
[relation_child_real_id] =>
[relation_parent_id] =>
[relation_parent_real_id] =>
[remote_ip] =>
[shipping_method] => vendor_rates_freeshipping_freesh
[store_currency_code] => SGD
[store_name] => Wine.Delivery Singapore
Wine.Del
[x_forwarded_for] =>
[customer_note] =>
[created_at] => 2019-12-11 07:18:49
[updated_at] => 2019-12-16 04:50:33
[total_item_count] => 2
[customer_gender] =>
[discount_tax_compensation_amount] => 0.0000
[base_discount_tax_compensation_amount] => 0.0000
[shipping_discount_tax_compensation_amount] => 0.0000
[base_shipping_discount_tax_compensation_amnt] =>
[discount_tax_compensation_invoiced] => 0.0000
[base_discount_tax_compensation_invoiced] => 0.0000
[discount_tax_compensation_refunded] =>
[base_discount_tax_compensation_refunded] =>
[shipping_incl_tax] => 0.0000
[base_shipping_incl_tax] => 0.0000
[coupon_rule_name] =>
[gift_message_id] =>
[paypal_ipn_customer_notified] => 0
[cedDeliveryDate] => 2019-12-12 00:00:00
[cedTimestamp] => 14:00 - 18:00
[cedDeliveryComment] =>
[delivered] => 1
[wdgift] =>
[surcharge] => 10
[order_note] =>
[packed] => 0
[require_delivery_photo] =>
)
预期结果:仅包括特定字段。
实际结果:所有字段都包括在内。
谢谢。
解决方法
缺少第三个参数。
$collection->getSelect()
->reset(\Zend_Db_Select::COLUMNS)
->columns(["driver_name" => new \Zend_Db_expr("CONCAT(driver.first_name,driver.last_name)")])
->columns(["delivery_date" => 'order.cedDeliveryDate'])
->columns(["delivery_timeslot" => 'order.cedTimestamp'])
->join(
['driver' => $collection->getTable('magenative_mobidelivery_driver')],'main_table.driver_id = driver.id',[]
)
->join(
['order' => $collection->getTable('sales_order')],'main_table.increment_id = order.increment_id',[]
);