Last active
August 29, 2015 14:01
-
-
Save jsieber/b9a409f5f1c74858a99c to your computer and use it in GitHub Desktop.
Create order deliveries in Slatwall for old orders without deliveries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
This file belongs in the integration views directory. | |
---> | |
<cfoutput> | |
<form name="processOrders" action="?s=1" class="form-horizontal"> | |
<input type="hidden" name="slatAction" value="aca_closeOrder:main.processOrder" /> | |
<fieldset class="dl-horizontal"> | |
<div class="control-group"> | |
<label class="control-label" for="username">Order Number</label> | |
<div class="controls"> | |
<input type="text" name="orderNumberStart"> | |
</div> | |
</div> | |
<input type="submit" name="submit" class="btn"> | |
</fieldset> | |
</form> | |
</cfoutput> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adventure Cycling Association | |
John Sieber 4/30/2014 | |
Integration to bulk close open orders within Slatwall | |
Notes: This file goes in the root of the integration directory. | |
*/ | |
component accessors="true" output="false" extends="Slatwall.integrationServices.BaseIntegration" implements="Slatwall.integrationServices.IntegrationInterface" { | |
public any function init() { | |
return this; | |
} | |
public string function getIntegrationTypes() { | |
return "fw1"; | |
} | |
public string function getDisplayName() { | |
return "ACA Close Orders"; | |
} | |
public struct function getSettings() { | |
var settings = { | |
// OrderID = {fieldType="text"} | |
}; | |
return settings; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Adventure Cycling Association | |
John Sieber 4/30/2014 | |
Integration to bulk close open orders within Slatwall | |
Notes: | |
Modified to attempt to close orders that contained mixed fulfillments, partial payment captures and partial order deliveries due to back ordered product. js 20140617 | |
*/ | |
component extends="Slatwall.org.Hibachi.HibachiController" { | |
public function processOrder(required struct rc) { | |
var numberToProcess = arguments.rc.NumberToProcess; | |
var result = []; | |
var orderObj = "empty"; | |
// writeDump(var="#arguments#", top=2, abort=true); | |
if(isNumeric(arguments.rc.orderNumberStart)) { | |
for(i = arguments.rc.orderNumberStart; i < arguments.rc.orderNumberStart + numberToProcess; i = i + 1){ | |
orderObj = entityLoad("SlatwallOrder",{orderNumber=i},true); | |
//writeDump(var="#orderObj#", top=2); | |
//abort; | |
if(! isDefined("orderObj") || ! isObject(orderObj)){ | |
arrayAppend(result, "Order: #i# - does not exist."); | |
writeLog(text="Order: #i# - does not exist." file="closeOrder"); | |
}else if(orderObj.getorderStatusType().gettype() eq "Closed"){ | |
arrayAppend(result, "Order: #orderObj.getOrderNumber()# - order is already is closed."); | |
writeLog(text="Order: #orderObj.getOrderNumber()# - order is already closed." file="closeOrder"); | |
}else if(orderObj.getorderStatusType().gettype() eq "Cancelled" || orderObj.getorderStatusType().gettype() eq "Canceled"){ | |
arrayAppend(result, "Order: #orderObj.getOrderNumber()# - order is already is canceled."); | |
writeLog(text="Order: #orderObj.getOrderNumber()# - order is already is canceled." file="closeOrder"); | |
}else if(! arrayLen(orderObj.getorderItems())){ | |
arrayAppend(result, "Order: #orderObj.getOrderNumber()# - order has no items."); | |
writeLog(text="Order: #orderObj.getOrderNumber()# - order has no items." file="closeOrder"); | |
}else if(orderObj.getorderStatusType().gettype() eq "On Hold"){ | |
arrayAppend(result, "Order: #orderObj.getOrderNumber()# - order is on hold."); | |
writeLog(text="Order: #orderObj.getOrderNumber()# - order is on hold." file="closeOrder"); | |
// handle orders that have multiple delivers, for example content access and physical shipping items. | |
/* Deprecated - We can't check for existing delivieries as orders with content access products will always have an existing delivery. | |
}else if(arrayLen(orderObj.getorderDeliveries()) and arrayLen(orderObj.getorderDeliveries()) eq 1){ | |
arrayAppend(result, "Order: #orderObj.getOrderNumber()# - already has all deliveries."); | |
writeLog(text="Order: #orderObj.getOrderNumber()# - already has all deliveries." file="closeOrder"); | |
*/ | |
}else{ | |
//writeDump(var="#orderObj.getorderFulfillments()#", top=2, abort=true); | |
for(item in orderObj.getorderFulfillments()){ | |
if(item.getfulfillmentMethod().getfulfillmentMethodType() eq "shipping"){ | |
var fulfillmentMethodID = item.getorderFulfillmentID(); | |
// writeDump(var="#item.getorderFulfillmentItems()#", top=3); | |
// abort; | |
var orderDeliveryItems = []; | |
var orderItem = {}; | |
var orderItemStruct = {}; | |
var quantity = {}; | |
// Loop through order items | |
for(var product in item.getorderFulfillmentItems()){ | |
orderItemStruct = {}; | |
//writeDump(var="#item#", top=3, abort=true); | |
// Make sure product has undelivered items. | |
if(product.getquantityUndelivered() gt 0){ | |
// writeLog(file="closeOrder" text="orderItemID = #product.getOrderItemID()#"); | |
orderItemStruct.orderItem = {orderItemID = product.getOrderItemID()}; | |
orderItemStruct.quantity = product.getQuantity(); | |
arrayAppend(orderDeliveryItems, orderItemStruct); | |
} | |
} | |
// make sure the order has undelivered items to create a delivery with. | |
if(arrayLen(orderDeliveryItems)){ | |
var data = { | |
order = { | |
orderID = '#item.getOrder().getOrderID()#' | |
}, | |
orderFulfillment = { | |
orderFulfillmentID = '#fulfillmentMethodID#' | |
}, | |
shippingMethod = { | |
shippingMethodID = '#item.getshippingMethod().getshippingMethodID()#' | |
}, | |
shippingAddress = { | |
addressID = '#item.getshippingAddress().getaddressID()#' | |
}, | |
location = { | |
locationID = '88e6d435d3ac2e5947c81ab3da60eba2' | |
}, | |
trackingNumber = '', | |
captureAuthorizedPaymentsFlag = 0, | |
orderDeliveryItems = orderDeliveryItems | |
}; | |
// create a new order delivery to populate | |
var orderDelivery = request.slatwallScope.getService('orderService').newOrderDelivery(); | |
// populate order delivery with order data | |
orderDelivery = request.slatwallScope.getService('orderService').processOrderDelivery(orderDelivery, data, 'create'); | |
// writeDump(var="#arguments.rc.$.slatwall.getORMHasErrors()#" top="2" abort="true"); | |
} | |
var orderPayment = orderObj.getOrderPayments()[1]; | |
if(orderPayment.getAmountUnreceived() gt 0){ | |
var paymentData = {amount=orderPayment.getAmountUnreceived(), transactionType='receiveOffline'}; | |
orderPayment = request.slatwallScope.getService('orderService').processOrderPayment(orderPayment, paymentData, 'createTransaction'); | |
} | |
if(! arguments.rc.$.slatwall.getORMHasErrors()){ | |
ormFlush(); | |
} else { | |
arrayAppend(result, "Order: #orderObj.getOrderNumber()# - An error has occured saving the entity."); | |
writeLog(text="Order: #orderObj.getOrderNumber()# - Error occured saving the entity." file="closeOrder"); | |
writeDump(var="#arguments.rc.$.slatwall.getORMHasErrors()#" abort=true); | |
} | |
if(arrayLen(orderDeliveryItems) && !StructIsEmpty(orderDelivery.getErrors())){ | |
writeLog(text="Order: #orderObj.getOrderNumber()# - Error occured processing order." file="closeOrder"); | |
arrayAppend(result, "Order: #orderObj.getOrderNumber()# - Error occured processing order."); | |
writeDump(var="#orderDelivery.getErrors()#" abort=true); | |
}else { | |
// Set order status as closed. | |
type = entityLoad("SlatwallType",{systemCode="ostClosed"},true); | |
orderObj.setOrderStatusType(type); | |
arrayAppend(result, "Order: #orderObj.getOrderNumber()# - successfully processed."); | |
writeLog(text="Order: #orderObj.getOrderNumber()# - successfully processed." file="closeOrder"); | |
} | |
} | |
} | |
} | |
} | |
} else { | |
arrayAppend(result, "Order: #orderObj.getOrderNumber()# - is invalid."); | |
writeLog(text="Order: #orderObj.getOrderNumber()# - is invalid." file="closeOrder"); | |
//return rc.result | |
} | |
rc.result = result; | |
return rc.result; | |
// getFW().redirect(action="admin:main"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
This file belongs in the integration views directory. | |
---> | |
<cfoutput> | |
<cfif structKeyExists(rc, "result")> | |
<p>#rc.result#</p> | |
<cfelse> | |
<p>Something has went wrong...</p> | |
</cfif> | |
</cfoutput> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment