| <?php |
| <?php |
| |
| |
| namespace App\Http\Controllers; |
| namespace App\Http\Controllers; |
| header("Access-Control-Allow-Origin: *"); |
| header("Access-Control-Allow-Origin: *"); |
| |
| |
| use App\Http\Requests\OrderValidation; |
| use App\Http\Requests\OrderValidation; |
| use Illuminate\Http\Request; |
| use Illuminate\Http\Request; |
| use App\Model\Shopify\Product; |
| use App\Model\Shopify\Product; |
| use App\Model\IterableModel; |
| use App\Model\IterableModel; |
| use OhMyBrew\BasicShopifyAPI; |
| use OhMyBrew\BasicShopifyAPI; |
| use Config; |
| use Config; |
| use stdClass; |
| use stdClass; |
| |
| |
| class OrderController extends Controller { |
| class OrderController extends Controller { |
| |
| |
| private $productObj; |
| private $productObj; |
| private $shopifyApi; |
| private $shopifyApi; |
| private $iterableObj; |
| private $iterableObj; |
| private $shProductDetails = []; |
| private $shProductDetails = []; |
| private $shopify_api_version; |
| private $shopify_api_version; |
| |
| |
| /** |
| /** |
| * Create a new controller instance. |
| * Create a new controller instance. |
| * |
| * |
| * @return void |
| * @return void |
| */ |
| */ |
| public function __construct() { |
| public function __construct() { |
| $this->productObj = new Product(); |
| $this->productObj = new Product(); |
| $this->iterableObj = new IterableModel(); |
| $this->iterableObj = new IterableModel(); |
| $this->shopifyApi = new BasicShopifyAPI(); |
| $this->shopifyApi = new BasicShopifyAPI(); |
. | //$password = Config::get('shopify.password'); |
| $password = Config::get('shopify.passwordOrder'); |
| $passwords = ['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']; |
| $shopDomain = Config::get('shopify.shopDomainOrder'); |
| shuffle($passwords); |
| |
| $password = $passwords[0]; |
| |
| $shopDomain = Config::get('shopify.shopDomain'); |
| |
| $this->shopifyApi->setShop($shopDomain); |
| $this->shopifyApi->setShop($shopDomain); |
| $this->shopifyApi->setAccessToken($password); |
| $this->shopifyApi->setAccessToken($password); |
| $this->shopify_api_version = env('SHOPIFY_API_VERSION', true); |
| $this->shopify_api_version = env('SHOPIFY_API_VERSION', true); |
| } |
| } |
| |
| |
| // To store the order in shopify |
| // To store the order in shopify |
| public function saveOrder() { |
| public function saveOrder() { |
| |
| |
| $message = "Endpoint parameters are missing"; |
| $message = "Endpoint parameters are missing"; |
| $status = "Failed"; |
| $status = "Failed"; |
| |
| |
| if (empty($_REQUEST['data'])){ |
| if (empty($_REQUEST['data'])){ |
| $response = array( |
| $response = array( |
| 'status' => $status, |
| 'status' => $status, |
| 'errorMessage' => $message, |
| 'errorMessage' => $message, |
| ); |
| ); |
| echo json_encode($response); |
| echo json_encode($response); |
| die(); |
| die(); |
| } else { |
| } else { |
| $data = json_decode($_REQUEST['data'],true); |
| $data = json_decode($_REQUEST['data'],true); |
| $lineItemStatus = 0; |
| $lineItemStatus = 0; |
| $shippingStatus = 0; |
| $shippingStatus = 0; |
| if (empty($data['order']['email']) || empty($data['order']['product_id']) || |
| if (empty($data['order']['email']) || empty($data['order']['product_id']) || |
| empty($data['order']['variant_id'])){ |
| empty($data['order']['variant_id'])){ |
| $response = array( |
| $response = array( |
| 'status' => $status, |
| 'status' => $status, |
| 'errorMessage' => $message, |
| 'errorMessage' => $message, |
| ); |
| ); |
| echo $_REQUEST['callback'] . '(' . json_encode($response) . ')'; |
| echo $_REQUEST['callback'] . '(' . json_encode($response) . ')'; |
| die(); |
| die(); |
| } else { |
| } else { |
| |
| |
| if (isset($data['order']['line_items'])){ |
| if (isset($data['order']['line_items'])){ |
| foreach ($data['order']['line_items'] as $lineItems){ |
| foreach ($data['order']['line_items'] as $lineItems){ |
| if ((empty($lineItems['variant_id']) || empty($lineItems['product_id']) || |
| if ((empty($lineItems['variant_id']) || empty($lineItems['product_id']) || |
| empty($lineItems['name']) || empty($lineItems['value'])) && empty($lineItems['utm'])){ |
| empty($lineItems['name']) || empty($lineItems['value'])) && empty($lineItems['utm'])){ |
| $lineItemStatus = 1; |
| $lineItemStatus = 1; |
| } |
| } |
| } |
| } |
| } else { |
| } else { |
| $lineItemStatus = 1; |
| $lineItemStatus = 1; |
| } |
| } |
| |
| |
| if (empty($data['order']['line_items']) || $lineItemStatus == 1){ |
| if (empty($data['order']['line_items']) || $lineItemStatus == 1){ |
| $response = array( |
| $response = array( |
| 'status' => 'Failed', |
| 'status' => 'Failed', |
| 'errorMessage' => 'Missing required parameters in the line item properties', |
| 'errorMessage' => 'Missing required parameters in the line item properties', |
| ); |
| ); |
| echo $_REQUEST['callback'] . '(' . json_encode($response) . ')'; |
| echo $_REQUEST['callback'] . '(' . json_encode($response) . ')'; |
| die(); |
| die(); |
| } |
| } |
| |
| |
| if (!empty($data['order']['shipping_address'])){ |
| if (!empty($data['order']['shipping_address'])){ |
| $shippingaddress = $data['order']['shipping_address']; |
| $shippingaddress = $data['order']['shipping_address']; |
| if(empty($shippingaddress['first_name']) || empty($shippingaddress['last_name']) || |
| if(empty($shippingaddress['first_name']) || empty($shippingaddress['last_name']) || |
| empty($shippingaddress['address1']) || empty($shippingaddress['city']) || |
| empty($shippingaddress['address1']) || empty($shippingaddress['city']) || |
| empty($shippingaddress['country']) || empty($shippingaddress['state'])){ |
| empty($shippingaddress['country']) || empty($shippingaddress['state'])){ |
| $shippingStatus = 1; |
| $shippingStatus = 1; |
| } |
| } |
| } else { |
| } else { |
| $shippingStatus = 1; |
| $shippingStatus = 1; |
| } |
| } |
| |
| |
| if ($shippingStatus == 1){ |
| if ($shippingStatus == 1){ |
| $response = array( |
| $response = array( |
| 'status' => 'Failed', |
| 'status' => 'Failed', |
| 'errorMessage' => 'Missing required parameters in the Shipping Address', |
| 'errorMessage' => 'Missing required parameters in the Shipping Address', |
| ); |
| ); |
| echo $_REQUEST['callback'] . '(' . json_encode($response) . ')'; |
| echo $_REQUEST['callback'] . '(' . json_encode($response) . ')'; |
| die(); |
| die(); |
| } |
| } |
| |
| |
| } |
| } |
| |
| |
| } |
| } |
| |
| |
| $requestData = json_decode($_REQUEST['data'],true); |
| $requestData = json_decode($_REQUEST['data'],true); |
| $setOrderRequest = $this->setOrderRequest($requestData); |
| $setOrderRequest = $this->setOrderRequest($requestData); |
| $params['order'] = $setOrderRequest; |
| $params['order'] = $setOrderRequest; |
| $result = $this->shopifyApi->rest('POST', htmlentities('/admin/api/'.$this->shopify_api_version.'/orders.json'), $params); |
| $result = $this->shopifyApi->rest('POST', htmlentities('/admin/api/'.$this->shopify_api_version.'/orders.json'), $params); |
| |
| |
| if ($result->errors){ |
| if ($result->errors){ |
| $response = array( |
| $response = array( |
| 'status' => $status, |
| 'status' => $status, |
| 'errorMessage' => $result->errors, |
| 'errorMessage' => $result->errors, |
| ); |
| ); |
| echo $_REQUEST['callback'] . '(' . json_encode($response) . ')'; |
| echo $_REQUEST['callback'] . '(' . json_encode($response) . ')'; |
| die(); |
| die(); |
| } else { |
| } else { |
| if(!empty($requestData['order']['newsletter']) && |
| if(!empty($requestData['order']['newsletter']) && |
| !empty($requestData['order']['email'])) { |
| !empty($requestData['order']['email'])) { |
| |
| |
| $emailAddress = trim($requestData['order']['email']); |
| $emailAddress = trim($requestData['order']['email']); |
| $checkOutStatus = trim($requestData['order']['newsletter']); |
| $checkOutStatus = trim($requestData['order']['newsletter']); |
| $preferenceIds = env('INFLUENCER_PREFERENCE_IDS',true); |
| $preferenceIds = env('INFLUENCER_PREFERENCE_IDS',true); |
| $preferenceIdsExplode = explode(",",$preferenceIds); |
| $preferenceIdsExplode = explode(",",$preferenceIds); |
| |
| |
| $channelIds = env('INFLUENCER_CHANNEL_IDS',true); |
| $channelIds = env('INFLUENCER_CHANNEL_IDS',true); |
| $channelIdsExplode = explode(",",$channelIds); |
| $channelIdsExplode = explode(",",$channelIds); |
| |
| |
| $iterableSubscriptionDetails = $this->iterableObj->getIterableSubscription($emailAddress); |
| $iterableSubscriptionDetails = $this->iterableObj->getIterableSubscription($emailAddress); |
| |
| |
| $iterableSubscriptionDetails = (array)$iterableSubscriptionDetails; |
| $iterableSubscriptionDetails = (array)$iterableSubscriptionDetails; |
| //print_r($iterableSubscriptionDetails); die; |
| //print_r($iterableSubscriptionDetails); die; |
| if(isset($iterableSubscriptionDetails['user'])) { |
| if(isset($iterableSubscriptionDetails['user'])) { |
| |
| |
| $unsubscribedChannelIds = !empty($iterableSubscriptionDetails['user'] |
| $unsubscribedChannelIds = !empty($iterableSubscriptionDetails['user'] |
| ->dataFields->unsubscribedChannelIds) ? $iterableSubscriptionDetails['user'] |
| ->dataFields->unsubscribedChannelIds) ? $iterableSubscriptionDetails['user'] |
| ->dataFields->unsubscribedChannelIds : ''; |
| ->dataFields->unsubscribedChannelIds : ''; |
| |
| |
| $unsubscribedMessageTypeIds = !empty($iterableSubscriptionDetails['user'] |
| $unsubscribedMessageTypeIds = !empty($iterableSubscriptionDetails['user'] |
| ->dataFields->unsubscribedMessageTypeIds) ? $iterableSubscriptionDetails['user'] |
| ->dataFields->unsubscribedMessageTypeIds) ? $iterableSubscriptionDetails['user'] |
| ->dataFields->unsubscribedMessageTypeIds : ''; |
| ->dataFields->unsubscribedMessageTypeIds : ''; |
| |
| |
| $subscribedMessageTypeIds = !empty($iterableSubscriptionDetails['user'] |
| $subscribedMessageTypeIds = !empty($iterableSubscriptionDetails['user'] |
| ->dataFields->subscribedMessageTypeIds) ? $iterableSubscriptionDetails['user'] |
| ->dataFields->subscribedMessageTypeIds) ? $iterableSubscriptionDetails['user'] |
| ->dataFields->subscribedMessageTypeIds : ''; |
| ->dataFields->subscribedMessageTypeIds : ''; |
| |
| |
| $newUnsubscribedChannelIds = []; |
| $newUnsubscribedChannelIds = []; |
| $newUnsubscribedMessageTypeId = []; |
| $newUnsubscribedMessageTypeId = []; |
| $newSubscribedMessageTypeIds = []; |
| $newSubscribedMessageTypeIds = []; |
| |
| |
| if ($checkOutStatus == 'true') { |
| if ($checkOutStatus == 'true') { |
| |
| |
| if (!empty($unsubscribedChannelIds)) { |
| if (!empty($unsubscribedChannelIds)) { |
| $newUnsubscribedChannelIds = array_diff($unsubscribedChannelIds, (is_array($channelIdsExplode) ? |
| $newUnsubscribedChannelIds = array_diff($unsubscribedChannelIds, (is_array($channelIdsExplode) ? |
| $channelIdsExplode : array($channelIdsExplode))); |
| $channelIdsExplode : array($channelIdsExplode))); |
| } else { |
| } else { |
| $newUnsubscribedChannelIds = []; |
| $newUnsubscribedChannelIds = []; |
| } |
| } |
| |
| |
| if (!empty($unsubscribedMessageTypeIds)) { |
| if (!empty($unsubscribedMessageTypeIds)) { |
| $newUnsubscribedMessageTypeIds = array_diff($unsubscribedMessageTypeIds, (is_array($preferenceIdsExplode) ? |
| $newUnsubscribedMessageTypeIds = array_diff($unsubscribedMessageTypeIds, (is_array($preferenceIdsExplode) ? |
| $preferenceIdsExplode : array($preferenceIdsExplode))); |
| $preferenceIdsExplode : array($preferenceIdsExplode))); |
| } else { |
| } else { |
| $newUnsubscribedMessageTypeIds = []; |
| $newUnsubscribedMessageTypeIds = []; |
| } |
| } |
| |
| |
| if(!empty($subscribedMessageTypeIds)) { |
| if(!empty($subscribedMessageTypeIds)) { |
| $newSubscribedMessageTypeIds = $subscribedMessageTypeIds; |
| $newSubscribedMessageTypeIds = $subscribedMessageTypeIds; |
| } |
| } |
| for ($i=0; $i < count($preferenceIdsExplode) ; $i++) { |
| for ($i=0; $i < count($preferenceIdsExplode) ; $i++) { |
| |
| |
| $newSubscribedMessageTypeIds[] = $preferenceIdsExplode[$i]; |
| $newSubscribedMessageTypeIds[] = $preferenceIdsExplode[$i]; |
| } |
| } |
| $newSubscribedMessageTypeIds = array_unique($newSubscribedMessageTypeIds); |
| $newSubscribedMessageTypeIds = array_unique($newSubscribedMessageTypeIds); |
| |
| |
| } elseif($checkOutStatus == 'false') { |
| } elseif($checkOutStatus == 'false') { |
| |
| |
| $newUnsubscribedChannelIds = !empty($unsubscribedChannelIds) ? $unsubscribedChannelIds : []; |
| $newUnsubscribedChannelIds = !empty($unsubscribedChannelIds) ? $unsubscribedChannelIds : []; |
| |
| |
| |
| |
| if (!empty($unsubscribedMessageTypeIds)) { |
| if (!empty($unsubscribedMessageTypeIds)) { |
| |
| |
| $newUnsubscribedMessageTypeIds = $unsubscribedMessageTypeIds; |
| $newUnsubscribedMessageTypeIds = $unsubscribedMessageTypeIds; |
| } |
| } |
| for ($i=0; $i < count($preferenceIdsExplode); $i++) { |
| for ($i=0; $i < count($preferenceIdsExplode); $i++) { |
| |
| |
| $newUnsubscribedMessageTypeIds[] = $preferenceIdsExplode[$i]; |
| $newUnsubscribedMessageTypeIds[] = $preferenceIdsExplode[$i]; |
| } |
| } |
| $newUnsubscribedMessageTypeIds = array_unique($newUnsubscribedMessageTypeIds); |
| $newUnsubscribedMessageTypeIds = array_unique($newUnsubscribedMessageTypeIds); |
| |
| |
| |
| |
| if (!empty($subscribedMessageTypeIds)) { |
| if (!empty($subscribedMessageTypeIds)) { |
| $newSubscribedMessageTypeIds = array_diff($subscribedMessageTypeIds, (is_array($preferenceIdsExplode) ? |
| $newSubscribedMessageTypeIds = array_diff($subscribedMessageTypeIds, (is_array($preferenceIdsExplode) ? |
| $preferenceIdsExplode : array($preferenceIdsExplode))); |
| $preferenceIdsExplode : array($preferenceIdsExplode))); |
| } else { |
| } else { |
| $newSubscribedMessageTypeIds = []; |
| $newSubscribedMessageTypeIds = []; |
| } |
| } |
| |
| |
| } |
| } |
| |
| |
| $updateRequest = array( |
| $updateRequest = array( |
| "email" => $emailAddress, |
| "email" => $emailAddress, |
| "unsubscribedChannelIds" => array_map('intval', $newUnsubscribedChannelIds), |
| "unsubscribedChannelIds" => array_map('intval', $newUnsubscribedChannelIds), |
| "unsubscribedMessageTypeIds" => array_map('intval', $newUnsubscribedMessageTypeIds), |
| "unsubscribedMessageTypeIds" => array_map('intval', $newUnsubscribedMessageTypeIds), |
| "subscribedMessageTypeIds" => array_map('intval', $newSubscribedMessageTypeIds) |
| "subscribedMessageTypeIds" => array_map('intval', $newSubscribedMessageTypeIds) |
| ); |
| ); |
| |
| |
| $preferenceUpdatedResponse = $this->iterableObj->updateUserIterableSubscription( |
| $preferenceUpdatedResponse = $this->iterableObj->updateUserIterableSubscription( |
| json_encode($updateRequest)); |
| json_encode($updateRequest)); |
| |
| |
| } |
| } |
| } |
| } |
| $order_details = $result->body; |
| $order_details = $result->body; |
| $response = array( |
| $response = array( |
| 'status' => 'success', |
| 'status' => 'success', |
| 'successMessage' => array('order_id' => $order_details->order->id, |
| 'successMessage' => array('order_id' => $order_details->order->id, |
| 'message' => 'Order created successfully'), |
| 'message' => 'Order created successfully'), |
| 'errorMessage' => "", |
| 'errorMessage' => "", |
| ); |
| ); |
| echo $_REQUEST['callback'] . '(' . json_encode($response) . ')'; |
| echo $_REQUEST['callback'] . '(' . json_encode($response) . ')'; |
| die(); |
| die(); |
| } |
| } |
| |
| |
| } |
| } |
| |
| |
| // To set the request for order and draft order |
| // To set the request for order and draft order |
| public function setOrderRequest($reqObj){ |
| public function setOrderRequest($reqObj){ |
| |
| |
| $customerEmail = $reqObj['order']['email']; |
| $customerEmail = $reqObj['order']['email']; |
| $request = []; |
| $request = []; |
| $lineProperties = []; |
| $lineProperties = []; |
| $prod = $this->setProductDetails(); |
| $prod = $this->setProductDetails(); |
| if (isset($reqObj['order']['line_items'])){ |
| if (isset($reqObj['order']['line_items'])){ |
| // Handling duplicate line in properties |
| // Handling duplicate line in properties |
| $rearrangeLineItems = array(); |
| $rearrangeLineItems = array(); |
| $i = 0; |
| $i = 0; |
| $j= 1; |
| $j= 1; |
| foreach ($reqObj['order']['line_items'] as $key => $itemValue){ |
| foreach ($reqObj['order']['line_items'] as $key => $itemValue){ |
| if (!isset($itemValue['utm'])){ |
| if (!isset($itemValue['utm'])){ |
| if (isset($rearrangeLineItems[$itemValue['variant_id']])){ |
| if (isset($rearrangeLineItems[$itemValue['variant_id']])){ |
| $rearrangeLineItems[$itemValue['variant_id']]['quantity'] += |
| $rearrangeLineItems[$itemValue['variant_id']]['quantity'] += |
| $itemValue['quantity']; |
| $itemValue['quantity']; |
| } else { |
| } else { |
| $itemValue['name'] = 'Vitamin'.($j<10? '0'.$j++:$j++); |
| $itemValue['name'] = 'Vitamin'.($j<10? '0'.$j++:$j++); |
| $rearrangeLineItems[$itemValue['variant_id']] = $itemValue; |
| $rearrangeLineItems[$itemValue['variant_id']] = $itemValue; |
| } |
| } |
| } else { |
| } else { |
| $rearrangeLineItems['utm'] = $itemValue; |
| $rearrangeLineItems['utm'] = $itemValue; |
| } |
| } |
| $i++; |
| $i++; |
| } |
| } |
| if(isset($reqObj['order']['Pack'])){ |
| if(isset($reqObj['order']['Pack'])){ |
| $rearrangeLineItems['packs'] = array('packs' => $reqObj['order']['Pack']); |
| $rearrangeLineItems['packs'] = array('packs' => $reqObj['order']['Pack']); |
| } |
| } |
| // print_r($rearrangeLineItems); die; |
| // print_r($rearrangeLineItems); die; |
| unset($reqObj['order']['line_items']); |
| unset($reqObj['order']['line_items']); |
| $reqObj['order']['line_items'] = array_values($rearrangeLineItems); |
| $reqObj['order']['line_items'] = array_values($rearrangeLineItems); |
| |
| |
| $totalPrice = 0; |
| $totalPrice = 0; |
| foreach ($reqObj['order']['line_items'] as $key => $itemValue){ |
| foreach ($reqObj['order']['line_items'] as $key => $itemValue){ |
| $propertyValue = ''; |
| $propertyValue = ''; |
| if (!isset($itemValue['utm']) && !isset($itemValue['packs'])){ |
| if (!isset($itemValue['utm']) && !isset($itemValue['packs'])){ |
| |
| |
| $productId = $itemValue['product_id']; |
| $productId = $itemValue['product_id']; |
| $variantId = $itemValue['variant_id']; |
| $variantId = $itemValue['variant_id']; |
| if (isset($prod['products'][$productId]) && isset($prod['products'] |
| if (isset($prod['products'][$productId]) && isset($prod['products'] |
| [$productId]['variants'][$variantId])){ |
| [$productId]['variants'][$variantId])){ |
| $variantData = $prod['products'][$productId]['variants'][$variantId]; |
| $variantData = $prod['products'][$productId]['variants'][$variantId]; |
| $lineItemDosage = !empty($itemValue['dosage']) ? $itemValue['dosage'] : 'default title'; |
| $lineItemDosage = !empty($itemValue['dosage']) ? $itemValue['dosage'] : 'default title'; |
| $propertyValue .= $itemValue['value'].' | '.$lineItemDosage.' | ' |
| $propertyValue .= $itemValue['value'].' | '.$lineItemDosage.' | ' |
| .$itemValue['quantity'].' | '.$itemValue['variant_id'].' | '.$variantData['sku']; |
| .$itemValue['quantity'].' | '.$itemValue['variant_id'].' | '.$variantData['sku']; |
| $lineProperties[] = ['name' => $itemValue['name'],'value' => $propertyValue]; |
| $lineProperties[] = ['name' => $itemValue['name'],'value' => $propertyValue]; |
| $lineItemQuantity = !empty($itemValue['quantity']) ? $itemValue['quantity'] : '1'; |
| $lineItemQuantity = !empty($itemValue['quantity']) ? $itemValue['quantity'] : '1'; |
| $totalPrice += $lineItemQuantity * $variantData['price']; |
| $totalPrice += $lineItemQuantity * $variantData['price']; |
| } |
| } |
| } else if (isset($itemValue['utm'])){ |
| } else if (isset($itemValue['utm'])){ |
| $lineProperties[] = ['name'=> 'utm','value'=> $itemValue['utm']]; |
| $lineProperties[] = ['name'=> 'utm','value'=> $itemValue['utm']]; |
| } else if (isset($itemValue['packs'])){ |
| } else if (isset($itemValue['packs'])){ |
| $lineProperties[] = ['name'=> 'Packs','value'=> $itemValue['packs']]; |
| $lineProperties[] = ['name'=> 'Packs','value'=> $itemValue['packs']]; |
| } |
| } |
| |
| |
| } |
| } |
| } |
| } |
. | $result_data = $this->shopifyApi->rest('GET', |
| $result_data = $this->shopifyApi->rest('GET', |
| '/admin/api/'.$this->shopify_api_version.'/customers/search.json',["query" =>"email:".$customerEmail, "fields" => |
| '/admin/api/'.$this->shopify_api_version.'/customers/search.json',["query" =>"email:".$customerEmail, "fields" => |
| "id,email,first_name,tags"]); |
| "id,email,first_name,tags"]); |
| $tag = !empty($result_data->body->customers[0]->tags) ? $result_data->body->customers[0]->tags : ''; |
| $tag = !empty($result_data->body->customers[0]->tags) ? $result_data->body->customers[0]->tags : ''; |
| |
| |
. | if(!empty($tag) || isset($tag)) { |
| if(!empty($tag) || isset($tag)) { |
| $tag = $tag.' ,VIP'; |
| $tag = $tag.' ,VIP'; |
| } else { |
| } else { |
| $tag = 'VIP'; |
| $tag = 'VIP'; |
| } |
| } |
| |
| $shippingAddress = $reqObj['order']['shipping_address']; |
| $shippingAddress = $reqObj['order']['shipping_address']; |
| $request['customer']['first_name'] = $shippingAddress['first_name']; |
| $request['customer']['first_name'] = $shippingAddress['first_name']; |
| $request['customer']['last_name'] = $shippingAddress['last_name']; |
| $request['customer']['last_name'] = $shippingAddress['last_name']; |
| $request['customer']['email'] = $reqObj['order']['email']; |
| $request['customer']['email'] = $reqObj['order']['email']; |
| $request['customer']['tags'] = $tag; |
| $request['customer']['tags'] = $tag; |
| $request['email'] = $reqObj['order']['email']; |
| $request['email'] = $reqObj['order']['email']; |
| $request['tags'] = 'VIP'; |
| $request['tags'] = 'VIP'; |
| $request['line_items'] = array( |
| $request['line_items'] = array( |
| array( |
| array( |
| 'title' => "Your Monthly Subscription (Ships every 7 Days)", |
| 'title' => "Your Monthly Subscription (Ships every 7 Days)", |
| 'product_id' => $reqObj['order']['product_id'], |
| 'product_id' => $reqObj['order']['product_id'], |
| 'variant_id' => $reqObj['order']['variant_id'], |
| 'variant_id' => $reqObj['order']['variant_id'], |
| 'quantity' => !empty($reqObj['order']['quantity']) ? |
| 'quantity' => !empty($reqObj['order']['quantity']) ? |
| $reqObj['order']['quantity'] : '1', |
| $reqObj['order']['quantity'] : '1', |
| 'price' => $totalPrice, |
| 'price' => $totalPrice, |
| 'properties' => $lineProperties |
| 'properties' => $lineProperties |
| ) |
| ) |
| ); |
| ); |
| |
| |
| $request['shipping_address'] = array( |
| $request['shipping_address'] = array( |
| "address1" => $shippingAddress['address1'], |
| "address1" => $shippingAddress['address1'], |
| "address2" => $shippingAddress['address2'], |
| "address2" => $shippingAddress['address2'], |
| "city" => $shippingAddress['city'], |
| "city" => $shippingAddress['city'], |
| "country" => $shippingAddress['country'], |
| "country" => $shippingAddress['country'], |
| "first_name"=> $shippingAddress['first_name'], |
| "first_name"=> $shippingAddress['first_name'], |
| "last_name" => $shippingAddress['last_name'], |
| "last_name" => $shippingAddress['last_name'], |
| "province" => $shippingAddress['state'], |
| "province" => $shippingAddress['state'], |
| "zip" => $shippingAddress['zip'], |
| "zip" => $shippingAddress['zip'], |
| "phone" => $shippingAddress['phone'], |
| "phone" => $shippingAddress['phone'], |
| ); |
| ); |
| $request['send_receipt'] = true; |
| $request['send_receipt'] = true; |
| |
| return $request; |
| return $request; |
| } |
| } |
| |
| |
| /** |
| /** |
| * To set the shopify product details |
| * To set the shopify product details |
| */ |
| */ |
| public function setProductDetails() { |
| public function setProductDetails() { |
| |
| |
| $shopifyVariants = []; |
| $shopifyVariants = []; |
| $shopifyProducts['products'] = []; |
| $shopifyProducts['products'] = []; |
| $limit = 50; |
| $limit = 50; |
| $nextLink = ''; |
| $nextLink = ''; |
| $previousLink = ''; |
| $previousLink = ''; |
| |
| |
| do { |
| do { |
| |
| |
| try{ |
| try{ |
| |
| |
| if(empty($previousLink) && empty($nextLink)) { |
| if(empty($previousLink) && empty($nextLink)) { |
| |
| |
| $productDetails =$this->shopifyApi->rest('GET', |
| $productDetails =$this->shopifyApi->rest('GET', |
| '/admin/api/'.$this->shopify_api_version.'/products.json',["published_status" => "published", "fields" => |
| '/admin/api/'.$this->shopify_api_version.'/products.json',["published_status" => "published", "fields" => |
| "id,title,variants", "limit" => $limit]); |
| "id,title,variants", "limit" => $limit]); |
| $previousLink = !empty($productDetails->link->previous) ? |
| $previousLink = !empty($productDetails->link->previous) ? |
| $productDetails->link->previous : ''; |
| $productDetails->link->previous : ''; |
| $nextLink = !empty($productDetails->link->next) ? |
| $nextLink = !empty($productDetails->link->next) ? |
| $productDetails->link->next : ''; |
| $productDetails->link->next : ''; |
| |
| |
| }elseif(!empty($nextLink)) { |
| }elseif(!empty($nextLink)) { |
| |
| |
| $params = ["fields" => "id,title,variants", "limit" => $limit, |
| $params = ["fields" => "id,title,variants", "limit" => $limit, |
| 'page_info' => $nextLink]; |
| 'page_info' => $nextLink]; |
| $productDetails = $this->shopifyApi->rest('GET', '/admin/api/'.$this->shopify_api_version.'/products.json',$params); |
| $productDetails = $this->shopifyApi->rest('GET', '/admin/api/'.$this->shopify_api_version.'/products.json',$params); |
| $previousLink = !empty($productDetails->link->previous) ? |
| $previousLink = !empty($productDetails->link->previous) ? |
| $productDetails->link->previous : ''; |
| $productDetails->link->previous : ''; |
| $nextLink = !empty($productDetails->link->next) ? |
| $nextLink = !empty($productDetails->link->next) ? |
| $productDetails->link->next : ''; |
| $productDetails->link->next : ''; |
| } |
| } |
| } catch(Exception $e) { |
| } catch(Exception $e) { |
| echo PHP_EOL."Error when fetching the products from shopify and the error is - " |
| echo PHP_EOL."Error when fetching the products from shopify and the error is - " |
| .$e->getMessage(); |
| .$e->getMessage(); |
| die; |
| die; |
| } |
| } |
| |
| |
| $productDetails = $productDetails->body; |
| $productDetails = $productDetails->body; |
| |
| |
| if (!empty($productDetails)) { |
| if (!empty($productDetails)) { |
| |
| |
| $subscription_product = array('1809168695367','4359186350162'); |
| $subscription_product = array('1809168695367','4359186350162'); |
| |
| |
| foreach ($productDetails->products as $products) { |
| foreach ($productDetails->products as $products) { |
| if(in_array($products->id,$subscription_product)){ |
| if(in_array($products->id,$subscription_product)){ |
| continue; |
| continue; |
| } |
| } |
| |
| |
| |
| |
| foreach ($products->variants as $variants) { |
| foreach ($products->variants as $variants) { |
| |
| |
| $shopifyVariants[$variants->id] = [ |
| $shopifyVariants[$variants->id] = [ |
| 'id' => $variants->id , |
| 'id' => $variants->id , |
| 'product_id' => $variants->product_id, |
| 'product_id' => $variants->product_id, |
| 'title' => $variants->title, |
| 'title' => $variants->title, |
| 'sku' => $variants->sku, |
| 'sku' => $variants->sku, |
| 'price' => $variants->price |
| 'price' => $variants->price |
| ]; |
| ]; |
| } |
| } |
| $shopifyProducts['products'][$products->id] = ['id'=>$products->id, |
| $shopifyProducts['products'][$products->id] = ['id'=>$products->id, |
| 'title'=>$products->title,'variants'=>$shopifyVariants]; |
| 'title'=>$products->title,'variants'=>$shopifyVariants]; |
| $shopifyVariants = []; |
| $shopifyVariants = []; |
| |
| |
| } |
| } |
| |
| |
| } |
| } |
| $count = count($productDetails->products); |
| $count = count($productDetails->products); |
| if(empty($nextLink)) { |
| if(empty($nextLink)) { |
| break; |
| break; |
| } |
| } |
| } while($limit == $count); |
| } while($limit == $count); |
| |
| |
| return $shopifyProducts; |
| return $shopifyProducts; |
| } |
| } |
| } |
| } |
| |
| |
. | ?> |
| ?> |
| |
| |