Unable to create shipment programmatically
I try to create programmatically a shipment of an order with a track code.
This is my current code :
$order = Mage::getModel('sales/order')->loadByIncrementId("100014930");
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($order->getItemQtys());
$arrTracking = array(
'carrier_code' => $order->getShippingCarrier()->getCarrierCode(),
'title' => $order->getShippingCarrier()->getConfigData('title'),
'number' => "1234",
);
$track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);
$shipment->addTrack($track);
$shipment->register();
$order->save();
With this, I have no error while I execute it.
In the Magento panel, you can't ship the order, but the order stay in pending and the shipment doesn't appear.
Please help
Problem solved with this solution
magento-1.9 shipment shipment-tracking
add a comment |
I try to create programmatically a shipment of an order with a track code.
This is my current code :
$order = Mage::getModel('sales/order')->loadByIncrementId("100014930");
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($order->getItemQtys());
$arrTracking = array(
'carrier_code' => $order->getShippingCarrier()->getCarrierCode(),
'title' => $order->getShippingCarrier()->getConfigData('title'),
'number' => "1234",
);
$track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);
$shipment->addTrack($track);
$shipment->register();
$order->save();
With this, I have no error while I execute it.
In the Magento panel, you can't ship the order, but the order stay in pending and the shipment doesn't appear.
Please help
Problem solved with this solution
magento-1.9 shipment shipment-tracking
Without any errors is hard to help you. Check all logs, also if logging is on and make sure display_errors is enabled
– Sander Mangel♦
Sep 8 '15 at 14:34
add a comment |
I try to create programmatically a shipment of an order with a track code.
This is my current code :
$order = Mage::getModel('sales/order')->loadByIncrementId("100014930");
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($order->getItemQtys());
$arrTracking = array(
'carrier_code' => $order->getShippingCarrier()->getCarrierCode(),
'title' => $order->getShippingCarrier()->getConfigData('title'),
'number' => "1234",
);
$track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);
$shipment->addTrack($track);
$shipment->register();
$order->save();
With this, I have no error while I execute it.
In the Magento panel, you can't ship the order, but the order stay in pending and the shipment doesn't appear.
Please help
Problem solved with this solution
magento-1.9 shipment shipment-tracking
I try to create programmatically a shipment of an order with a track code.
This is my current code :
$order = Mage::getModel('sales/order')->loadByIncrementId("100014930");
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($order->getItemQtys());
$arrTracking = array(
'carrier_code' => $order->getShippingCarrier()->getCarrierCode(),
'title' => $order->getShippingCarrier()->getConfigData('title'),
'number' => "1234",
);
$track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);
$shipment->addTrack($track);
$shipment->register();
$order->save();
With this, I have no error while I execute it.
In the Magento panel, you can't ship the order, but the order stay in pending and the shipment doesn't appear.
Please help
Problem solved with this solution
magento-1.9 shipment shipment-tracking
magento-1.9 shipment shipment-tracking
edited 11 mins ago
Himanshu
802521
802521
asked Sep 8 '15 at 14:31
grewn0uillegrewn0uille
1229
1229
Without any errors is hard to help you. Check all logs, also if logging is on and make sure display_errors is enabled
– Sander Mangel♦
Sep 8 '15 at 14:34
add a comment |
Without any errors is hard to help you. Check all logs, also if logging is on and make sure display_errors is enabled
– Sander Mangel♦
Sep 8 '15 at 14:34
Without any errors is hard to help you. Check all logs, also if logging is on and make sure display_errors is enabled
– Sander Mangel♦
Sep 8 '15 at 14:34
Without any errors is hard to help you. Check all logs, also if logging is on and make sure display_errors is enabled
– Sander Mangel♦
Sep 8 '15 at 14:34
add a comment |
1 Answer
1
active
oldest
votes
I think I've found your error. getItemQtys
is not a valid function on any Magento class, so in Magento magic methods it returns null
. Essentially you're trying to ship null
number of items. You can't do that. Yes, it fails silently.
Some controllers implement a _getItemQtys
method to return the values you're looking for; however none of these are plug and play. Instead I suggest you create this as it's just a keyed array in the format of:
array(
'order_item_id'=>$qty,
'order_item_id'=>$qty,
'order_item_id'=>$qty
)
However, if you're always shipping all items in a shipment, without exception there is an even easier way:
$converter=Mage::getModel('sales/convert_order');
$shipment=$converter->toShipment($order);
Please read this answer here for more information on how to create shipments programmatically:
https://magento.stackexchange.com/a/3345/336
I replaced the getItemsQty line with converter. When I execute, I got a Mage_Core_Exception "Cannot create an empty shipment" but when I var_dump the shipment (juste before saving it) I have all the information about it. Is it because loading the order like I did does make a Varien Object ?
– grewn0uille
Sep 8 '15 at 15:12
You needn't do anything (including save) just create the shipment with the $order.
– philwinkle
Sep 8 '15 at 15:17
So i don't keep the line with $shipment->register() ? Do i keep the addTrack() things ? Now just nothing is happening, no error, no shipment created.
– grewn0uille
Sep 8 '15 at 15:35
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f82325%2funable-to-create-shipment-programmatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think I've found your error. getItemQtys
is not a valid function on any Magento class, so in Magento magic methods it returns null
. Essentially you're trying to ship null
number of items. You can't do that. Yes, it fails silently.
Some controllers implement a _getItemQtys
method to return the values you're looking for; however none of these are plug and play. Instead I suggest you create this as it's just a keyed array in the format of:
array(
'order_item_id'=>$qty,
'order_item_id'=>$qty,
'order_item_id'=>$qty
)
However, if you're always shipping all items in a shipment, without exception there is an even easier way:
$converter=Mage::getModel('sales/convert_order');
$shipment=$converter->toShipment($order);
Please read this answer here for more information on how to create shipments programmatically:
https://magento.stackexchange.com/a/3345/336
I replaced the getItemsQty line with converter. When I execute, I got a Mage_Core_Exception "Cannot create an empty shipment" but when I var_dump the shipment (juste before saving it) I have all the information about it. Is it because loading the order like I did does make a Varien Object ?
– grewn0uille
Sep 8 '15 at 15:12
You needn't do anything (including save) just create the shipment with the $order.
– philwinkle
Sep 8 '15 at 15:17
So i don't keep the line with $shipment->register() ? Do i keep the addTrack() things ? Now just nothing is happening, no error, no shipment created.
– grewn0uille
Sep 8 '15 at 15:35
add a comment |
I think I've found your error. getItemQtys
is not a valid function on any Magento class, so in Magento magic methods it returns null
. Essentially you're trying to ship null
number of items. You can't do that. Yes, it fails silently.
Some controllers implement a _getItemQtys
method to return the values you're looking for; however none of these are plug and play. Instead I suggest you create this as it's just a keyed array in the format of:
array(
'order_item_id'=>$qty,
'order_item_id'=>$qty,
'order_item_id'=>$qty
)
However, if you're always shipping all items in a shipment, without exception there is an even easier way:
$converter=Mage::getModel('sales/convert_order');
$shipment=$converter->toShipment($order);
Please read this answer here for more information on how to create shipments programmatically:
https://magento.stackexchange.com/a/3345/336
I replaced the getItemsQty line with converter. When I execute, I got a Mage_Core_Exception "Cannot create an empty shipment" but when I var_dump the shipment (juste before saving it) I have all the information about it. Is it because loading the order like I did does make a Varien Object ?
– grewn0uille
Sep 8 '15 at 15:12
You needn't do anything (including save) just create the shipment with the $order.
– philwinkle
Sep 8 '15 at 15:17
So i don't keep the line with $shipment->register() ? Do i keep the addTrack() things ? Now just nothing is happening, no error, no shipment created.
– grewn0uille
Sep 8 '15 at 15:35
add a comment |
I think I've found your error. getItemQtys
is not a valid function on any Magento class, so in Magento magic methods it returns null
. Essentially you're trying to ship null
number of items. You can't do that. Yes, it fails silently.
Some controllers implement a _getItemQtys
method to return the values you're looking for; however none of these are plug and play. Instead I suggest you create this as it's just a keyed array in the format of:
array(
'order_item_id'=>$qty,
'order_item_id'=>$qty,
'order_item_id'=>$qty
)
However, if you're always shipping all items in a shipment, without exception there is an even easier way:
$converter=Mage::getModel('sales/convert_order');
$shipment=$converter->toShipment($order);
Please read this answer here for more information on how to create shipments programmatically:
https://magento.stackexchange.com/a/3345/336
I think I've found your error. getItemQtys
is not a valid function on any Magento class, so in Magento magic methods it returns null
. Essentially you're trying to ship null
number of items. You can't do that. Yes, it fails silently.
Some controllers implement a _getItemQtys
method to return the values you're looking for; however none of these are plug and play. Instead I suggest you create this as it's just a keyed array in the format of:
array(
'order_item_id'=>$qty,
'order_item_id'=>$qty,
'order_item_id'=>$qty
)
However, if you're always shipping all items in a shipment, without exception there is an even easier way:
$converter=Mage::getModel('sales/convert_order');
$shipment=$converter->toShipment($order);
Please read this answer here for more information on how to create shipments programmatically:
https://magento.stackexchange.com/a/3345/336
edited Apr 13 '17 at 12:54
Community♦
1
1
answered Sep 8 '15 at 14:44
philwinklephilwinkle
33.1k579143
33.1k579143
I replaced the getItemsQty line with converter. When I execute, I got a Mage_Core_Exception "Cannot create an empty shipment" but when I var_dump the shipment (juste before saving it) I have all the information about it. Is it because loading the order like I did does make a Varien Object ?
– grewn0uille
Sep 8 '15 at 15:12
You needn't do anything (including save) just create the shipment with the $order.
– philwinkle
Sep 8 '15 at 15:17
So i don't keep the line with $shipment->register() ? Do i keep the addTrack() things ? Now just nothing is happening, no error, no shipment created.
– grewn0uille
Sep 8 '15 at 15:35
add a comment |
I replaced the getItemsQty line with converter. When I execute, I got a Mage_Core_Exception "Cannot create an empty shipment" but when I var_dump the shipment (juste before saving it) I have all the information about it. Is it because loading the order like I did does make a Varien Object ?
– grewn0uille
Sep 8 '15 at 15:12
You needn't do anything (including save) just create the shipment with the $order.
– philwinkle
Sep 8 '15 at 15:17
So i don't keep the line with $shipment->register() ? Do i keep the addTrack() things ? Now just nothing is happening, no error, no shipment created.
– grewn0uille
Sep 8 '15 at 15:35
I replaced the getItemsQty line with converter. When I execute, I got a Mage_Core_Exception "Cannot create an empty shipment" but when I var_dump the shipment (juste before saving it) I have all the information about it. Is it because loading the order like I did does make a Varien Object ?
– grewn0uille
Sep 8 '15 at 15:12
I replaced the getItemsQty line with converter. When I execute, I got a Mage_Core_Exception "Cannot create an empty shipment" but when I var_dump the shipment (juste before saving it) I have all the information about it. Is it because loading the order like I did does make a Varien Object ?
– grewn0uille
Sep 8 '15 at 15:12
You needn't do anything (including save) just create the shipment with the $order.
– philwinkle
Sep 8 '15 at 15:17
You needn't do anything (including save) just create the shipment with the $order.
– philwinkle
Sep 8 '15 at 15:17
So i don't keep the line with $shipment->register() ? Do i keep the addTrack() things ? Now just nothing is happening, no error, no shipment created.
– grewn0uille
Sep 8 '15 at 15:35
So i don't keep the line with $shipment->register() ? Do i keep the addTrack() things ? Now just nothing is happening, no error, no shipment created.
– grewn0uille
Sep 8 '15 at 15:35
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f82325%2funable-to-create-shipment-programmatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Without any errors is hard to help you. Check all logs, also if logging is on and make sure display_errors is enabled
– Sander Mangel♦
Sep 8 '15 at 14:34