Ejemplo n.º 1
0
 /**
  * Edit te payment method of an order
  * @param TinyBrick_OrderEdit_Model_Order $order
  * @param array $data
  * @return string 
  */
 public function edit(TinyBrick_OrderEdit_Model_Order $order, $data = array())
 {
     $array = array();
     $payment = $order->getPayment();
     $oldPaymentmethod = $payment->getMethod();
     //echo '<pre>old';print_r($oldPaymentmethod);echo '</pre>';
     //echo '<pre>new';print_r($data);echo '</pre>';die;
     if ($data['paymentmethod_id'] != '') {
         $payment->setMethod($data['paymentmethod_id']);
     }
     try {
         $payment->save();
         $newPaymentmethod = $payment->getMethod();
         $results = strcmp($oldPaymentmethod, $newPaymentmethod);
         if ($results != 0) {
             $comment = "Changed payment method:<br />";
             $comment .= "Changed FROM: " . $oldPaymentmethod . " TO: " . $newPaymentmethod . "<br /><br />";
             return $comment;
         }
         return true;
     } catch (Exception $e) {
         $array['status'] = 'error';
         $array['msg'] = "Error updating payment method";
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 /** 
  * Adds new items to order
  * @param TinyBrick_OrderEdit_Model_Order $order
  * @param array $data
  * @return boolean
  */
 public function edit(TinyBrick_OrderEdit_Model_Order $order, $data = array())
 {
     $comment = "";
     if ($data['simplesku']) {
         $producttype = 'simplesku';
     } else {
         $producttype = 'sku';
     }
     foreach ($data[$producttype] as $key => $sku) {
         $qty = $data['qty'][$key];
         $product = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('sku', $sku)->addAttributeToSelect('*')->getFirstItem();
         $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
         $stockItem->subtractQty($qty);
         $stockItem->save();
         $quoteItem = Mage::getModel('sales/quote_item')->setProduct($product)->setQuote(Mage::getModel('sales/quote')->load($order->getQuoteId()));
         //$quoteItem->setOptions(array(501=>36, 502=>41));
         $orderItem = Mage::getModel('sales/convert_quote')->itemToOrderItem($quoteItem)->setProduct($product);
         $productPrice = $data['price'][$key];
         //$options = array(501=>36, 502=>41);
         //$orderItem->setProductOptions($options);
         //$orderItem->addAttribute($options);
         $orderItem->setPrice($productPrice);
         $orderItem->setBasePrice($productPrice);
         $orderItem->setBaseOriginalPrice($productPrice);
         $orderItem->setOriginalPrice($productPrice);
         $orderItem->setQtyOrdered($qty);
         if ($data['discount'][$key]) {
             $orderItem->setDiscountAmount($data['discount'][$key]);
         } else {
             $orderItem->setDiscountAmount(0);
         }
         $orderItem->setOrderId($order->getId());
         $orderItem->setOrder($order);
         $orderItem->save();
         $order->addItem($orderItem);
         $order->save();
         $comment .= "Added item(SKU): " . $sku . "<br />";
     }
     if ($comment != "") {
         $comment = "Added new items:<br />" . $comment;
         return $comment;
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Does the actual editing of the billing address for the order
  * @param TinyBrick_OrderEdit_Model_Order $order
  * @param array $data
  * @return boolean 
  */
 public function edit(TinyBrick_OrderEdit_Model_Order $order, $data = array())
 {
     $array = array();
     $billing = $order->getBillingAddress();
     $oldArray = $billing->getData();
     //echo '<pre>old';print_r($oldArray);echo '</pre>';
     //echo '<pre>new';print_r($data);echo '</pre>';die;
     $data['street'] = $data['street1'];
     if ($data['street2']) {
         $data['street'] .= "\n" . $data['street2'];
     }
     $billing->setData($data);
     try {
         $billing->save();
         /**
          * logging for changes in billing address
          */
         $newArray = $billing->getData();
         $results = array_diff($oldArray, $newArray);
         $count = 0;
         $comment = "";
         // echo '<pre>';print_r($results);echo '</pre>';die;
         foreach ($results as $key => $result) {
             if (array_key_exists($key, $newArray)) {
                 if ($key == 'updated_at') {
                 } else {
                     $comment .= "Changed " . $key . " FROM: " . $oldArray[$key] . " TO: " . $newArray[$key] . "<br />";
                     $count++;
                 }
             }
         }
         if ($count != 0) {
             $comment = "Changed billing address:<br />" . $comment . "<br />";
             return $comment;
         }
         return true;
     } catch (Exception $e) {
         $array['status'] = 'error';
         $array['msg'] = "Error updating billing address";
         return false;
     }
 }
Ejemplo n.º 4
0
 /**
  * Edits the shipping address of the order
  * @param TinyBrick_OrderEdit_Model_Order $order
  * @param array $data
  * @return string 
  */
 public function edit(TinyBrick_OrderEdit_Model_Order $order, $data = array())
 {
     $array = array();
     $shipping = $order->getShippingAddress();
     $oldArray = $shipping->getData();
     $data['street'] = $data['street1'];
     if ($data['street2']) {
         $data['street'] .= "\n" . $data['street2'];
     }
     $shipping->setData($data);
     $region = Mage::getResourceModel('directory/region_collection')->addFieldToFilter('default_name', $data['region'])->getFirstItem();
     $shipping->setRegionId($region->getId());
     try {
         $shipping->save();
         $newArray = $shipping->getData();
         $results = array_diff($oldArray, $newArray);
         $count = 0;
         $comment = "";
         foreach ($results as $key => $result) {
             if (array_key_exists($key, $newArray)) {
                 if ($key == 'updated_at') {
                 } else {
                     $comment .= "Changed " . $key . " FROM: " . $oldArray[$key] . " TO: " . $newArray[$key] . "<br />";
                     $count++;
                 }
             }
         }
         if ($count != 0) {
             $comment = "Changed shipping address:<br />" . $comment . "<br />";
             return $comment;
         }
         return true;
     } catch (Exception $e) {
         $array['status'] = 'error';
         $array['msg'] = "Error updating shipping address";
         return false;
     }
 }
Ejemplo n.º 5
0
 /**
  * Edits the status of the order
  * @param TinyBrick_OrderEdit_Model_Order $order
  * @param array $data
  * @return string 
  */
 public function edit(TinyBrick_OrderEdit_Model_Order $order, $data = array())
 {
     $array = array();
     $oldStatus = $order->getStatusLabel();
     if ($data['status_id'] != '') {
         $order->setStatus($data['status_id']);
     }
     try {
         $order->save();
         $newStatus = $order->getStatusLabel();
         $results = strcmp($oldStatus, $newStatus);
         if ($results != 0) {
             $comment = "Changed Status:<br />";
             $comment .= "Changed FROM: " . $oldStatus . " TO: " . $newStatus . "<br /><br />";
             return $comment;
         }
         return true;
     } catch (Exception $e) {
         $array['status'] = 'error';
         $array['msg'] = "Error updating status";
         return false;
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Declare quote model instance
  *
  * @param   Mage_Sales_Model_Quote $quote
  * @return  Mage_Sales_Model_Quote_Payment
  */
 public function setOrder(TinyBrick_OrderEdit_Model_Order $order)
 {
     $this->_order = $order;
     $this->setOrderId($order->getId());
     return $this;
 }
Ejemplo n.º 7
0
 /** 
  * Edits existing items of the order
  * @param TinyBrick_OrderEdit_Model_Order $order
  * @param array $data
  * @return boolean 
  */
 public function edit(TinyBrick_OrderEdit_Model_Order $order, $data = array())
 {
     $comment = "";
     foreach ($data['id'] as $key => $itemId) {
         $item = $order->getItemById($itemId);
         $product = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('sku', $item->getSku())->addAttributeToSelect('*')->getFirstItem();
         if ($data['remove'][$key]) {
             $comment .= "Removed Item(SKU): " . $item->getSku() . "<br />";
             $oldQty = $item->getQtyOrdered();
             $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
             $stockItem->addQty($oldQty);
             $stockItem->save();
             $order->removeItem($itemId);
         } else {
             $oldArray = array('price' => $item->getPrice(), 'discount' => $item->getDiscountAmount(), 'qty' => $item->getQtyOrdered());
             $item->setPrice($data['price'][$key]);
             $item->setBasePrice($data['price'][$key]);
             $item->setBaseOriginalPrice($data['price'][$key]);
             $item->setOriginalPrice($data['price'][$key]);
             $item->setBaseRowTotal($data['price'][$key]);
             if ($data['discount'][$key]) {
                 $item->setDiscountAmount($data['discount'][$key]);
                 $item->setBaseDiscountAmount($data['discount'][$key]);
             }
             if ($data['qty'][$key]) {
                 $oldQty = $item->getQtyOrdered();
                 $item->setQtyOrdered($data['qty'][$key]);
                 $newQty = $item->getQtyOrdered();
                 if ($newQty > $oldQty) {
                     $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
                     $stockItem->subtractQty($newQty - $oldQty);
                     $stockItem->save();
                 } else {
                     if ($newQty < $oldQty) {
                         $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
                         $stockItem->addQty($oldQty - $newQty);
                         $stockItem->save();
                     }
                 }
             }
             $item->save();
             $newArray = array('price' => $item->getPrice(), 'discount' => $item->getDiscountAmount(), 'qty' => $item->getQtyOrdered());
             if ($newArray['price'] != $oldArray['price'] || $newArray['discount'] != $oldArray['discount'] || $newArray['qty'] != $oldArray['qty']) {
                 $comment = "Edited item " . $item->getSku() . "<br />";
                 if ($newArray['price'] != $oldArray['price']) {
                     $comment .= "Price FROM: " . $oldArray['price'] . " TO: " . $newArray['price'] . "<br />";
                 }
                 if ($newArray['discount'] != $oldArray['discount']) {
                     $comment .= "Discount FROM: " . $oldArray['discount'] . " TO: " . $newArray['discount'] . "<br />";
                 }
                 if ($newArray['qty'] != $oldArray['qty']) {
                     $comment .= "Qty FROM: " . $oldArray['qty'] . " TO: " . $newArray['qty'] . "<br />";
                 }
             }
         }
     }
     if ($comment != "") {
         $comment = "Edited items:<br />" . $comment . "<br />";
         return $comment;
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * Edits the shipping method of the order
  * @param TinyBrick_OrderEdit_Model_Order $order
  * @param array $data
  * @return string 
  */
 public function edit(TinyBrick_OrderEdit_Model_Order $order, $data = array())
 {
     $array = array();
     $orderStatus = $order->getStatus();
     $oldMethod = $order->getShippingDescription() . " - \$" . substr($order->getShippingAmount(), 0, -2);
     if ($data['customcarrier'] != '' && $data['rateid'] == 'custom') {
         $order->setShippingMethod('custom');
         $order->setShippingDescription($data['customcarrier'] . " - " . $data['customMethod']);
     } else {
         if ($data['rateid'] != 'custom') {
             $shippingRate = Mage::getModel('orderedit/order_address_rate')->getCollection()->addFieldToFilter('rate_id', $data['rateid'])->getFirstItem();
             $order->setShippingMethod($shippingRate->getCode());
             $order->setShippingDescription($shippingRate->getCarrierTitle() . " - " . $shippingRate->getMethodTitle());
         }
     }
     if ($data['customPrice'] != '') {
         $order->setShippingAmount($data['customPrice']);
         $order->setBaseShippingAmount($data['customPrice']);
     } else {
         if ($data['rateid'] != 'custom') {
             $order->setShippingAmount($shippingRate->getPrice());
         }
     }
     try {
         $order->save();
         //$newMethod = $order->getShippingDescription()." - $".substr($order->getShippingAmount(),0,-2);
         $newMethod = $order->getShippingDescription() . " - \$" . $order->getShippingAmount;
         $results = strcmp($oldMethod, $newMethod);
         if ($results != 0) {
             $comment = "Changed shipping method:<br />";
             $comment .= "Changed FROM: " . $oldMethod . " TO: " . $newMethod . "<br /><br />";
             return $comment;
         }
         return true;
     } catch (Exception $e) {
         $array['status'] = 'error';
         $array['msg'] = "Error updating shipping method";
         return false;
     }
     return true;
 }
Ejemplo n.º 9
0
 /**
  * Logs comment to the order
  * @param TinyBrick_OrderEdit_Model_Order $order
  * @param string $comment Comment appended to order
  * @param string $status Status of order
  * @param int $notify Notify customer
  */
 public function logComment(TinyBrick_OrderEdit_Model_Order $order, $comment, $status, $notify = 0)
 {
     $order->addStatusToHistory($status, $comment, $notify);
     $order->save();
 }