0

I'm trying to complete my software which interacting with the Magento API and another external API (REST). In this project I forwarding the orders of the other shop system towards Magento and I'm able to create a order (yeha!).

Unfortunately, Magento seems to cause an fatal error after the successful order. That's a problem because I've to convert about hundrets orders...

Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Server] Call to a member function getSelect() on a non-object in /var/orders.php:280
Stack trace:
#0 /var/orders.php: SoapClient->__call('call', Array)
#1 /var/orders.php: SoapClient->call('6ceb613d278de9e...', 'cart.order', Array)
#2 /var/orders.php: complete_order(Array, 3)
#3 /var/orders.php: new_orders(Object(mysqli))

Does anybody have any idea how to solve that?

The involved line in the PHP file:

    $result = $client->call($session, 'cart.info', $shopping_cart_id);

The whole PHP code:

function complete_order($val,$i=1) {
    if($i == 3) {
    $client = new SoapClient(MAGENTO_HOST.'/api/soap/?wsdl');
    $session = $client->login(MAGENTO_API_USER, MAGENTO_API_KEY);

    # Choose a store id 
    $store_id = $client->call($session, 'category.currentStore', MAGENTO_STORE_ID);

    # Create a new shopping cart
    $shopping_cart_id = $client->call( $session, 'cart.create', $store_id );

    # Add products to cart #
    $product_for_cart = array(
        array(
            "sku" => "TOPP19600",
            "qty" => 2,
            "options" => null
        ),
        array(
            "sku" => "TOPP19601",
            "qty" => 1,
            "options" => null
        )
    );

    $val['items'] = $product_for_cart;

    foreach($val['items'] AS $item) {
        $filters = array( 
            'status' => array( '=' => 1 ),  
            'sku' => array( '=' => $item['sku']), 
        ); 
        $result = $client->call($session, 'catalog_product.list', array($filters,$store_id));
        if($result != NULL AND count($result) > 0) {
            $product_for_cart[] = array('product_id' => $result[0]['product_id'], 'qty' => $item['qty']);
        } else {
            # unknown product found #
            echo('Unknown product'); 
        }
    }

    # Customer information (as guest) #
    $customer = array(
    'mode' => 'guest',
    'firstname' => $val['invoice_address']['firstname'],
    'lastname' => $val['invoice_address']['lastname'],
    'email' => $val['invoice_address']['email'],
    'website_id' => 0,
    'store_id' => 0,
    'group_id' => 0,
    'dob' => date('d.m.Y',$val['created_at']),
    'confirmation' => 1
    );

    $resultCustomerSet = $client->call($session, 'cart_customer.set', array($shopping_cart_id, $customer, $store_id) );

    // Set customer addresses, for example guest's addresses
    $arrAddresses = array(
        array(
            "mode" => "shipping",
            "firstname" => "testFirstname",
            "lastname" => "testLastname",
            "company" => "testCompany",
            "street" => "testStreet",
            "city" => "testCity",
            "region" => "testRegion",
            "postcode" => "testPostcode",
            "country_id" => "id",
            "telephone" => "0123456789",
            "fax" => "0123456789",
            "is_default_shipping" => 0,
            "is_default_billing" => 0
        ),
        array(
            "mode" => "billing",
            "firstname" => "testFirstname",
            "lastname" => "testLastname",
            "company" => "testCompany",
            "street" => "testStreet",
            "city" => "testCity",
            "region" => "testRegion",
            "postcode" => "testPostcode",
            "country_id" => "id",
            "telephone" => "0123456789",
            "fax" => "0123456789",
            "is_default_shipping" => 0,
            "is_default_billing" => 0
        )
    );

    $add_product_to_cart = $client->call($session,"cart_product.add",array($shopping_cart_id, $product_for_cart));

    $resultCustomerAddresses = $client->call($session,"cart_customer.addresses",array($shopping_cart_id, $arrAddresses, $store_id));

    $choose_shipping_method = $client->call($session, 'cart_shipping.method', array($shopping_cart_id, 'pl_store_pickup_kostenlose_selbstabholung_w_hrend_den_gesch_ftszeiten_sie_erhalten_eine_e_mail_benachrichtigung_sobald_ihre_bestellung_zur_abholung_bereit_liegt__jawolle_rheinstr_29_66113_saarbr_cken'));

    $resultPaymentMethod = $client->call($session,'cart_payment.method',array($shopping_cart_id, $paymentMethod = array('method' => 'bankpayment')));

    # Finishing order # 
    $result = $client->call($session, 'cart.info', $shopping_cart_id);

    $client->endSession($session);
6
  • Please post the code of orders.php, because it seems as the error is thrown there in line 280. Feb 22, 2015 at 22:28
  • @FabianBlechschmidt I added the "bad" line.
    – EaglePsyX
    Feb 22, 2015 at 22:41
  • Ok, I slowly understand. Than it is time to dig in magento. This is no standard behaviour, therefore I think we can't help you, because the problem is not reproducable Feb 22, 2015 at 22:42
  • That would not be the first time. In the first approach I was not able to add a customer because Magento ask for a "day of birth", which is nowhere noticed (espacially not in the Magento documentations). Therefore I digged several minutes the PHP code of Magento and was able to identify the missing veriable "dob". Is there a workaround to "ignore" the fatal error and continue the script?
    – EaglePsyX
    Feb 22, 2015 at 22:48
  • Nope, Fatal errors can't be catched. Feb 22, 2015 at 22:49

1 Answer 1

1

I understand what's wrong....

I have a plugin (TrustedShop) who use an observer on 'checkout_type_onepage_save_order_after'

I remove in the plugin the part :

        <checkout_type_onepage_save_order_after>
           <observers>
                <buyerprotect>
                    <type>singleton</type>
                    <class>Symmetrics_Buyerprotect_Model_Observer</class>
                    <method>registerTsSoapModel</method>
                </buyerprotect>
            </observers>
        </checkout_type_onepage_save_order_after>

And it's fine...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.