How can I remove a shipment that was created accidentally? I know there is no way to do it through the admin, but I'm trying to figure out what I need to do to revert an order back to a status of "Processing" along with all the old shipment information so it can be shipped at a later time. I'm hoping this can be done programmatically via PHP or even just directly in MySQL.
FYI, I'm using Magento version 1.1.8.
Try
require_once 'app/Mage.php';
Varien_Profiler::enable();
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app('default');
Mage::register('isSecureArea', 1);
//Update Order id
$orderId = xyz;
$order = Mage::getModel('sales/order')->load($orderId);
// check if has shipments
if(!$order->hasShipments()){
die('No Shipments');
}
//delete shipment
$shipments = $order->getShipmentsCollection();
foreach ($shipments as $shipment){
$shipment->delete();
}
// Reset item shipment qty
// see Mage_Sales_Model_Order_Item::getSimpleQtyToShip()
$items = $order->getAllVisibleItems();
foreach($items as $i){
$i->setQtyShipped(0);
$i->save();
}
//Reset order state
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Undo Shipment');
$order->save();
echo 'Done';
$shipment = Mage::getModel('sales/order_shipment')->load($shippingOrderId);
$shipment->delete();
I assume this works. I haven't tried it.
I ended up purchasing the extension below which did the trick beautifully. Even though it doesn't say it supports versions prior to 1.3, it worked flawlessly on my setup of v1.1.8.
http://www.magentocommerce.com/magento-connect/delete-shipment-6498.html
Say you shipped an order in its entirety and didn't mean to. Just delete the INVOICE. It will remove the invoice and any of the shipments...SHIPMENTS plural!
So you have to be careful, if you have other shipments you will need to recreate them. Then invoice it again. Then it will be just like you never shipped anything and you can then SHIP whatever quantity you originally required.
Related
I want to simply change the shipping method of an order on Woocommerce.
I have seen a few posts on editing shipping methods on orders but I'm not 100% clear on the exact protocol of how it works, I have a rough idea but no success yet! If you can help me to get the order to update its shipping method that would be awesome! (this is the middle of a large project so I can't share the whole plugin, let me know if you need anymore details happy to provide anything that's necessary!)
I have this small bit of code that returns me a list of orders that need shipping method updated and the new shipping method rateID that it has to be changed to, that all works fine but i have included it so you can see where it comes from.
Once the array of orders to be updated has been constructed, it then needs to be processed using the set_shipping() method. One at a time working through the array items and updating the shipping method of each, from the original to the new one provided in the toUpdate array
UPDATED: i have tried using the WC_API_Orders() class as set_shipping is a method of that. still coming up with the unrecognised error.
'Class 'Inc\Api\Callbacks\WC_API_Orders' not found'
private function updateRound()
{
if (! empty($_POST['update'])) {
$updateorderID= $_POST['orderID']; //get list of orderID to change
$updateRound= $_POST['newRound']; //list of rounds new orders want swapped to
$updateList= $_POST['update']; //uses a check box to confirm user wants to update row (stops accidentally updating the whole list)
// print_r($_POST['update']); //shows an output to check results.
$toUpdate = []; //this is the array for all the shippingmmethods to update on set order etc.
//make list of order ID's to update and their new shipping method
foreach ($updateList as $key => $value) {
$toUpdate[] = [
'orderID' => $key,
'newRound' => $updateRound[$key]
];
}
}
$absOrder = new WC_API_Orders();
foreach ($toUpdate as $updateOrder) {
//echo "</br>OrderID: ".$updateOrder['orderID']." Round updated to ".$updateOrder['newRound'];
echo "order ".$updateOrder['orderID']."updating";
$absOrder->wc_get_order($updateOrder['orderID']);
echo " order retreived";
$absOrder->set_shipping($order, $updateOrder['newRound'], 'update' );
echo "updated </br>";
}
}
This is for a very local veg delivery scheme, people can only place an order if their postcode is in the set group, so that's not so important, this shipping method we use to change from 'wed round' to 'thurs round' etc. Simple really no concern for delivery companies etc, its all in house. Tax etc. doesn't matter, it's all done elsewhere, this is simply meant to be a way of editing orders onto delivery rounds.
I have a problem seeing products on the frontend of Magento.
I have created a script, save.php:
<?php
set_time_limit(0);
// require magento core
require_once 'app/Mage.php';
// execute on admin store
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$products = Mage::getModel('catalog/product')->getCollection();
foreach($products as $product) {
echo $product->getName() . '<br/>';
// save the product
$product->save();
}
echo 'DONE';
?>
After I run it with php -f /var/www/shell/save.php, I still don't see the product on frontend. If I save product with backend I see it, why is that?
Please Clarify your question:
If you are simply wanting to see your echos of the product name and the final 'done', it could be either Permissions may need to be set to 644 or the script is not in magento root.
If that is not your question:
Your current code is saving objects who's record(s) are already in your DB, without changing any data to save..
The proper way to duplicate is:
$newProduct = clone $product;
$newProduct->setData('sku','wowaNewSkuString');
$newProduct->save();
The proper way to just edit, is:
$product->setData('sku','wowaNewSkuString');
$product->save();
And of course, with Magento always flush cache and reindex after major changed/edits to ensure your flat tables (if enabled) are up to date.
I'm working on the automation of the shipping method, it seems to be working fine, but problem is:
Every 2nd order there is same error "Please specify a shipping method"
Can it be session error? Should variables be send over get-post or retrieved from Magento in other way?
Here is a code:
<?php
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
echo $customAddress = Mage::getModel('customer/address')->load($customer->getDefaultBilling());
$quote = Mage::getSingleton('checkout/session')->getQuote()->setBillingAddress(Mage::getSingleton('sales/quote_address')->importCustomerAddress($customAddress));
$cart = Mage::getSingleton('checkout/cart');
$storeId = Mage::app()->getStore()->getId();
$checkout = Mage::getSingleton('checkout/type_onepage');
$checkout->initCheckout();
$checkout->saveCheckoutMethod('register');
$checkout->saveShippingMethod('matrixrate_matrixrate_35');
$checkout->savePayment(array('method'=>'pay'));
Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->setShippingMethod('matrixrate_matrixrate_35');
try {
if ($checkout->saveOrder()) {echo "SUCCESSSSS!!!";}}
catch (Exception $ex) {
echo $ex->getMessage();
}
/* Clear the cart */
$cart->truncate();
$cart->save();
$cart->getItems()->clear()->save();
Mage::getSingleton('checkout/session')->clear();
It's using custom payment gateway called Pay and I'm using matrixrate extension for shipping, althought there is same eror on flatrate_flatrate so I don'd consider it as extension issue.
Thanks!!!
Adam
Issue: Cart items still displaying after order splitting
1.Save quote collection in shipping method step..
$quote->collectTotals()->save();
2.Add the below steps in the last section of the order split.
$quote->setIsActive(false);
$quote->save();
PROBLEM IS SOLVED.
Looks like there has been issue with sessions/time, server didn't process everything at once.
I had to add on cart-total page:
$checkout->getQuote()->getShippingAddress()->setShippingMethod('matrixrate_matrixrate_35');
$checkout->saveShippingMethod('matrixrate_matrixrate_35');
To make sure that shipping is set, also:
session is cleared at success page manually.
There has been a bug with total quote amount, so I just redesigned script to count it properly.
Many Thanks for help!!
Adam
I hope someone can help me with this, I am trying to extract the product prices from magento based on customer group.
I am not using tier pricing, I simply have a product with a standard price and I have specified different prices for each customer group. For some reason I have been unable to extract this information.
I can see that the price mappings seems to be held in the table 'catalog_product_index_group_price' so I guess I could write direct SQL to extract these but I would much rather use the PHP Mage model to do this, or the V2 SOAP API.
I have tried many methods, currently im using something like below, but without success the price variable is always empty.
$rules = Mage::getResourceModel('catalogrule/rule');
$price = $rules->getRulePrice($now, $websiteId, $customer_group_id, $productID);
Please try the following
$product = Mage::getModel('catalog/product')->load($productId);
$groupPrices = $product->getData('group_price')
$groupPrices should now be an array with the data you are looking for.
the code didnt format well in the comment so here it is again!
<?php
include_once '../App/Mage.php';
Mage::app();
$productID = $_GET["id"];
$pd = Mage::getModel('catalog/product')->load($productID);
$groupPrices = $pd->getData('group_price');
echo json_encode($groupPrices);
?>
I am trying to write a module that syncs my newsletter subscribers in Magento with a external database. I need to be able to update the subscription status in Magento programmatically but I am having diffuculty getting the "setStatus" method in Magento to work. It does not throw any errors but the code does not seem to have any effect. Below is the code where I call the method:
$collection = Mage::getResourceModel('newsletter/subscriber_collection')->showStoreInfo()->showCustomerInfo();
foreach ($collection as $cust) {
$cust->setStatus(1);
}
In theory, this should set the status of all of my subscribers to "subscribed". I could optionally change the argument sent to "setStatus" to any of the below ints for a different status.
1: Subscribed
2: Status Not Active
3: Unsubscribed
How to best change the subscriber status or get this code working?
Here an import script:
<?php
require_once("./app/Mage.php");
Mage::app();
$subscribers = array('email1#server1.com', 'email2#server2.com');
foreach ($subscribers as $email) {
# create new subscriber without send an confirmation email
Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe($email);
# get just generated subscriber
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
# change status to "subscribed" and save
$subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
$subscriber->save();
}
?>
It seems that newsletter subscribers are also stored elsewhere. What you are setting is just a check in the customer base for some other use.
You need to do the following for each customer as well.
Mage::getModel('newsletter/subscriber')->subscribe($email);
See this link for a complete reference.
Thanks to the link #Ozair shared I was able to figure out what I needed to do.
I was successfully setting the status of the subscriber in the Magento subscriber object but I was not saving the object. I needed to call Magento's save method so it would call the ORM and write it to the database. All I need to do was add
$cust->save();
in the for loop. Below is the whole code snippet.
$collection = Mage::getResourceModel('newsletter/subscriber_collection')->showStoreInfo()->showCustomerInfo();
foreach ($collection as $cust) {
$cust->setStatus(1);
$cust->save();
}
I Hope this helps someone in the future. I needed it for a Constant Contact - Magento Synchronization extension I was making: http://www.freelunchlabs.com/store/constant-contact-and-magento-sync.html