Usually the “picked” and “packed” items will show the status as “pending shipment” as per the SCAstandard feature, But if we need to point out the exact status of “picked” and “packed” we can use the below code in Extension.
So for the “picked” item, the status will be “picked” and for “packed” item the status will be “packed”.
prototype.getShippablePackages = _.wrap(prototype.getShippablePackages, function getShippablePackages(fn) {
//let container = SC.Application(Object.keys(SC._applications)[0])
var currentView = application.getLayout().currentView
console.log("CurrentView", currentView);
console.log("this of getshippable", this)
//var shipmethod = this.model.attributes.shipmethod.attributes.name
// var context = fn.call(this);
var self = this
, shippable_lines = this.getShippableLines()
, is_multi_ship_to = this.model.get('ismultishipto')
, ship_groups = {}
, amount = 0;
_.each(shippable_lines || [], function (line) {
// console.log("this of", self)
console.log("line of", line)
if (line.get('quantitybackordered') || line.get('quantitypicked') || line.get('quantitypacked')) {
var shipaddress = is_multi_ship_to ? line.get('shipaddress') : self.model.get('shipaddress')
, shipmethod = is_multi_ship_to ? line.get('shipmethod') : self.model.get('shipmethod');
if (line.get('quantitybackordered')) {
var pending_line;
if (line.get('quantitypacked') === line.get('quantity')) {
pending_line = line;
}
else {
pending_line = line.clone();
pending_line.set('item', line.get('item').attributes);
pending_line.set('quantity', line.get('quantitybackordered'));
amount = BigNumber(line.get('rate')).times(pending_line.get('quantity')).toNumber();
pending_line.set('amount', amount);
pending_line.set('amount_formatted', Utils.formatCurrency(amount));
}
var key_pending = [shipaddress, shipmethod, 'pending'].join('-');
ship_groups[key_pending] = ship_groups[key_pending] || {
internalid: key_pending
, shipaddress: self.model.get('addresses').findWhere({ internalid: shipaddress })
, shipmethod: self.model.get('shipmethods').findWhere({ internalid: shipmethod })
, packageGroup: 'ship'
, status: {
internalid: 'pending'
, name: _('Pending shipment').translate()
}
, lines: []
, ScriptsShipmethod: self.model.get('shipmethods').findWhere({ internalid: shipmethod }) ?
(self.model.get('shipmethods').findWhere({ internalid: shipmethod })).get('name') : ''
};
ship_groups[key_pending].lines.push(pending_line);
}
if (line.get('quantitypicked') || line.get('quantitypacked')) {
var picked_packed_line;
var quantity = 0;
if (line.get('quantitypicked')) {
quantity += line.get('quantitypicked');
}
if (line.get('quantitypacked')) {
quantity += line.get('quantitypacked');
}
if (quantity === line.get('quantity')) {
picked_packed_line = line;
}
else {
picked_packed_line = line.clone();
picked_packed_line.set('quantity', quantity);
amount = BigNumber(line.get('rate')).times(picked_packed_line.get('quantity')).toNumber();
picked_packed_line.set('amount', amount);
picked_packed_line.set('amount_formatted', Utils.formatCurrency(amount));
picked_packed_line.set('item', line.get('item').attributes);
}
var key_processing = [shipaddress, shipmethod, 'processing'].join('-');
if (line.get('quantitypicked')) {
ship_groups[key_processing] = ship_groups[key_processing] || {
internalid: key_processing
, shipaddress: self.model.get('addresses').findWhere({ internalid: shipaddress })
, shipmethod: self.model.get('shipmethods').findWhere({ internalid: shipmethod })
, packageGroup: 'ship'
, status: {
internalid: 'picked_packed'
, name: _('Picked').translate()
}
, lines: []
, ScriptsShipmethod: self.model.get('shipmethods').findWhere({ internalid: shipmethod }) ?
(self.model.get('shipmethods').findWhere({ internalid: shipmethod })).get('name') : ''
};
}
if (line.get('quantitypacked')) {
ship_groups[key_processing] = ship_groups[key_processing] || {
internalid: key_processing
, shipaddress: self.model.get('addresses').findWhere({ internalid: shipaddress })
, shipmethod: self.model.get('shipmethods').findWhere({ internalid: shipmethod })
, packageGroup: 'ship'
, status: {
internalid: 'picked_packed'
, name: _('Packed').translate()
}
, lines: []
, ScriptsShipmethod: self.model.get('shipmethods').findWhere({ internalid: shipmethod }) ?
(self.model.get('shipmethods').findWhere({ internalid: shipmethod })).get('name') : ''
};
}
ship_groups[key_processing].lines.push(picked_packed_line);
}
}
});
console.log("this of fulfillments", this)
this.model.get('fulfillments').each(function (fulfillment) {
var shipaddress = self.model.get('addresses').findWhere({ internalid: fulfillment.get('shipaddress') })
, shipmethod = self.model.get('shipmethods').findWhere({ internalid: fulfillment.get('shipmethod') });
console.log("fulfillment of getshippable", fulfillment)
fulfillment.set('shipaddress', shipaddress);
fulfillment.set('shipmethod', shipmethod);
var lines = _.compact(fulfillment.get('lines').map(function (line) {
var fulfilled_line
, original_line = self.model.get('lines').get(line.get('internalid'));
if (original_line && original_line.get('linegroup') === 'shippable') //ignore instore lines
{
if (original_line.get('quantity') === line.get('fulfilled')) {
fulfilled_line = original_line;
}
else {
fulfilled_line = original_line.clone();
fulfilled_line.set('quantity', line.get('quantity'));
amount = BigNumber(original_line.get('rate')).times(fulfilled_line.get('quantity')).toNumber();
fulfilled_line.set('amount', amount);
fulfilled_line.set('amount_formatted', Utils.formatCurrency(amount));
fulfilled_line.set('item', original_line.get('item'), { silent: true });
}
return fulfilled_line;
}
}));
if (lines.length) {
console.log("ship method 2", shipmethod)
ship_groups[fulfillment.get('internalid')] = ship_groups[fulfillment.get('internalid')] || {
internalid: fulfillment.get('internalid')
, shipaddress: shipaddress
, shipmethod: shipmethod
, packageGroup: 'ship'
, status: {
internalid: 'shipped'
, name: _('Shipped').translate()
}
, date: fulfillment.get('date')
, trackingnumbers: fulfillment.get('trackingnumbers')
, lines: []
, transactiondate: fulfillment.get('transactiondate')
, ScriptsShipmethod: fulfillment.get('ScriptsShipmethod') || (shipmethod ? shipmethod.get('name') : '')
};
ship_groups[fulfillment.get('internalid')].lines = lines;
}
});
return _.values(ship_groups);
// return context;
})