It was some logic issue in your code
issue1: 'Items' => $order->getAllVisibleItems()
not works it is big object.it print and var_dump is stuck works.
change the function $data['Items']=$this->createOrderItems($order->getIncrementId());
and modified code
public function exportOrder($order)
{
Mage::log('Shopaton Order exportOrder', null, 'Shopatron.log');
$dirPath = Mage::getBaseDir('var') . DS . 'export';
if (!is_dir($dirPath))
{
mkdir($dirPath, 0777, true);
}
$customerIP = Mage::helper('core/http')->getRemoteAddr(true);
$data=array();
//Getting the Proper 2 Character State
$regionModel = Mage::getSingleton('directory/region');
$regionModel->load($order->getShippingAddress()->getRegionId());
$sstate_code = $regionModel->getCode();
$regionModel->load($order->getBillingAddress()->getRegionId());
$bstate_code = $regionModel->getCode();
Mage::log($bstate_code, null, 'Shopatron.log');
Mage::log($sstate_code, null, 'Shopatron.log');
$data = array('OrderID'=>$order->getIncrementId(),
'Email'=>$order->getData('customer_email'),
'CustomerIP'=>$customerIP,
'ShipMethod' =>$order->getData('shipping_method'),
'ShippingPhone' =>$order->getShippingAddress()->getData('telephone'),
'ShippingFirstName'=>$order->getShippingAddress()->getFirstname(),
'ShippingLastName' => $order->getShippingAddress()->getLastname(),
'ShippingStreet' => $order->getShippingAddress()->getStreet(),
'ShippingCity' => $order->getShippingAddress()->getCity(),
'ShippingState' => $sstate_code,
'ShippingCountry' => $order->getShippingAddress()->getCountryId(),
'ShippingZip' => substr($order->getShippingAddress()->getPostcode(),0,5),
'BillingPhone' => $order->getBillingAddress()->getData('telephone'),
'BillingFirstName' => $order->getBillingAddress()->getFirstname(),
'BillingLastName' => $order->getBillingAddress()->getLastname(),
'BillingStreet' => $order->getBillingAddress()->getStreet(),
'BillingCity' => $order->getBillingAddress()->getcity(),
'BillingState' => $bstate_code,
'BillingCountry' => $order->getBillingAddress()->getCountryId(),
'BillingZip' => substr($order->getBillingAddress()->getPostcode(),0,5),
//Why can't I call getAllVisibleItems?
//'Items' => $order->getAllVisibleItems()
);
try{
$data['Items']=$this->createOrderItems($order->getIncrementId());
} catch(Exception $e){
Mage::log($e->getMessage(), null, 'system.log');
//Nothing shows up in the log to help troubleshoot
}
//$xstrout = toXmlRpc($data);
/*file_put_contents(
$dirPath. DS .$data['OrderID'].'.xml22',
print "<PRE>" . htmlentities ( $xstrout ) . "</PRE>",
FILE_APPEND
);*/
//sendMsg($xstrout);
return true;
}
Issue:
lot of issue:
public function createOrderItems($orderId)
{
Mage::log('Shopatron Order createOrderItems', null, 'Shopatron.log');
$order=Mage::getModel('sales/order')->loadByIncrementId($orderId);
$items=$order->getAllVisibleItems();
$i=0;
$IO=array();
$itemcount=count($items);
foreach ($items as $item)
{
$IO[$i]['name']=$item->getName();
$IO[$i]['price']=$item->getPrice();
$IO[$i]['sku']=$item->getSku();
$IO[$i]['id']=$item->getProductId();
// $IO[$i]['upc']=getUpcFromSku($item->getSku());
$IO[$i]['qty']=$item->getQtyOrdered(); //$item->getQtyToInvoice();
//$IO[$i]['options']=createOptionsArray($item->getProductOptions(), $itemId);
if($itemcount>1)
{
$IO[$i]['shipping']=$order->getData('shipping_amount')/$itemcount;
$IO[$i]['tax'] = $order->getData('tax_amount')/$itemcount;
}
elseif($itemcount == 1)
{
$IO[$i]['shipping']=$order->getData('shipping_amount');
$IO[$i]['tax'] = $order->getData('tax_amount');
}
$i++;
}
return $IO;
}
}
I figured it out myself. You need to observe the event checkout_cart_product_add_after
. In the observer you need the following:
public function change_price(Varient_Event_Observer $observer) {
// get the quote
$item = $observer->getQuoteItem();
// checks for parent item
if ($item->getParentItem()) {
$item = $item->getParentItem();
}
// your price logic here
$new_price = 999;
$item->setCustomPrice($new_price);
$item->setOriginalCustomPrice($new_price);
$item->getProduct()->setIsSuperMode(true);
}
Best Answer
Instead of
you should use something like this:
The key here is that removing an item, sets the
is_deleted
flag and with this you can check if an item is already flagged for deletion. Also you don't need to save each one individually as long as the cart gets saved in the end.