Inventory Management not working when order cancelled
I have setup simple inventory management and have successfuly got this to work when checkout is complete.
I have added the pipeline tasks for ToCancelled as below however the Inventory isnt being incremented when I cancel. Anyone got any ideas why this may not be working:
The productdefinitionField it's looking for in the task is "InventoryOnHand". Is your inventory property called that ? Does it work when it is decreasing inventory on hand on checkout as it is supposed to do?
I just made the same task you describe for a client.
This i how i made it:
The pipeline
public class InventoryIncrease : IPipelineTask<UCommerce.EntitiesV2.PurchaseOrder>
{
public PipelineExecutionResult Execute(PurchaseOrder order)
{
//Call on order cancel
PipelineLogic.ChangeInventoryStatus(order,false);
return PipelineExecutionResult.Success;
}
}
The pipeline logic:
internal static void ChangeInventoryStatus(PurchaseOrder order, bool decrease = true)
{
const string inventoryOnHandAlias = "InventoryOnHand";
foreach (var orderLine in order.OrderLines)
{
Product product = null;
//Fetch product or definition
product = !string.IsNullOrEmpty(orderLine.VariantSku) ? Product.FirstOrDefault(x => x.VariantSku == orderLine.VariantSku) : Product.FirstOrDefault(x => x.Sku == orderLine.Sku);
//Check if alias is on the product
if (!product.IsVariant && product.ProductDefinition.ProductDefinitionFields.Any(x => x.Name == inventoryOnHandAlias)
|| product.IsVariant && product.ProductDefinition.ProductDefinitionFields.Any(x => x.Name == inventoryOnHandAlias && x.IsVariantProperty))
{
var rawStockValue = product.GetProperty(inventoryOnHandAlias).GetValue().ToString();
var parsedStockValue = 0;
var converted = int.TryParse(rawStockValue, out parsedStockValue);
if (converted)
{
if (decrease)
{
product.GetProperty(inventoryOnHandAlias).SetValue(parsedStockValue - orderLine.Quantity);
}
else
{
product.GetProperty(inventoryOnHandAlias).SetValue(parsedStockValue + orderLine.Quantity);
}
product.Save();
}
}
}
}
There's built-in support for that. At least in 3.0
UCommerce.Pipelines.Common.InventoryTask does the trick well. And as you have registered, there's also tasks built-in for both calling it with increase and decrease. The question is weather it works also on Increase. And that you've configured it the right way using InventoryOnHand property.
dicking deeper into it, it actually looks like it's been around since 1.1.1.0 :) It also states that you only need to add a product definition field and your'e good to go.
<configuration> <components> <!-- Pipeline Instance --> <component id="ToCancelled" service="UCommerce.Pipelines.IPipeline`1[[UCommerce.EntitiesV2.PurchaseOrder, UCommerce]], UCommerce" type="UCommerce.Pipelines.OrderProcessing.OrderProcessingPipeline, UCommerce.Pipelines"> <parameters> <tasks> <array> <!-- Payment processing vendors ussually require additional subscription fees for you to be able to access their API. Please consult your agreement to see if API access is supported for your particular plan. --> <!--<value>${ToCancelled.CancelPaymentTask}</value>--> <value>${ToCancelled.IncrementInventoryOnHand}</value> </array> </tasks> </parameters> </component>
Inventory Management not working when order cancelled
I have setup simple inventory management and have successfuly got this to work when checkout is complete.
I have added the pipeline tasks for ToCancelled as below however the Inventory isnt being incremented when I cancel. Anyone got any ideas why this may not be working:
<value>${ToCancelled.IncrementInventoryOnHand}</value>
<component id="ToCancelled.IncrementInventoryOnHand"
service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.EntitiesV2.PurchaseOrder, UCommerce]], UCommerce"
type="UCommerce.Pipelines.OrderProcessing.IncrementInventoryOnHandTask, UCommerce.Pipelines" />
What kind of error do you get in the umbraco log?
Hi Nickolaj,
Not getting any error in umbracoLog for this step.
Cheers,
Marc
The productdefinitionField it's looking for in the task is "InventoryOnHand". Is your inventory property called that ? Does it work when it is decreasing inventory on hand on checkout as it is supposed to do?
I just made the same task you describe for a client.
This i how i made it:
The pipeline
The pipeline logic:
And the ToCancelled.config
Hope this helps you out :)
There's built-in support for that. At least in 3.0
UCommerce.Pipelines.Common.InventoryTask does the trick well. And as you have registered, there's also tasks built-in for both calling it with increase and decrease. The question is weather it works also on Increase. And that you've configured it the right way using InventoryOnHand property.
Great info Morten - didn't notice the new pipelinetasks in 3.0.
I'll have a look in dotPeak and see if it does everything I need it to do :)
dicking deeper into it, it actually looks like it's been around since 1.1.1.0 :) It also states that you only need to add a product definition field and your'e good to go.
http://ucommerce.dk/en/support/release-notes.aspx
Hi Morten,
I have the "InventoryOnHand" property setup and the decrement is working on checkout. When I cancel an order the increment isnt working.
Any ideas?
Cheers,
Marc
And the toCancelled pipeline are running as it should ?
Sounds strange. What uCommerce version are you running on ?
Hi Morten, using 3.0, not sure where to look to see why this is not working. Everything seems to be setup correctly and not receiving any errors.
Cheers,
Marc
Can you please try to paste your entire ToCancelled.config file here :)
<configuration>
<components>
<!-- Pipeline Instance -->
<component id="ToCancelled"
service="UCommerce.Pipelines.IPipeline`1[[UCommerce.EntitiesV2.PurchaseOrder, UCommerce]], UCommerce"
type="UCommerce.Pipelines.OrderProcessing.OrderProcessingPipeline, UCommerce.Pipelines">
<parameters>
<tasks>
<array>
<!--
Payment processing vendors ussually require additional subscription fees for you to be able to access their API.
Please consult your agreement to see if API access is supported for your particular plan.
-->
<!--<value>${ToCancelled.CancelPaymentTask}</value>-->
<value>${ToCancelled.IncrementInventoryOnHand}</value>
</array>
</tasks>
</parameters>
</component>
<!-- Pipeline Tasks-->
<component id="ToCancelled.CancelPaymentTask"
service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.EntitiesV2.PurchaseOrder, UCommerce]], UCommerce"
type="UCommerce.Pipelines.OrderProcessing.CancelPaymentTask, UCommerce.Pipelines" />
<component id="ToCancelled.IncrementInventoryOnHand"
service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.EntitiesV2.PurchaseOrder, UCommerce]], UCommerce"
type="UCommerce.Pipelines.OrderProcessing.IncrementInventoryOnHandTask, UCommerce.Pipelines" />
</components>
</configuration>
First of all.
You do know that <value>${ToCancelled.CancelPaymentTask}</value> are not run because it is outcommented right?
AHHHHHHHHHHHHHH, jesus, never noticed.
Cheers, Morten
No problem. Did it also solve the increament issue ?
Hi Morten, thats it sorted thanks for the extra pair of eyes.
Glad to help out :)
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.