Plugin Directory

Changeset 3036965


Ignore:
Timestamp:
02/16/2024 07:22:36 PM (2 years ago)
Author:
lucaslc
Message:

updates for wc HPOS

Location:
sementes-cas-gcrs/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sementes-cas-gcrs/trunk/inc/Api/Callbacks/ReportCallbacks.php

    r2979752 r3036965  
    176176
    177177        $supplier_taxonomy = $this->get_sementes_option( 'supplier_taxonomy' );
    178 
    179         $order_items = $wpdb->get_results(
    180             $wpdb->prepare(
    181             "
    182             SELECT
    183             woi.order_item_id as 'OrderItemID',
    184             woi.order_item_name as 'Product',
    185             product_id.meta_value as 'ProductID',
    186             quantity.meta_value as 'Quantity',
    187             subtotal.meta_value/quantity.meta_value as 'UnitPrice',
    188             subtotal_tax.meta_value/quantity.meta_value as 'UnitTax',
    189             subtotal.meta_value as 'Price',
    190             subtotal_tax.meta_value as 'Tax',
    191             new_stock.meta_value as 'NewStock'
    192             from {$wpdb->prefix}woocommerce_order_items `woi`
    193             INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta `product_id`
    194             ON woi.order_item_id = product_id.order_item_id AND product_id.meta_key = '_product_id'
    195             INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta `quantity`
    196             ON woi.order_item_id = quantity.order_item_id AND quantity.meta_key = '_qty'
    197             INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta `subtotal`
    198             ON woi.order_item_id = subtotal.order_item_id AND subtotal.meta_key = '_line_subtotal'
    199             INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta `subtotal_tax`
    200             ON woi.order_item_id = subtotal_tax.order_item_id AND subtotal_tax.meta_key = '_line_subtotal_tax'
    201             LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta `new_stock`
    202             ON woi.order_item_id = new_stock.order_item_id AND new_stock.meta_key = '_new_stock'
    203             WHERE woi.order_id =  %s;
    204         ",
    205                 $order_id
    206             ),
    207             OBJECT
    208         );
     178       
     179        $order_items = $order->get_items();
    209180
    210181        $cycle_id = get_post_meta( $order_id, '_eita_gcr_cycle_id', true);
     
    213184            return;
    214185        }
    215 
     186        // Sementes related data
    216187        $cycle_name = get_the_title($cycle_id);
    217         $cycle_start_date = get_post_meta( $cycle_id, 'cycle_start_date', true);
     188        $cycle_start_date = get_post_meta($cycle_id, 'cycle_start_date', true);
     189        $order_delivery_place_id = get_post_meta($order_id, '_shipping_deliveryplace', true);
     190
     191        // WC related data, using WC_Order methods:
     192
    218193        $order_datetime = $order->get_date_created()->format('Y-m-d H:i:s');
    219         $order_first_name = get_post_meta( $order_id, '_billing_first_name', true);
    220         $order_last_name = get_post_meta( $order_id, '_billing_last_name', true);
    221         $order_delivery_place_id = get_post_meta( $order_id, '_shipping_deliveryplace', true);
    222         $order_payment_method_title = get_post_meta( $order_id, '_payment_method_title', true );
    223         $order_phone_number = get_post_meta( $order_id, '_billing_phone', true);
    224         $order_shipping_postcode = get_post_meta( $order_id, '_shipping_postcode', true);
    225         $order_address_1 = get_post_meta( $order_id, '_shipping_address_1', true);
    226         $order_address_2 = get_post_meta( $order_id, '_shipping_address_2', true);
    227         $order_shipping_city = get_post_meta( $order_id, '_shipping_city', true);
    228         $order_shipping_state = get_post_meta( $order_id, '_shipping_state', true);
    229         $order_shipping_items = $order->get_items( 'shipping' );
     194        $order_first_name = $order->get_billing_first_name();
     195        $order_last_name = $order->get_billing_last_name();
     196        $order_payment_method_title = $order->get_payment_method_title();
     197        $order_phone_number = $order->get_billing_phone();
     198        $order_shipping_postcode = $order->get_shipping_postcode();
     199        $order_address_1 =  $order->get_shipping_address_1();
     200        $order_address_2 = $order->get_shipping_address_2();
     201        $order_shipping_city = $order->get_shipping_city();
     202        $order_shipping_state = $order->get_shipping_state();
     203        $order_shipping_items = $order->get_items('shipping');
    230204
    231205        $order_zone = null;
     
    251225        }
    252226
    253     $order_delivery_place = '';
     227        $order_delivery_place = '';
    254228        if ( $order_delivery_place_id ) {
    255229            $order_delivery_place = get_the_title( $order_delivery_place_id );
     
    261235
    262236        foreach ($order_items as $order_item) {
    263             $product_category = wp_get_post_terms( $order_item->ProductID, $supplier_taxonomy );
     237            $product_category = wp_get_post_terms( $order_item['product_id'], $supplier_taxonomy );
    264238
    265239            if ( count( $product_category ) == 0 ) {
     
    274248                "{$wpdb->prefix}eitagcr_report",
    275249                array(
    276                     'order_item_id'              => $order_item->OrderItemID,
     250                    'order_item_id'              => $order_item->get_id(),
    277251                    'order_id'                   => $order_id,
    278252                    'cycle_id'                   => $cycle_id,
     
    285259                    'order_delivery_place'       => esc_sql( $order_delivery_place ),
    286260                    'order_payment_method_title' => esc_sql( $order_payment_method_title ),
    287                     'order_item_product_id'      => $order_item->ProductID,
    288                     'order_item_product'         => esc_sql( $order_item->Product ),
     261                    'order_item_product_id'      => $order_item['product_id'],
     262                    'order_item_product'         => esc_sql( $order_item->get_name() ),
    289263                    'order_item_category_id'     => $product_category_id,
    290264                    'order_item_category'        => esc_sql( $product_category ),
    291                     'order_item_quantity'        => $order_item->Quantity,
    292                     'order_item_unit_price'      => $order_item->UnitPrice,
    293                     'order_item_unit_tax'        => $order_item->UnitTax,
    294                     'order_item_price'           => $order_item->Price,
    295                     'order_item_tax'             => $order_item->Tax,
    296                     'order_item_stock'           => $order_item->NewStock,
     265                    'order_item_quantity'        => $order_item->get_quantity(),
     266                    'order_item_unit_price'      => $order_item->get_subtotal()/$order_item->get_quantity(),
     267                    'order_item_unit_tax'        => $order_item->get_subtotal_tax()/$order_item->get_quantity(),
     268                    'order_item_price'           => $order_item->get_subtotal(),
     269                    'order_item_tax'             => $order_item->get_subtotal_tax(),
     270                    'order_item_stock'           => $order_item['new_stock'],
    297271                    'order_phone'                => esc_sql($order_phone_number),
    298272                    'order_shipping_postcode'    => esc_sql($order_shipping_postcode),
     
    357331    }
    358332
    359   public function generate_report() {
     333    public function generate_report() {
    360334
    361335        global $wpdb;   
    362336        $wpdb->get_results( "TRUNCATE TABLE {$wpdb->prefix}eitagcr_report" );
    363337
    364         $args = array(
    365             'post_type' => 'shop_order',
    366             'posts_per_page' => -1,
    367             'post_status' => array_keys( wc_get_order_statuses() ),
    368         );
    369 
    370         $orders = get_posts( $args );
    371        
     338        $orders = wc_get_orders( array( 'limit' => -1) );
    372339        $all_shipping_zones = $this->get_all_shipping_zones();
    373340
    374341        foreach ($orders as $order) {
    375             $order = wc_get_order( $order->ID );
    376342            $this->eitagcr_add_to_report( $order, NULL, $all_shipping_zones );
    377343        }
    378344    }
    379 
    380   public function get_report( $report, $cycle_id, $orderby, $includetax, $extra_configs ) {
     345 
     346    public function get_report( $report, $cycle_id, $orderby, $includetax, $extra_configs ) {
    381347
    382348        if( !in_array( $report, [ 'report_1', 'report_2', 'report_3', 'report_4', 'report_5', 'report_6', 'report_7', 'report_shipping_tag' ] )){
     
    691657            $include_client_info = false;
    692658
    693       if ( isset( $extra_configs['include_client_info_report_4'] ) ) {
     659            if ( isset( $extra_configs['include_client_info_report_4'] ) ) {
    694660                $include_client_info = $extra_configs[ 'include_client_info_report_4' ];
    695661            }
  • sementes-cas-gcrs/trunk/inc/Base/CycleController.php

    r2944903 r3036965  
    6969
    7070        add_action( 'manage_cycle_posts_custom_column', array( $this, 'add_custom_columns_value_to_cycle_list' ), 10, 2 );
    71 
     71       
     72        // Legacy CPT Orders custom collumn creation
    7273        add_filter( 'manage_edit-shop_order_columns', array( $this, 'add_cycle_column_to_wc_orders_list' ), 10, 2 );
    73 
    7474        add_action( 'manage_shop_order_posts_custom_column', array( $this, 'add_cycle_column_value_to_wc_orders_list' ), 10, 2 );
     75
     76        // HPOS collumn creation
     77        add_filter( 'manage_woocommerce_page_wc-orders_columns', array( $this, 'add_cycle_column_to_wc_orders_list' ), 10, 2 );
     78        add_action( 'manage_woocommerce_page_wc-orders_custom_column', array( $this, 'add_cycle_column_value_to_wc_orders_list' ), 10, 2 );
    7579
    7680        add_filter( 'gettext', array( $this, 'translate_cycle_edit_page' ), 20 );
     
    433437    }
    434438
    435     public function add_cycle_column_value_to_wc_orders_list( $column_key, $post_id ) {
    436         $cycle_id = get_post_meta( $post_id, '_eita_gcr_cycle_id', true );
    437         $cycle_name = '-';
    438         if ( isset($cycle_id) && $cycle_id ) {
    439             $cycle_name = get_the_title( $cycle_id );
    440         }
    441         if ( $column_key == 'cycle_id') {
    442             echo esc_html($cycle_name);
     439    public function add_cycle_column_value_to_wc_orders_list( $column_key, $order_or_post_id ) {
     440       
     441        if ( $column_key == 'cycle_id') {
     442            //  Since the second arg is a WC_Order in HPOS:
     443            $post_id = ( is_a($order_or_post_id,'WC_Order') ? $order_or_post_id->get_id() : $order_or_post_id ) ;
     444       
     445            $cycle_id = get_post_meta( $post_id, '_eita_gcr_cycle_id', true );
     446            $cycle_name = '-';
     447            if ( isset($cycle_id) && $cycle_id ) {
     448                $cycle_name = get_the_title( $cycle_id );
     449            }
     450                echo esc_html($cycle_name);
    443451        }
    444452    }
  • sementes-cas-gcrs/trunk/readme.txt

    r2979752 r3036965  
    55Requires at least: 5.7
    66Tested up to: 6.1.1
    7 Stable tag: 1.2.17
     7Stable tag: 1.2.18
    88
    99Adaptação do Woocommerce para Grupos de Consumo Responsável e Cestas Agroecológicas.
  • sementes-cas-gcrs/trunk/sementes.php

    r2979752 r3036965  
    55/*
    66 * Plugin Name: Sementes - Sistema de Cestas Agroecológicas e de Grupos de Consumo Responsável
    7  * Version: 1.2.17
     7 * Version: 1.2.18
    88 * Plugin URI: https://gitlab.com/eita/eitagcr
    99 * Description: This plugin offers some enhancements to the Woocommerce e-commerce platform to make it fit for using in Responsible Consumer Groups (GCR). It assumes GCRs are composed by several consumers and several suppliers, and the there is a buying cycle.
Note: See TracChangeset for help on using the changeset viewer.