Plugin Directory

Changeset 2642517


Ignore:
Timestamp:
12/10/2021 04:18:20 PM (4 years ago)
Author:
lucascreativecode
Message:

Atualizado calculo de medidas

Location:
unienvios/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • unienvios/trunk/ClassUnienvios.php

    r2614696 r2642517  
    6767    public function calculate_shipping($package = null)
    6868    {
     69       
    6970        global $woocommerce;
    7071        $items = $woocommerce->cart->get_cart();
     
    7879        $count = 0;
    7980        //LOOP ALL THE PRODUCTS IN THE CART
     81        $cubagemTotal = 0;
     82        $pesoTotal = 0;
    8083        foreach ($items as $item => $values) {
    8184            $count += 1;
    8285            $_product =  wc_get_product($values['data']->get_id());
    83             //GET GET PRODUCT M3
    84             $dimensoes['estimate_height'] += doubleval($_product->get_height()) * $values['quantity'];
    85             $dimensoes['estimate_width'] += doubleval($_product->get_width()) * $values['quantity'];
    86             $dimensoes['estimate_length'] += doubleval($_product->get_length()) * $values['quantity'];
    87             $dimensoes['estimate_weight'] += doubleval($_product->get_weight()) * $values['quantity'];
    88             // pegar quantidade do item
     86
     87            $medidas = [
     88                        doubleval($_product->get_height()) * intval( $values['quantity'] ),
     89                        doubleval($_product->get_width()) * intval( $values['quantity'] ),
     90                        doubleval($_product->get_length()) * intval( $values['quantity']),
     91                        doubleval($_product->get_weight()) * intval( $values['quantity'] )
     92            ];
     93
     94            $pesoTotal += $medidas[3];
     95
     96            $cubagem = ( $medidas[0] * $medidas[1] * $medidas[2] )/6000;
     97            array_push($medidas, $cubagem);
     98       
     99            $cubagem = $cubagem;
     100            $cubagemTotal += $cubagem;
     101           
    89102        }
     103
     104        $cubagemTotal = round($cubagemTotal, 4);
     105
     106        $cubagemReversa = $cubagemTotal * doubleval(6000);
     107
     108        $raizCubica = pow($cubagemReversa, 1.0/3.0);
     109
     110        $raizCubica = round($raizCubica, 1);
     111
     112        $dimensoes = [
     113                    'estimate_height' => $raizCubica,
     114                    'estimate_width' => $raizCubica,
     115                    'estimate_length' => $raizCubica,
     116                    'estimate_weight' => $pesoTotal
     117                ];
     118
    90119        //     wc_add_notice( __('debug: ', 'woothemes') .  json_encode($dimensoes), 'error' );
    91120        // return;
     121
     122        // wp_send_json($dimensoes);
    92123
    93124        $api = new API_UNIENVIOS('https://api.unienvios.com.br');
  • unienvios/trunk/index.php

    r2618363 r2642517  
    154154    ];
    155155
     156
    156157    $quotation = $api->create_quotation($dados, $dimensoes);
    157158
Note: See TracChangeset for help on using the changeset viewer.