1

Ok this is getting really serious here. I will continue explaining the code first.

This is my WSDL path connection:

$client = new SoapClient('http://xxxxxxxxxxxxx', array("connection_timeout"=>120));

These are some of my classes not all of them:

$aWebOrder = new WebOrder;
$aWebOrder->OrderNumber                         = $order->getIncrementId();
$aWebOrder->OrderCreationDate                   = $order->getCreatedAtStoreDate()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

$aWebOrder->CustomerAddress = new CustomerAddress;
$aWebOrder->CustomerAddress->FirstName          = $order->getCustomerFirstname(); 
$aWebOrder->CustomerAddress->LastName           = $order->getCustomerLastname();
$aWebOrder->CustomerAddress->Telephone          = $order->getBillingAddress()->getTelephone();
$aWebOrder->CustomerAddress->Fax                = $order->getBillingAddress()->getFax(); 
$aWebOrder->CustomerAddress->Email              = $order->getCustomerEmail(); 

This is the code where i want to pass my product info:

$aProduct = new OrderDetail; 
$aProduct->SkuId =     $order->getSku();
$aProduct->Quantity=   $order->getQtyOrdered();
$aProduct->Sellprice = $order->getPrice();

$aProduct = new OrderDetail; 
$aProduct1->SkuId =     $order->getSku();
$aProduct1->Quantity=   $order->getQtyOrdered();
$aProduct1->Sellprice = $order->getPrice();

$aWebOrder->ProductDetailList = array($aProduct,$aProduct1);

And this is the code which pass these classes to the wsdl file and after they are sent into a database:

$params = array('OrderWebAPILogin' => array("login" => 'xxx', "password"=> 'xxxx'), 'DbVersion' => 16, 'Order' => $aWebOrder,'RequestOptions' => NULL);
$result = $client->addOrder($params);

This way the code works just fine. because i haven't created a foreach in the product section.

In the product section i add this code to get all products info with a foreach

Here is the code i use:

foreach ($order->getAllVisibleItems() as $item){

$aProduct = new OrderDetail;

$data[] = array(

    $aProduct->SkuId        => $item->getSku(),
    $aProduct->Quantity     => $item->getQtyOrdered(),
    $aProduct->Sellprice    => $item->getPrice()

    );
}

foreach($data as $product){

    $aWebOrder->ProductDetailList = $product;

}

I don't get any error on the log file but no data are inserted into database, it means that i am doing something wrong when i pass the values into the foreach or into the $params array().

This is an event observer which fires anytime an order is completed and purchased.

  • which event are you using? can we see your Observer class? – user1704524 Oct 25 '13 at 15:20
  • Please write a proper title – Alex Jul 3 '16 at 13:09
2

I don't really understand you code but I see a difference between the case that works and the one that doesn't.
In the first case (when it works) I see that $aWebOrder->ProductDetailList is an array of objects with type OrderDetail.
In the second case (when it doesn't work) $aWebOrder->ProductDetailList is an array of strings.
In this last case the $product var will look like this:

array(

    $aProduct->SkuId        => $item->getSku(),
    $aProduct->Quantity     => $item->getQtyOrdered(),
    $aProduct->Sellprice    => $item->getPrice()

)

If $aProduct is an empty instance of OrderDetail then $aProduct->SkuId will evaluate to null and so will the rest of the values.
So your array will end up something like this:

array(
    null => '44.99' // or some other price
) 

I assume that this is not the format you were expecting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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