Jump to content

Recommended Posts

При добавлении нового товара в уже сделанный заказ, в админке не добавляется товар

в консоли вылезает такая ошибка

 

 

index.php?module=OrderAdmin&status=3&id=2333&return=%2Fsimpla%2Findex.php%3Fmodule%3DOrdersAdmin%26status%3D3:1433 Uncaught ReferenceError: data is not defined
    at HTMLInputElement.onSelect (index.php?module=OrderAdmin&status=3&id=2333&return=%2Fsimpla%2Findex.php%3Fmodule%3DOrdersAdmin%26status%3D3:1433)
    at g.onSelect (jquery.autocomplete-min.js:27)
    at g.select (jquery.autocomplete-min.js:26)
    at HTMLDivElement.<anonymous> (jquery.autocomplete-min.js:13)
    at HTMLDivElement.dispatch (jquery.js:3)
    at HTMLDivElement.i (jquery.js:3)
onSelect @ index.php?module=OrderAdmin&status=3&id=2333&return=%2Fsimpla%2Findex.php%3Fmodule%3DOrdersAdmin%26status%3D3:1433
onSelect @ jquery.autocomplete-min.js:27
select @ jquery.autocomplete-min.js:26
(anonymous) @ jquery.autocomplete-min.js:13
dispatch @ jquery.js:3
i @ jquery.js:3
2index.php?module=OrderAdmin&status=3&id=2333&return=%2Fsimpla%2Findex.php%3Fmodule%3DOrdersAdmin%26status%3D3:1 Unchecked runtime.lastError: The message port closed before a response was received.
 

 

 
Содержимое OrderAdmin.php
 

 

<?PHP


require_once('api/Simpla.php');


############################################
# Class Product - edit the static section
############################################
class OrderAdmin extends Simpla
{
    public function fetch()
    {
        $order = new stdClass;
        if($this->request->method('post'))
        {
            $order->id = $this->request->post('id', 'integer');
            $order->name = $this->request->post('name');
            $order->email = $this->request->post('email');
            $order->phone = $this->request->post('phone');
            $order->address = $this->request->post('address');
            $order->comment = $this->request->post('comment');
            $order->note = $this->request->post('note');
            $order->discount = $this->request->post('discount', 'floatr');
            $order->coupon_discount = $this->request->post('coupon_discount', 'floatr');
            $order->delivery_id = $this->request->post('delivery_id', 'integer');
            $order->delivery_price = $this->request->post('delivery_price', 'float');
            $order->payment_method_id = $this->request->post('payment_method_id', 'integer');
            $order->paid = $this->request->post('paid', 'integer');
            $order->user_id = $this->request->post('user_id', 'integer');
            $order->separate_delivery = $this->request->post('separate_delivery', 'integer');
    
             if(!$order_labels = $this->request->post('order_labels'))
                 $order_labels = array();


            if(empty($order->id))
            {
                  $order->id = $this->orders->add_order($order);
                $this->design->assign('message_success', 'added');
              }
            else
            {
                $this->orders->update_order($order->id, $order);
                $this->design->assign('message_success', 'updated');
            }    


            $this->orders->update_order_labels($order->id, $order_labels);
            
            if($order->id)
            {
                // Покупки
                $purchases = array();
                if($this->request->post('purchases'))
                {
                    foreach($this->request->post('purchases') as $n=>$va) foreach($va as $i=>$v)
                    {
                        if(empty($purchases[$i]))
                            $purchases[$i] = new stdClass;
                        $purchases[$i]->$n = $v;
                    }
                }        
                $posted_purchases_ids = array();
                foreach($purchases as $purchase)
                {
                    $variant = $this->variants->get_variant($purchase->variant_id);


                    if(!empty($purchase->id))
                        if(!empty($variant))
                            $this->orders->update_purchase($purchase->id, array('variant_id'=>$purchase->variant_id, 'variant_name'=>$variant->name, 'sku'=>$variant->sku,'price'=>$purchase->price, 'amount'=>$purchase->amount));
                        else
                            $this->orders->update_purchase($purchase->id, array('price'=>$purchase->price, 'amount'=>$purchase->amount));
                    elseif(!$purchase->id = $this->orders->add_purchase(array('order_id'=>$order->id, 'variant_id'=>$purchase->variant_id, 'variant_name'=>$variant->name, 'price'=>$purchase->price, 'amount'=>$purchase->amount)))
                        $this->design->assign('message_error', 'error_closing');
                        
                    $posted_purchases_ids[] = $purchase->id;            
                }
                
                // Удалить непереданные товары
                foreach($this->orders->get_purchases(array('order_id'=>$order->id)) as $p)
                    if(!in_array($p->id, $posted_purchases_ids))
                        $this->orders->delete_purchase($p->id);
                    
                // Принять?
                if($this->request->post('status_new'))
                    $new_status = 0;
                elseif($this->request->post('status_accept'))
                    $new_status = 1;
                elseif($this->request->post('status_done'))
                    $new_status = 2;
                elseif($this->request->post('status_deleted'))
                    $new_status = 3;
                else
                    $new_status = $this->request->post('status', 'string');
    
                if($new_status == 0)                    
                {
                    if(!$this->orders->open(intval($order->id)))
                        $this->design->assign('message_error', 'error_open');
                    else
                        $this->orders->update_order($order->id, array('status'=>0));
                }
                elseif($new_status == 1)                    
                {
                    if(!$this->orders->close(intval($order->id)))
                        $this->design->assign('message_error', 'error_closing');
                    else
                        $this->orders->update_order($order->id, array('status'=>1));
                }
                elseif($new_status == 2)                    
                {
                    if(!$this->orders->close(intval($order->id)))
                        $this->design->assign('message_error', 'error_closing');
                    else
                        $this->orders->update_order($order->id, array('status'=>2));
                }
                elseif($new_status == 3)                    
                {
                    if(!$this->orders->open(intval($order->id)))
                        $this->design->assign('message_error', 'error_open');
                    else
                        $this->orders->update_order($order->id, array('status'=>3));
                    header('Location: '.$this->request->get('return'));
                }
                $order = $this->orders->get_order($order->id);
    
                // Отправляем письмо пользователю
                if($this->request->post('notify_user'))
                    $this->notify->email_order_user($order->id);
            }


        }
        else
        {
            $order->id = $this->request->get('id', 'integer');
            $order = $this->orders->get_order(intval($order->id));
            // Метки заказа
            $order_labels = array();
            if(isset($order->id))
            foreach($this->orders->get_order_labels($order->id) as $ol)
                $order_labels[] = $ol->id;            
        }




        $subtotal = 0;
        $purchases_count = 0;
        if($order && $purchases = $this->orders->get_purchases(array('order_id'=>$order->id)))
        {
            // Покупки
            $products_ids = array();
            $variants_ids = array();
            foreach($purchases as $purchase)
            {
                $products_ids[] = $purchase->product_id;
                $variants_ids[] = $purchase->variant_id;
            }
            
            $products = array();
            foreach($this->products->get_products(array('id'=>$products_ids)) as $p)
                $products[$p->id] = $p;
    
            $images = $this->products->get_images(array('product_id'=>$products_ids));        
            foreach($images as $image)
                $products[$image->product_id]->images[] = $image;
            
            $variants = array();
            foreach($this->variants->get_variants(array('product_id'=>$products_ids)) as $v)
                $variants[$v->id] = $v;
            
            foreach($variants as $variant)
                if(!empty($products[$variant->product_id]))
                    $products[$variant->product_id]->variants[] = $variant;
                
    
            foreach($purchases as &$purchase)
            {
                if(!empty($products[$purchase->product_id]))
                    $purchase->product = $products[$purchase->product_id];
                if(!empty($variants[$purchase->variant_id]))
                    $purchase->variant = $variants[$purchase->variant_id];
                $subtotal += $purchase->price*$purchase->amount;
                $purchases_count += $purchase->amount;                
            }            
            
        }
        else
        {
            $purchases = array();
        }
        
        // Если новый заказ и передали get параметры
        if(empty($order->id))
        {
            $order = new stdClass;
            if(empty($order->phone))
                $order->phone = $this->request->get('phone', 'string');
            if(empty($order->name))
                $order->name = $this->request->get('name', 'string');
            if(empty($order->address))
                $order->address = $this->request->get('address', 'string');
            if(empty($order->email))
                $order->email = $this->request->get('email', 'string');
        }


        $this->design->assign('purchases', $purchases);
        $this->design->assign('purchases_count', $purchases_count);
        $this->design->assign('subtotal', $subtotal);
        $this->design->assign('order', $order);


        if(!empty($order->id))
        {
            // Способ доставки
            $delivery = $this->delivery->get_delivery($order->delivery_id);
            $this->design->assign('delivery', $delivery);
    
            // Способ оплаты
            $payment_method = $this->payment->get_payment_method($order->payment_method_id);
            
            if(!empty($payment_method))
            {
                $this->design->assign('payment_method', $payment_method);
        
                // Валюта оплаты
                $payment_currency = $this->money->get_currency(intval($payment_method->currency_id));
                $this->design->assign('payment_currency', $payment_currency);
            }
            // Пользователь
            if($order->user_id)
                $this->design->assign('user', $this->users->get_user(intval($order->user_id)));
    
            // Соседние заказы
            $this->design->assign('next_order', $this->orders->get_next_order($order->id, $this->request->get('status', 'string')));
            $this->design->assign('prev_order', $this->orders->get_prev_order($order->id, $this->request->get('status', 'string')));
        }


        // Все способы доставки
        $deliveries = $this->delivery->get_deliveries();
        $this->design->assign('deliveries', $deliveries);


        // Все способы оплаты
        $payment_methods = $this->payment->get_payment_methods();
        $this->design->assign('payment_methods', $payment_methods);


        // Метки заказов
          $labels = $this->orders->get_labels();
         $this->design->assign('labels', $labels);
          
         $this->design->assign('order_labels', $order_labels);          
        
        if($this->request->get('view') == 'print')
               return $this->design->fetch('order_print.tpl');
           else
               return $this->design->fetch('order.tpl');
    }
}

 

 

В чем может быть проблема ? 
Edited by ABSORBER
Стилизация
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...