Post by Domovoi » Tue Aug 02, 2016 7:52 pm

Hi Guys,

I've added a function in /model/checkout/order.php that exports orders to an external database when there's a successful checkout. The function has been working fine with paypal, but today I implemented a new payment option (Worldpay Business). Orders are still processed and my function succeeds, but the view fails to load and all the customer sees is a PHP Error:

Code: Select all

Undefined Property Proxy::(nameOfMyFunction)
I've done some digging around and from what I can understand this error is triggered by /system/engine/proxy.php when there is no $key value set. Can anyone explain to me what the Proxy class does, and how I can make sure the $key value is properly set?

Thanks!

Newbie

Posts

Joined
Fri Jan 03, 2014 9:55 pm

Post by straightlight » Tue Aug 02, 2016 7:57 pm

The proxy error is intended when a controller or model has not been properly defined from the source. There is nothing wrong with the proxy engine.

Which OC version are you using? Can you provide the codes of your built-in controller and / or model files?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Domovoi » Tue Aug 02, 2016 8:09 pm

Sure, I'm using version 2.2.0.

In controller/checkout/success.php I've added the following code to get info about the orders:

Code: Select all

    

    //GET ORDER DETAILS

    //LOAD MODEL
    $this->load->model('checkout/order');

    //GET ORDER DETAILS
    $order_info = $this->model_checkout_order->getOrder($order_id);

    //NEW MODEL TO COLLECT TAX
    $get_order_tax = $this->model_checkout_order->getOrderTax($order_id);

    if($get_order_tax){
	    //ASSIGN TAX TO NEW VARIABLE
	    $order_tax = $get_order_tax['value'];
    } else {
	    //THERE WAS NO TAX COLLECTED
	    $order_tax = '';
    }

    //NEW MODEL TO COLLECT SHIPPING
    $get_order_shipping = $this->model_checkout_order->getOrderShipping($order_id);

    if($get_order_shipping){
	    //ASSIGN SHIPPING TO NEW VARIABLE
	    $order_shipping = $get_order_shipping['value'];
    } else {
	    //THERE WAS NO SHIPPING COLLECTED
	    $order_shipping = '';
    }

    //NEW MODEL TO COLLECT ALL PRODUCTS ASSOCIATED WITH ORDER
    $get_order_products = $this->model_checkout_order->getOrderProducts($order_id);

    //CREATE ARRAY TO HOLD PRODUCTS
    $order_products = array();

    foreach($get_order_products as $prod){				

	    $order_products[] = array(
		    'order_id'  => $order_id,
		    'model'     => $prod['model'],
		    'name'      => $prod['name'],
		    'sku'       => $prod['sku'],
		    'category'  => '',
		    'price'     => number_format($prod['price'], 2, '.', ','),
		    'quantity'  => $prod['quantity'],
		    'value'     => $prod['value']
	    );

    }

    //NEW ORDER ARRAY
    $order_tracker = array(
	    'order_id'    => $order_id,
	    'store_name'  => $order_info['store_name'],
	    'total'       => $order_info['total'],
	    'tax'         => $order_tax,
	    'shipping'    => $order_shipping,
	    'city'        => $order_info['payment_city'],
	    'state'       => $order_info['payment_zone'],
	    'country'     => $order_info['payment_country'],
	    'currency'    => $order_info['currency_code'],
	    'products'    => $order_products
    );

    $this->session->data['order_tracker'] = $order_tracker;

	  $order_info['shipping'] = $order_shipping;
	  $order_info['products'] = $order_products;

	  $this->model_checkout_order->exportToMyFunction($order_id);

    //END MODIFICATION
The data is then passed to an export function in /model/checkout/order.php. The code for that is:

Code: Select all

  private function exportToMyDB($order) {    
      $hash = $this->toHashMap($order);
      $db = $this->getMyDB();
      $sql = "INSERT INTO orders VALUES (" . implode(array_keys($hash), ',') . ")";
      try {
        $db->prepare($sql)->execute($hash);
      }
      catch (Exception $e) {
        error_log($e->getMessage());
        error_log("Export failed: {$sql}; with values: " . implode($hash, ","));
      }
  }

  private function toHashMap($order) {
      return [
          ":id"            => NULL,
          ":fname"         => $order['firstname'],
          ":lname"         => $order['lastname'],
          ":address1"      => $order['shipping_address_1'],
          ":address2"      => $order['shipping_address_2'],
          ":city"          => $order['shipping_city'],
          ":county"        => $order['shipping_zone'],
          ":postcode"      => $order['shipping_postcode'],
          ":country"       => $order['shipping_iso_code_2'],
          ":tel"           => $order['telephone'],
          ":email"         => $order['email'],
          ":comments"      => $order['comment'],
          ":postage"       => number_format($order['shipping'], 2, '.', ','),
          ":subTotal"      => number_format($order['total'] - $order['shipping'], 2, '.', ','),
          ":total"         => number_format($order['total'], 2, '.', ','),
          ":products"      => implode(array_map([$this, 'getProductString'], $order['products']), ":"),
          ":productsNice"  => "Unavailable",
          ":domain"        => $order['store_name'],
          ":time"          => $order['date_modified'],
          ":currency"      => $order['currency_code'],
          ":paymentMethod" => "card",
          ":new"           => "1",
          ":orderRef"      => $order['order_id'],
          ":complete"      => "1",
          ":txnid"         => $order['order_id'],
          ":dispatched"    => "0"
      ];
  }

  private function getProductString($product) {
      return implode([
          $product['sku'],
          $product['name'],
          $product['price'],
          $product['quantity'],
          "0.00"
      ], ";");
  }
  
Though reading back through the comments on the WorldPay Business Gateway extension page it seems like this is a problem people have encountered with previous versions of the extension.

Newbie

Posts

Joined
Fri Jan 03, 2014 9:55 pm

Post by straightlight » Tue Aug 02, 2016 8:16 pm

Since this enquiry is about an extension, this topic will be moved to the Extensions Support section of the forum. In the mean time, I would suggest to contact the developer of that extension to resolved this issue.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Domovoi » Tue Aug 02, 2016 8:19 pm

Okay, thanks for confirming that it's nothing to do with the proxy engine.

Newbie

Posts

Joined
Fri Jan 03, 2014 9:55 pm

Post by straightlight » Tue Aug 02, 2016 8:24 pm

Domovoi wrote:Okay, thanks for confirming that it's nothing to do with the proxy engine.
Correct. It is also about a developed extension which is why this topic has been moved to the proper category. ;)

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by karapuz » Tue Aug 23, 2016 3:08 pm

Just met the same error in my extension. In my case it happened because a function name did not match function declaration by letter case. In PHP the function names are case-insensitive, but proxy "feature" made it to behave this way.

Actually I have a lot of complaints to the "magic proxy feature" and I have no idea who need it. I never missed such functionality, vqmod and ocmod do a good job and they are straightforward. I would be glad if someone removed it in the next major Opencart version.

User avatar
New member

Posts

Joined
Tue Jul 17, 2012 4:59 am

Who is online

Users browsing this forum: No registered users and 4 guests