مشکل در یک ثبت سفارش ووکامرس

rocki3oy

کاربر عضو
با سلام و احترام.

افزونه ای برای ووکامرس نوشتم که فقط سفارش ثبت می کنه یعنی نه پرداختی خواهد داشت نه چیزی، فقط سفارش ثبت میشه که مدیر بررسی کنه.

در این افزونه من یک فانکشن که در پوسته نوشتم در این افزونه استفاده کردم.

این فانکشن به این صورته که بعد از ثبت سفارش به نویسنده  اون محصول اس ام اس ارسال میشه.

متاسفانه در گذشته به درستی این مورد کار می کرد.

اما در حال حاضر در زمان ثبت سفارش به این فانکشن میرسه خطای زیر در بالای فرم ثبت سفارش ووکامرس میده:

Server was unable to process request. ---> Object reference not set to an instance of an object.



در گوگل جستجو کردم گویا به soap ربط پیدا می کنه در حالی این کد در قالب استفاده میشه مشکلی نداره.

ممنون میشم اگر کسی میدونه راهنمایی کنه.

ممنونم.

 

Mohammad

مدیر انجمن
پرسنل مدیریت
چرا از nusoap استفاده نمی کنید؟

ضمن اینکه این خطا انگار مربوط به C# هست!. تابحال ندیدمش...

 

rocki3oy

کاربر عضو
با سلام  و احترام خدمت آقا محمد عزیز.

فانکشنی که استفاده می کنم برای ارسال اس ام اس کد زیر هست این فانکشن را در پوسته هر قسمتی استفاده می کنم به درستی اس ام اس ارسال می کنه اما در این پلاگین در قسمت ثبت سفارش در قسمتی که ثبت تموم میشه اگر این فانکشن قرار میگیره این خطا داده میشه اگر از این فانکشن را بردارم تمامی موارد به درستی کار می کنه.

//---send sms
function at_sendSMS($to,$text){
$client = new SoapClient("http://i-sms1.ir/API/send.asmx?WSDL");
$params->username = 'user1001';
$params->password = 'pass1001';
$params->from = '500000000';
$params->to=array($to);
$params->text=$text;
$params->flash=false;
$params->udh='';
$params->status=array();
$params->recId=array();
$result= $client->SendSms($params);
$SendResult=$result->SendSmsResult;
$RecId=(array)$result->recId->long;
}


اگر بخوام از nosoap استفاده کنم این کد به چه شکل خواهد شد؟

البته آقا محمد قبلا بدون مشکل کار می کرد یهو اینجوری شد.

 

hannanstd.ir

مدیر انجمن و توسعه دهنده ووکامرس پارسی
احتمالا بعد از ثبت سفارش پارامتر های $to و $text به درستی به این تابع پاس داده نمیشن. شما شماره موبایل و متن رو به صورت دستی و ثابت داخل این فانکشن وارد کنید و تست بگیرید.

 

rocki3oy

کاربر عضو
احتمالا بعد از ثبت سفارش پارامتر های $to و $text به درستی به این تابع پاس داده نمیشن. شما شماره موبایل و متن رو به صورت دستی و ثابت داخل این فانکشن وارد کنید و تست بگیرید.
با سلاک خدمت آقا حنان عزیز.

این مورد را تست کردم اصلا کلا فانکشن قرار ندادم کد را کامل قرار دادم به این می رسه این خطا رو میده اما عملیات ثبت سفارش انجام میشه.

افزونه ای که اوکی کردم یک تک فایل شامل کد زیر که سفارش رو ثبت و به طرف اس ام اس می کنه.

کد:
<?php
/**
 * Plugin Name: ثبت سفارش
 * Plugin URI: http://khanompaz.ir
 * Description: ثبت سفارش
 * Author: khanompaz.ir
 * Author URI: http://khanompaz.ir
 * Version: 1.0
 * Text Domain: wc-gateway-atOrder
 * Domain Path: /i18n/languages/

 */
 
defined( 'ABSPATH' ) or exit;

if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
	return;
}
//---
function wc_offline_add_to_gateways( $gateways ) {
	$gateways[] = 'WC_Gateway_atOrder';
	return $gateways;
}
add_filter( 'woocommerce_payment_gateways', 'wc_offline_add_to_gateways' );
//---
function wc_offline_gateway_plugin_links( $links ) {

	$plugin_links = array(
		'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout&section=at_order_gateway' ) . '">' . __( 'Configure', 'wc-gateway-atOrder' ) . '</a>'
	);

	return array_merge( $plugin_links, $links );
}
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wc_offline_gateway_plugin_links' );

//---
add_action( 'plugins_loaded', 'wc_offline_gateway_init', 11 );

function wc_offline_gateway_init() {

	class WC_Gateway_atOrder extends WC_Payment_Gateway {
		public function __construct() {
	  
			$this->id                 = 'at_order_gateway';
			$this->icon               = apply_filters('woocommerce_offline_icon', '');
			$this->has_fields         = false;
			$this->method_title       = __( 'ثبت سفارش', 'wc-gateway-atOrder' );
			$this->method_description = __( 'Allows Order payments. Very handy if you use your cheque gateway for another payment method, and can help with testing. Orders are marked as "pending-chef" when received.', 'wc-gateway-atOrder' );
		  
			// Load the settings.
			$this->init_form_fields();
			$this->init_settings();
		  
			// Define user set variables
			$this->title        = $this->get_option( 'title' );
			$this->description  = $this->get_option( 'description' );
			$this->instructions = $this->get_option( 'instructions', $this->description );
		  
			// Actions
			add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
			add_action( 'woocommerce_thankyou_' . $this->id, array( $this, 'thankyou_page' ) );
		  
			// Customer Emails
			add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 );
		}
//---
		public function init_form_fields() {
	  
			$this->form_fields = apply_filters( 'wc_offline_form_fields', array(
		  
				'enabled' => array(
					'title'   => __( 'فعال / غیرفعال کردن', 'wc-gateway-atOrder' ),
					'type'    => 'checkbox',
					'label'   => __( 'فعال کردن قابلیت ثبت سفارش', 'wc-gateway-atOrder' ),
					'default' => 'yes'
				),
				
				'title' => array(
					'title'       => __( 'عنوان', 'wc-gateway-atOrder' ),
					'type'        => 'text',
					'description' => __( 'This controls the title for the payment method the customer sees during checkout.', 'wc-gateway-atOrder' ),
					'default'     => __( 'ثبت سفارش', 'wc-gateway-atOrder' ),
					'desc_tip'    => true,
				),
				
				'description' => array(
					'title'       => __( 'توضیحات', 'wc-gateway-atOrder' ),
					'type'        => 'textarea',
					'description' => __( 'Payment method description that the customer will see on your checkout.', 'wc-gateway-atOrder' ),
					'default'     => __( 'Please remit payment to Store Name upon pickup or delivery.', 'wc-gateway-atOrder' ),
					'desc_tip'    => true,
				),
				
				'instructions' => array(
					'title'       => __( 'دستورالعمل', 'wc-gateway-atOrder' ),
					'type'        => 'textarea',
					'description' => __( 'Instructions that will be added to the thank you page and emails.', 'wc-gateway-atOrder' ),
					'default'     => '',
					'desc_tip'    => true,
				),
			) );
		}
	
	
		/**
		 * Output for the order received page.
		 */
		public function thankyou_page() {
			if ( $this->instructions ) {
				echo wpautop( wptexturize( $this->instructions ) );
			}
		}
//---
		public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
		
			if ( $this->instructions && ! $sent_to_admin && $this->id === $order->payment_method && $order->has_status( 'pending-chef' ) ) {
				echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL;
			}
		}
//---
		public function process_payment( $order_id ) {
	
			$order = wc_get_order( $order_id );
			
			// Mark as pending-chef (we're awaiting the payment)
			$order->update_status( 'pending-chef', __( '', 'wc-gateway-atOrder' ) );
			
			// Send sms to seller
			$mobile_seller = get_mobile_seller_of_order_id($order_id);
			$product_name = get_product_name_of_order_id($order_id);
			$order_quantity = get_order_quantity_of_order_id($order_id);
			$order_amount = get_order_amount_of_order_id($order_id);
			
			$sms_text = "هم اکنون یک سفارش جدید شامل ".$order_quantity." عدد ".$product_name." به مبلغ ".$order_amount." تومان ثبت شده است، لطفا هر چه سریعتر به پنل کاربری خود مراجعه کرده و نسبت به تایید یا لغو سفارش اقدام کنید. \n Khanompaz.ir";
			at_sendSMS($mobile_seller,$sms_text);
			
			// Reduce stock levels
			$order->reduce_order_stock();
			
			// Remove cart
			WC()->cart->empty_cart();
			
			// Return thankyou redirect
			return array(
				'result' 	=> 'success',
				'redirect'	=> $this->get_return_url( $order )
			);
		}
	
  } // end \WC_Gateway_atOrder class
}
 

rocki3oy

کاربر عضو
دوستان راه حل یا پیشنهادی یا کد اصلاحی ندارید.

ممکنه تغییراتی در سرور پیش اومده باشه که این خطا نمایش داده میشه.

چون اوایل این مشکل نبود یهو این مشکل پیش اومد.

 

amogheimi

تازه وارد
دوستان راه حل یا پیشنهادی یا کد اصلاحی ندارید.

ممکنه تغییراتی در سرور پیش اومده باشه که این خطا نمایش داده میشه.

چون اوایل این مشکل نبود یهو این مشکل پیش اومد.


احتمالا نظر حنان عزیز درست باشه شما برای فانکشن

get_mobile_seller_of_order_id


بررسی کنید خروجی به صورت آرایه است یا خیر اگر نیست باید

$mobile_seller


  تبدیل به ارایه بشه چون با توجه به فانکش ارسال پیامکی که در بالا قرار دادید باید این شماره موبایل بصورت ارایه وارد بشه و اگه اینطوری نباشه احتمالا مشکل از همینجاست

 
آخرین ویرایش توسط مدیر:

rocki3oy

کاربر عضو
با سلام و احترام خدمت آقای حنان عزیز و شما دوست عزیز.

بالاخره با راهنمایی های شما مشکل را پیدا کردم.

گویا کاربری که سفارش می داد شماره موبایل ثبت نکرده بود به خاطر همین فراخوانی نمیشد و خطا میداد.

بازم ممنونم بابت لطفتون.

 
بالا