Skip to content

Instantly share code, notes, and snippets.

@devinsays
Last active October 4, 2022 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devinsays/b8b984b5009e426b02cd238d8e0f8505 to your computer and use it in GitHub Desktop.
Save devinsays/b8b984b5009e426b02cd238d8e0f8505 to your computer and use it in GitHub Desktop.
Fulfil channel logic
<?php
/**
* Determine which Fulfil channel ID to use based on order type, source.
*
* @param Order $order Order to check
*
* @return mixed
*/
public static function getChannelId(Order $order)
{
// Set a default channel of channel_subbox_main for all orders.
$channelId = config('fulfil.channel_subbox_main');
// If it's a shop order, we use channel_shop_main.
if (Order::isSingleSale($order)) {
$channelId = config('fulfil.channel_shop_main');
}
// If it's a support order we use channel_subbox_support or channel_shop_support.
// We can return these right away since there won't be any additional logic to override.
$useSupportChannel = false;
if (Order::isSupportOrder($order) ||
// These are for support orders created via the bulk tool.
// We need to verify if there is an actual use case for this.
'customer_support' === $order->order_type ||
// The support channel is just used as an accounting catchall for other marketing orders.
'other_marketing' === $order->order_type
) {
$useSupportChannel = true;
}
if ($useSupportChannel) {
if (config('yums.support_line_shop') === $order->business_line) {
return config('fulfil.channel_shop_support');
}
return config('fulfil.channel_subbox_support');
}
// Affiliate marketing order.
if ('affiliate' === $order->order_type) {
return config('fulfil.channel_affiliate');
}
// Influencer marketing order.
if ('influencer' === $order->order_type) {
return config('fulfil.channel_influencer');
}
// If it's a renewal and hasn't already returned, use channel_subbox_renewal.
if (Order::isRenewalOrder($order->type)) {
return config('fulfil.channel_subbox_renewal');
}
return $channelId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment