From e770f6e83417ebd1e7d5a9a449cac33269cf80f1 Mon Sep 17 00:00:00 2001 From: antu chaudhary Date: Thu, 4 Jan 2024 15:43:27 +0530 Subject: [PATCH 1/8] Update the bagisto UPS Shipping module in v2.0 --- CHANGELOG for v0.1.x.md | 15 + README.md | 58 ++- composer.json | 13 +- package.json | 23 + src/Carriers/Ups.php | 126 +++--- src/Config/carriers.php | 0 src/Config/system.php | 68 +-- src/Helpers/ShippingMethodHelper.php | 452 ++++++++++--------- src/Providers/UpsShippingServiceProvider.php | 4 + src/Repositories/UpsRepository.php | 86 ++-- src/Resources/lang/ar/app.php | 23 + src/Resources/lang/bn/app.php | 23 + src/Resources/lang/de/app.php | 23 + src/Resources/lang/en/app.php | 27 +- src/Resources/lang/es/app.php | 23 + src/Resources/lang/fa/app.php | 23 + src/Resources/lang/fr/app.php | 23 + src/Resources/lang/he/app.php | 23 + src/Resources/lang/hi_IN/app.php | 23 + src/Resources/lang/it/app.php | 23 + src/Resources/lang/ja/app.php | 23 + src/Resources/lang/nl/app.php | 23 + src/Resources/lang/pl/app.php | 23 + src/Resources/lang/pt_BR/app.php | 23 + src/Resources/lang/ru/app.php | 23 + src/Resources/lang/sin/app.php | 23 + src/Resources/lang/tr/app.php | 23 + src/Resources/lang/uk/app.php | 23 + src/Resources/lang/zh_CN/app.php | 23 + webpack.mix.js | 19 + 30 files changed, 924 insertions(+), 381 deletions(-) create mode 100644 CHANGELOG for v0.1.x.md create mode 100644 package.json mode change 100644 => 100755 src/Config/carriers.php mode change 100644 => 100755 src/Providers/UpsShippingServiceProvider.php create mode 100755 src/Resources/lang/ar/app.php create mode 100644 src/Resources/lang/bn/app.php create mode 100755 src/Resources/lang/de/app.php create mode 100755 src/Resources/lang/es/app.php create mode 100755 src/Resources/lang/fa/app.php create mode 100755 src/Resources/lang/fr/app.php create mode 100755 src/Resources/lang/he/app.php create mode 100755 src/Resources/lang/hi_IN/app.php create mode 100755 src/Resources/lang/it/app.php create mode 100755 src/Resources/lang/ja/app.php create mode 100755 src/Resources/lang/nl/app.php create mode 100755 src/Resources/lang/pl/app.php create mode 100755 src/Resources/lang/pt_BR/app.php create mode 100755 src/Resources/lang/ru/app.php create mode 100755 src/Resources/lang/sin/app.php create mode 100755 src/Resources/lang/tr/app.php create mode 100755 src/Resources/lang/uk/app.php create mode 100755 src/Resources/lang/zh_CN/app.php create mode 100644 webpack.mix.js diff --git a/CHANGELOG for v0.1.x.md b/CHANGELOG for v0.1.x.md new file mode 100644 index 0000000..04aaf35 --- /dev/null +++ b/CHANGELOG for v0.1.x.md @@ -0,0 +1,15 @@ +# CHANGELOG for v0.1.x + +#### This changelog consists the bug & security fixes and new features being included in the releases listed below. + +## **v0.1.0(23 of Feb, 2020)** - *Release* + +* [feature] The admin can enable or disable the usps Shipping method. + +* [feature] The admin can set the ups shipping method name that will be shown from the front side. + +* [feature] The admin can define the allowed methods and weight units. + +* [feature] The admin can set packaging type and drop off type. + +* [feature] Dynamic shipping method for freight calculation. \ No newline at end of file diff --git a/README.md b/README.md index 04d956b..c03a9a1 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,55 @@ -# Introduction +### 1. Introduction: -Bagisto UPS Shipping add-on provides UPS Shipping methods for shipping the product. By using this, you can provide UPS (United Parcel Service) shipping. +UPS Shipping module provides UPS Shipping methods for shipping the product. By using this, you can provide UPS (United Parcel Service) shipping. UPS is widely acknowledged as a world-class company and now it is with the Bagisto. +This module works with the Bagisto core Package. To use this module you must have installed Bagisto. It packs in lots of demanding features that allows your business to scale in no time: -- The admin can enable or disable the UPS Shipping method. +* The admin can enable or disable the UPS Shipping method. -- The admin can set the UPS shipping method name that will be shown from the front side. +* The admin can set the UPS shipping method name that will be shown from the front side. -- The admin can define the allowed methods and weight units. +* The admin can define the allowed methods and weight units. -- Dynamic shipping method for freight calculation. +* Dynamic shipping method for freight calculation. -- Tax rate can be calculated based on UPS shipping +### 2. Requirements: -## Requirements: +* **Bagisto**: v0.1.6 or higher. -- **Bagisto**: v1.3.3 +### 3. Installation: -## Installation : -- Run the following command -``` -composer require bagisto/bagisto-ups-shipping -``` +* Unzip the respective extension zip and then merge "packages" folders into project root directory. +* Goto config/app.php file and add following line under 'providers' -- Run these commands below to complete the setup -``` +~~~ +Webkul\UpsShipping\Providers\UpsShippingServiceProvider::class +~~~ + +* Goto composer.json file and add following line under 'psr-4' + +~~~ +"Webkul\\UpsShipping\\": "packages/Webkul/UpsShipping/src" +~~~ + +* Run these commands below to complete the setup + +~~~ composer dump-autoload -``` +~~~ -``` +~~~ php artisan route:cache -php artisan optimize +~~~ + +~~~ +php artisan config:clear +~~~ + +~~~ php artisan vendor:publish -``` + -> Press 0 and then press enter to publish all assets and configurations. +~~~ -> now execute the project on your specified domain. +> now execute the project on your specified domain. \ No newline at end of file diff --git a/composer.json b/composer.json index 9f7d67d..57d68be 100644 --- a/composer.json +++ b/composer.json @@ -1,18 +1,13 @@ { - "name": "bagisto/bagisto-ups-shipping", + "name": "bagisto/laravel-ups", "license": "MIT", "authors": [ { - "name": "Naresh Verma", - "email": "naresh.verma327@webkul.com" - }, { - "name": "Vivek Sharma", - "email": "viveksh047@webkul.com" + "name": "Bagisto", + "email": "support@bagisto.com" } ], - "require": { - "konekt/concord": "^1.2" - }, + "require": {}, "autoload": { "psr-4": { "Webkul\\UpsShipping\\": "src/" diff --git a/package.json b/package.json new file mode 100644 index 0000000..782f295 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "private": true, + "scripts": { + "dev": "vite", + "build": "vite build" + }, + "devDependencies": { + "autoprefixer": "^10.4.14", + "axios": "^1.1.2", + "laravel-vite-plugin": "^0.7.2", + "postcss": "^8.4.23", + "tailwindcss": "^3.3.2", + "vite": "^4.0.0", + "vue": "^3.2.47" + }, + "dependencies": { + "@vee-validate/i18n": "^4.9.1", + "@vee-validate/rules": "^4.9.1", + "mitt": "^3.0.0", + "vee-validate": "^4.9.1", + "vue-flatpickr": "^2.3.0" + } +} diff --git a/src/Carriers/Ups.php b/src/Carriers/Ups.php index 7419e86..4194cf4 100644 --- a/src/Carriers/Ups.php +++ b/src/Carriers/Ups.php @@ -4,9 +4,10 @@ use Webkul\Checkout\Models\CartShippingRate; use Webkul\Shipping\Carriers\AbstractShipping; +use Webkul\Checkout\Facades\Cart; /** - * Ups Shipping Shipping. + * Ups Shipping. * */ class Ups extends AbstractShipping @@ -25,70 +26,89 @@ class Ups extends AbstractShipping */ public function calculate() { - if (! core()->getConfigData('sales.carriers.ups.active')) + $uspsMethod = ''; + + $shippingMethods = []; + + $rates = []; + + $shippingHelper = app('Webkul\UpsShipping\Helpers\ShippingMethodHelper'); + + $cart = Cart::getCart(); + + $address = $cart->shipping_address; + + $data = $shippingHelper->getAllCartProducts($address); + + $marketplaceShipping = session()->get('marketplace_shipping_rates'); + + if (! $this->isAvailable()) return false; - $shippingMethods = []; - $rates = []; - $shippingHelper = app('Webkul\UpsShipping\Helpers\ShippingMethodHelper'); - $getCommonServices = app('Webkul\UpsShipping\Repositories\UpsRepository'); - $data = $shippingHelper->getAllCartProducts(); - $serviceData = $getCommonServices->getCommonMethods($data['response']); - - $shippingRate = session()->get('shipping_rates'); - - if ( isset($data['response']) && $data['response'] && !$data['errorResponse'] && !empty($serviceData) ) { - foreach ($serviceData as $key => $upsServices) { - $rate = 0; - $totalShippingCost = 0; - $upsMethod = $key; - $classId = ''; - - foreach ($upsServices as $upsRate) { - $classId = $upsRate['classId']; - $rate += $upsRate['rate'] * $upsRate['itemQuantity']; - $itemShippingCost = $upsRate['rate'] * $upsRate['itemQuantity']; - - if ( isset($rates[$key]) ) { - $rates[$key] = [ - 'amount' => core()->convertPrice($rates[$key]['amount'] + $itemShippingCost), - 'base_amount' => $rates[$key]['base_amount'] + $itemShippingCost - ]; - } else { - $rates[$key] = [ - 'amount' => core()->convertPrice($itemShippingCost), - 'base_amount' => $itemShippingCost - ]; + if (isset ($data) && $data == true) + { + + foreach ($data as $key => $fedexServices) + { + $rate = 0; + $totalShippingCost = 0; + $upsMethod = $key; + $methodCode = $key; + + foreach ($fedexServices as $methods => $upsRate) + { + $rate += $upsRate['rate'] * $upsRate['itemQuantity']; + $sellerId = $upsRate['marketplace_seller_id']; + + $itemShippingCost = $upsRate['rate'] * $upsRate['itemQuantity']; + + $rates[$key][$sellerId] = [ + 'amount' => core()->convertPrice($itemShippingCost), + 'base_amount' => $itemShippingCost + ]; + + if (isset ($rates[$key][$sellerId])) + { + $rates[$key][$sellerId] = [ + 'amount' => core()->convertPrice($rates[$key][$sellerId]['amount'] + $itemShippingCost), + 'base_amount' => $rates[$key][$sellerId]['base_amount'] + $itemShippingCost + ]; } - $totalShippingCost += $itemShippingCost; + $totalShippingCost += $itemShippingCost; } + + $object = new CartShippingRate; + + $object->carrier = 'mpups'; + $object->carrier_title = $this->getConfigData('title'); + $object->method = 'mpups_' . '' . $methodCode; + $object->method_title = $this->getConfigData('title'); + $object->method_description = $upsMethod; + + $object->price = core()->convertPrice($totalShippingCost); + $object->base_price = $totalShippingCost; + + $marketplaceShippingRates = session()->get('marketplace_shipping_rates'); + + if (! is_array($marketplaceShipping)) + { + $marketplaceShippingRates['mpupsshipping'] = ['mpupsshipping' => $rates]; + session()->put('marketplace_shipping_rates', $marketplaceShippingRates); - $object = new CartShippingRate; - $object->carrier = 'ups'; - $object->carrier_title = $this->getConfigData('title') . ' (' . $this->getConfigData('description') . ')'; - $object->method = 'ups_' . $classId; - $object->method_title = $upsMethod; - $object->method_description = $this->getConfigData('title') . ' (' . $this->getConfigData('description') . ')'; - $object->is_calculate_tax = $this->getConfigData('is_calculate_tax'); - $object->price = core()->convertPrice($totalShippingCost); - $object->base_price = $totalShippingCost; - - $shippingRate = session()->get('shipping_rates'); - - if (! is_array($shippingRate)) { - $shippingRates['ups'] = $rates; - session()->put('shipping_rates', $shippingRates); } else { - session()->put('shipping_rates.ups', $rates); + $marketplaceFedexShipping = ['mpupshipping' => $rates]; } array_push($shippingMethods, $object); } + if (isset ($marketplaceFedexShipping)) + { + session()->put('marketplace_shipping_rates.mpupshipping', $marketplaceFedexShipping); + } + return $shippingMethods; - } else { - return null; } } -} \ No newline at end of file +} diff --git a/src/Config/carriers.php b/src/Config/carriers.php old mode 100644 new mode 100755 diff --git a/src/Config/system.php b/src/Config/system.php index a876108..79a8b43 100644 --- a/src/Config/system.php +++ b/src/Config/system.php @@ -4,68 +4,74 @@ [ 'key' => 'sales.carriers.ups', 'name' => 'ups::app.admin.system.ups', - 'sort' => 3, + 'info' => 'ups::app.admin.system.ups-description', + 'sort' => 4, 'fields' => [ [ 'name' => 'title', 'title' => 'ups::app.admin.system.title', - 'type' => 'depends', - 'depend' => 'active:1', - 'validation' => 'required_if:active,1', - 'channel_based' => true, + 'type' => 'text', + 'validation' => 'required', + 'channel_based' => false, 'locale_based' => true ], [ 'name' => 'description', 'title' => 'ups::app.admin.system.description', 'type' => 'textarea', - 'channel_based' => true, + 'channel_based' => false, 'locale_based' => true ], [ - 'name' => 'active', + 'name' => 'ups_active', 'title' => 'ups::app.admin.system.status', 'type' => 'boolean', - 'validation' => 'required', - 'channel_based' => true, - 'locale_based' => false ], [ - 'name' => 'is_calculate_tax', - 'title' => 'admin::app.admin.system.calculate-tax', - 'type' => 'boolean', + 'name' => 'mode', + 'title' => 'ups::app.admin.system.mode', + 'type' => 'select', 'validation' => 'required', - 'channel_based' => true, - 'locale_based' => false, + 'options' => [ + [ + 'title' => 'Development', + 'value' => 'DEVELOPMENT' + ], [ + 'title' => 'Live', + 'value' => "LIVE" + ] + ], ], [ 'name' => 'access_license_key', 'title' => 'ups::app.admin.system.access-license-number', 'type' => 'text', 'validation' => 'required', - 'channel_based' => true, - 'locale_based' => false + 'channel_based' => false, + 'locale_based' => true ], [ 'name' => 'user_id', 'title' => 'ups::app.admin.system.user-id', 'type' => 'text', 'validation' => 'required', - 'channel_based' => true, - 'locale_based' => false + 'channel_based' => false, + 'locale_based' => true ], [ 'name' => 'password', 'title' => 'ups::app.admin.system.password', 'type' => 'password', 'validation' => 'required', - 'channel_based' => true, - 'locale_based' => false - ], [ + 'channel_based' => false, + 'locale_based' => true + ], [ 'name' => 'shipper_number', 'title' => 'ups::app.admin.system.shipper', 'type' => 'text', - 'channel_based' => true, - 'locale_based' => false + 'channel_based' => false, + 'locale_based' => true ], [ 'name' => 'container', 'title' => 'ups::app.admin.system.container', 'type' => 'select', 'validation' => 'required', + 'channel_based' => false, + 'locale_based' => true, 'options' => [ [ 'title' => 'Package', @@ -82,15 +88,15 @@ ], [ 'title' => 'UPS Express Box', 'value' => '21' - ] + ], ], - 'channel_based' => true, - 'locale_based' => false ], [ 'name' => 'weight_unit', 'title' => 'ups::app.admin.system.weight-unit', 'type' => 'select', 'validation' => 'required', + 'channel_based' => false, + 'locale_based' => true, 'options' => [ [ 'title' => 'LBS', @@ -100,12 +106,12 @@ 'value' => 'KGS', ] ], - 'channel_based' => true, - 'locale_based' => false ], [ 'name' => 'services', 'title' => 'ups::app.admin.system.allowed-methods', 'type' => 'multiselect', + 'channel_based' => false, + 'locale_based' => true, 'options' => [ [ 'title' => 'Next Day Air Early AM', @@ -143,9 +149,7 @@ ], ], - 'channel_based' => true, - 'locale_based' => false - ] + ], ] ], ]; \ No newline at end of file diff --git a/src/Helpers/ShippingMethodHelper.php b/src/Helpers/ShippingMethodHelper.php index 13e2bb4..82883d8 100644 --- a/src/Helpers/ShippingMethodHelper.php +++ b/src/Helpers/ShippingMethodHelper.php @@ -18,45 +18,6 @@ class ShippingMethodHelper * @var array */ protected $_config; - - /** - * Payment method services - * - * @var string - */ - protected $services = [ - '01' => 'Next Day Air', - '02' => '2nd Day Air', - '03' => 'Ups Ground', - '07' => 'Ups Worldwide Express', - '08' => 'Ups Worldwide Expedited', - '11' => 'Standard', - '12' => '3 Day Select', - '13' => 'Next Day Air Saver', - '14' => 'Next Day Air Early A.M.', - '54' => 'Ups Worldwide Express Plus', - '59' => '2nd Day Air A.M.', - '65' => 'UPS World Wide Saver', - '82' => 'Today Standard', - '83' => 'Today Dedicated Courier', - '84' => 'Today Intercity', - '85' => 'Today Express', - '86' => 'Today Express Saver' - ]; - - /** - * Cart Address Object - * - * @var object - */ - protected $cartAddress; - - /** - * Ups Repository Object - * - * @var object - */ - protected $upsRepository; /** * RateServiceWsdl @@ -72,14 +33,6 @@ class ShippingMethodHelper */ protected $shipServiceWsdl; - /** - * SellerRepository object - * - * @var object - */ - protected $channel; - - /** * Create a new controller instance. * @@ -88,9 +41,9 @@ class ShippingMethodHelper * @param \Webkul\Shipping\Repositories\UpsRepository $upsRepository; */ public function __construct( - CartAddress $cartAddress, - UpsRepository $upsRepository, - Channel $channel + protected CartAddress $cartAddress, + protected UpsRepository $upsRepository, + protected Channel $channel ) { $this->_config = request('_config'); @@ -107,10 +60,11 @@ public function __construct( * * @return array */ - public function getAllCartProducts() + public function getAllCartProducts($address) { - return $this->_createSoapClient() - ; + $data = $this->_createSoapClient($address); + + return $data; } /** @@ -120,152 +74,211 @@ public function getAllCartProducts() * @param bool|int $trace * @return \SoapClient */ - protected function _createSoapClient() + protected function _createSoapClient($address) { - $allServices = []; - $errorResponse = []; - $cart = Cart::getCart(); - $address = $cart->shipping_address; - $channelDetails = $this->channel->findOneWhere(['code' => core()->getCurrentChannelCode()]); - $sellerAdminServices = explode(",", core()->getConfigData('sales.carriers.ups.services')); - - foreach ($cart->items()->get() as $cartProduct) { - if ($cartProduct->product->getTypeInstance()->isStockable()) { - $weight = $this->getWeight($cartProduct->weight); - $countryId = core()->getConfigData('sales.shipping.origin.country'); - $zoneInformation = core()->getConfigData('sales.shipping.origin.state'); - $address1 = core()->getConfigData('sales.shipping.origin.address1'); - $city = core()->getConfigData('sales.shipping.origin.city'); - $accessKey = core()->getConfigData('sales.carriers.ups.access_license_key'); - $userId = core()->getConfigData('sales.carriers.ups.user_id'); - $password = core()->getConfigData('sales.carriers.ups.password'); - $url = core()->getConfigData('sales.carriers.ups.gateway_url'); - $shipperNumber = core()->getConfigData('sales.carriers.ups.shipper_number'); - $shipperNumber = $shipperNumber ? $shipperNumber: ''; - - // create a simple xml object for AccessRequest & RateRequest - $accessRequesttXML = new \SimpleXMLElement ( "" ); - $rateRequestXML = new \SimpleXMLElement ( "" ); - - // create AccessRequest XML - $accessRequesttXML->addChild ("AccessLicenseNumber", $accessKey); - $accessRequesttXML->addChild ("UserId", $userId); - $accessRequesttXML->addChild ("Password", $password); - - // create RateRequest XML - $request = $rateRequestXML->addChild ('Request'); - $request->addChild ("RequestAction", "Rate"); - $request->addChild ("RequestOption", "Shop"); - - $shipment = $rateRequestXML->addChild ('Shipment'); - $shipper = $shipment->addChild ('Shipper'); - $shipper->addChild ("Name", $channelDetails->name); - $shipper->addChild ("ShipperNumber", $shipperNumber); - - $shipperddress = $shipper->addChild ('Address'); - $shipperddress->addChild ("AddressLine1", $address1 ? $address1 : ''); - $shipperddress->addChild ("City", $city ? $city : ''); - $shipperddress->addChild ("PostalCode", core()->getConfigData('sales.shipping.origin.zipcode')); - $shipperddress->addChild ("CountryCode", $countryId); - - $shipFrom = $shipment->addChild ('ShipFrom'); - $shipFrom->addChild ("CompanyName", $channelDetails->hostname); - $shipFromAddress = $shipFrom->addChild ( 'Address'); - $shipFromAddress->addChild ("AddressLine1", $address1 ? $address1 : ''); - $shipFromAddress->addChild ("City", $city ? $city : ''); - $shipFromAddress->addChild ("StateProvinceCode", $zoneInformation); - $shipFromAddress->addChild ("PostalCode", core()->getConfigData('sales.shipping.origin.zipcode')); - $shipFromAddress->addChild ("CountryCode", $countryId); - - $shipTo = $shipment->addChild ( 'ShipTo'); - $shipTo->addChild ("CompanyName", $address->first_name . ' ' . $address->last_name); - $shipToAddress = $shipTo->addChild ( 'Address'); - $shipToAddress->addChild ("AddressLine1", $address->address1); - $shipToAddress->addChild ("City", $address->city); - if ( $address->country == 'PR' ) { - $shipToAddress->addChild ("PostalCode", '00'. $address->postcode); + $cart = Cart::getCart(); + + $defaultChannel = core()->getCurrentChannelCode(); + + $adminData = $this->channel->findByField('code', $defaultChannel)->first(); + + $adminName = $adminData->name; + + $adminCompany = $adminData->hostname; + + if (! core()->getConfigData('sales.carriers.ups.ups_active')) + { + + return false; + } else { + $status = true; + } + + if ($status) + { + $sellerAdminData = $this->upsRepository->getSellerAdminData($cart->items()->get(), 'ups_postcode'); + } + + $sellerAdminServices = $allServices = []; + foreach ($sellerAdminData as $cartProduct) + { + $sellerAdminServices[0] = explode(",", core()->getConfigData('sales.carriers.ups.services')); + } + + foreach ($sellerAdminData as $cartProduct) + { + $weight = $this->getWeight($cartProduct->weight); + + $countryId = core()->getConfigData('sales.shipping.origin.country'); + + if (! isset($cartProduct->marketplace_seller_id)) + { + //if admin's product + $zoneInformation = core()->getConfigData('sales.shipping.origin.state'); + $address1 = core()->getConfigData('sales.shipping.origin.address1'); + $city = core()->getConfigData('sales.shipping.origin.city'); + } + + // Get The User Credentials + $accessKey = core()->getConfigData('sales.carriers.ups.access_license_key'); + $userId = core()->getConfigData('sales.carriers.ups.user_id'); + $password = core()->getConfigData('sales.carriers.ups.password'); + $url = core()->getConfigData('sales.carriers.ups.gateway_url'); + $shipperNumber = core()->getConfigData('sales.carriers.ups.shipper_number'); + + $shipperNumber = $shipperNumber ? $shipperNumber: ''; + + // create a simple xml object for AccessRequest & RateRequest + $accessRequesttXML = new \SimpleXMLElement ( "" ); + $rateRequestXML = new \SimpleXMLElement ( "" ); + + // create AccessRequest XML + $accessRequesttXML->addChild ( "AccessLicenseNumber", $accessKey ); + $accessRequesttXML->addChild ( "UserId", $userId ); + $accessRequesttXML->addChild ( "Password", $password ); + + // create RateRequest XML + $request = $rateRequestXML->addChild ( 'Request' ); + $request->addChild ( "RequestAction", "Rate" ); + $request->addChild ( "RequestOption", "Shop" ); + + $shipment = $rateRequestXML->addChild ( 'Shipment' ); + $shipper = $shipment->addChild ( 'Shipper' ); + + if (! isset($cartProduct->marketplace_seller_id)) + { + + $shipper->addChild ( "Name", $adminName ); + $shipper->addChild ( "ShipperNumber", $shipperNumber ); + + $shipperddress = $shipper->addChild ( 'Address' ); + $shipperddress->addChild ( "AddressLine1", $address1 ? $address1 : '' ); + $shipperddress->addChild ( "City", $city ? $city : '' ); + $shipperddress->addChild ( "PostalCode", core()->getConfigData('sales.shipping.origin.zipcode') ); + $shipperddress->addChild ( "CountryCode", $countryId ); + + $shipFrom = $shipment->addChild ( 'ShipFrom' ); + $shipFrom->addChild ( "CompanyName", $adminCompany ); + $shipFromAddress = $shipFrom->addChild ( 'Address' ); + $shipFromAddress->addChild ( "AddressLine1", $address1 ? $address1 : '' ); + $shipFromAddress->addChild ( "City", $city ? $city : '' ); + $shipFromAddress->addChild ( "StateProvinceCode", $zoneInformation ); + $shipFromAddress->addChild ( "PostalCode", core()->getConfigData('sales.shipping.origin.zipcode') ); + $shipFromAddress->addChild ( "CountryCode", $countryId ); + } + + $shipTo = $shipment->addChild ( 'ShipTo' ); + $shipTo->addChild ( "CompanyName", $address->first_name . ' ' . $address->last_name ); + $shipToAddress = $shipTo->addChild ( 'Address' ); + $shipToAddress->addChild ( "AddressLine1", $address->address1 ); + $shipToAddress->addChild ( "City", $address->city ); + if ($address->country == 'PR') + { + $shipToAddress->addChild ( "PostalCode", '00'. $address->postcode ); + } else { + $shipToAddress->addChild ( "PostalCode", $address->postcode ); + } + $shipToAddress->addChild ( "CountryCode", $address->country ); + $package = $shipment->addChild ( 'Package' ); + $packageType = $package->addChild ( 'PackagingType' ); + $packageType->addChild ( "Code", core()->getConfigData('sales.carriers.ups.container') ); + + $packageWeight = $package->addChild ( 'PackageWeight' ); + $unitOfMeasurement = $packageWeight->addChild ( 'UnitOfMeasurement' ); + $unitOfMeasurement->addChild ( "Code", "LBS" ); + $packageWeight->addChild ( "Weight", $weight ); + + $requestXML = $accessRequesttXML->asXML () . $rateRequestXML->asXML (); + $endpointurl = 'https://onlinetools.ups.com/ups.app/xml/Rate'; + + try { + $url = 'https://onlinetools.ups.com/ups.app/xml/Rate'; + + $ch = curl_init(); + curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); + curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + "Content-type: text/xml", + "Accept: text/xml", + "Cache-Control: no-cache", + "Pragma: no-cache", + )); + curl_setopt($ch, CURLOPT_POSTFIELDS,$requestXML); + + $response = curl_exec($ch); + + curl_close($ch); + + $upsServiceArray = simplexml_load_string($response); + + $upsServices = json_decode(json_encode($upsServiceArray)); + + if ( isset($cartProduct->marketplace_seller_id)) + { + $sellerId = $cartProduct->marketplace_seller_id; } else { - $shipToAddress->addChild ("PostalCode", $address->postcode); + $sellerId = 0; } - $shipToAddress->addChild ("CountryCode", $address->country); - $package = $shipment->addChild ('Package'); - $packageType = $package->addChild ('PackagingType'); - $packageType->addChild ("Code", core()->getConfigData('sales.carriers.ups.container')); - - $packageWeight = $package->addChild ('PackageWeight'); - $unitOfMeasurement = $packageWeight->addChild ('UnitOfMeasurement'); - $unitOfMeasurement->addChild ("Code", "LBS"); - $packageWeight->addChild ("Weight", $weight); - - $requestXML = $accessRequesttXML->asXML () . $rateRequestXML->asXML (); - - try { - $url = 'https://onlinetools.ups.com/ups.app/xml/Rate'; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_setopt($ch, CURLOPT_TIMEOUT, 30); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - "Content-type: text/xml", - "Accept: text/xml", - "Cache-Control: no-cache", - "Pragma: no-cache", - )); - curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXML); - $response = curl_exec($ch); - curl_close($ch); - - $upsServiceArray = simplexml_load_string($response); - $upsServices = json_decode(json_encode($upsServiceArray)); - - if ($response) { - if ( isset($upsServices->Response->ResponseStatusCode) - && $upsServices->Response->ResponseStatusCode == 1 ) { - - if ( isset($upsServices->RatedShipment) && $upsServices->RatedShipment ) { - - foreach ($upsServices->RatedShipment as $services) { - $serviceCode = $services->Service->Code; - - if ( !empty($sellerAdminServices) && in_array($serviceCode, $sellerAdminServices) && isset($this->services[$serviceCode]) ) { - - $cartProductServices[$this->services[$serviceCode]] = [ - 'classId' => $serviceCode, - 'rate' => $services->TotalCharges->MonetaryValue, - 'currency' => $services->TotalCharges->CurrencyCode, - 'weight' => $services->BillingWeight->Weight, - 'weightUnit' => $services->BillingWeight->UnitOfMeasurement->Code, - 'itemQuantity' => $cartProduct->quantity - ]; - } - } - if ( !empty($cartProductServices)) { - $allServices[] = $cartProductServices; + if ($response) + { + if ( isset($upsServices->Response->ResponseStatusDescription) + && $upsServices->Response->ResponseStatusDescription == 'Success') + { + if ( isset($upsServices->RatedShipment)) + { + foreach ($upsServices->RatedShipment as $services) + { + + $serviceCode = $services->Service->Code; + + $matchResult = $this->upsRepository->validateAllowedMethods($serviceCode, $sellerAdminServices); + + $serviceName = $this->getServiceName($serviceCode); + + if ($matchResult) + { + $cartProductServices[$serviceName] = [ + 'classId' => $serviceCode, + 'rate' => $services->RatedPackage->TotalCharges->MonetaryValue, + 'currency' => $services->RatedPackage->TotalCharges->CurrencyCode, + 'weight' => $services->BillingWeight->Weight, + 'weightUnit' => $services->BillingWeight->UnitOfMeasurement->Code, + 'marketplace_seller_id' => $sellerId, + 'itemQuantity' => $cartProduct->quantity + ]; } + } - } else { - if ( isset($upsServices->Response->ResponseStatusCode) && isset($upsServices->Response->Error->ErrorDescription) ) { - $this->getErrorLog($upsServices->Response->Error->ErrorDescription); - $errorResponse[] = $upsServices->Response->Error->ErrorDescription; + + if ( !empty($cartProductServices)) + { + $allServices[] = $cartProductServices; } } + + } else { + $errorLog = $this->getErrorLog($upsServices); + + return false; + //to check the error generated in the method; } - } catch (\Exception $e) { - $this->getErrorLog($e->getMessage()); - $errorResponse[] = $e->getMessage(); } + } catch (\Exception $e) { + + return false; } } - - $responses = [ - 'response' => $allServices, - 'errorResponse' => $errorResponse - ]; - - return $responses; + + if ( !empty($allServices) ) + { + return $this->upsRepository->getCommonMethods($allServices); + } else { + return false; + } } @@ -298,8 +311,10 @@ protected function getServiceName($serviceCode) ]; - foreach ($mapServices as $key => $service) { - if ($key == $serviceCode) { + foreach ($mapServices as $key => $service) + { + if ($key == $serviceCode) + { return $service; } } @@ -312,18 +327,24 @@ protected function getServiceName($serviceCode) * * @param string $weight **/ - public function getWeight($weight) + public function getWeight($weight) { - $coreWeightUnit = strtoupper(core()->getConfigData('general.general.locale_options.weight_unit')); - $upsWeightUnit = strtoupper(core()->getConfigData('sales.carriers.ups.weight_unit')); + + $coreWeightUnit = strtoupper(core()->getConfigData('general.general.locale_options.weight_unit')); + + $upsWeightUnit = strtoupper(core()->getConfigData('sales.carriers.ups.weight_unit')); + $convertedWeight = ''; - - if ($coreWeightUnit == 'LBS') { - if ( $upsWeightUnit == 'LBS') { + + if ($coreWeightUnit == 'LBS') + { + if ($upsWeightUnit == 'LBS') + { $convertedWeight = $weight; } else { //kgs to lbs $convertedWeight = $weight/0.45359237; + } } else { $convertedWeight = $weight/0.45359237; @@ -337,32 +358,29 @@ public function getWeight($weight) * * @param string $error **/ - public function getErrorLog($errors) { - if ( isset($errors->Response->Error) ) { - - if (gettype($errors->Response->Error) == 'array') { - - foreach ($errors->Response->Error as $errorLog) - { - $exception[] = $errorLog->ErrorDescription; - } + public function getErrorLog($errors) + { - $status = $errors->Response->ResponseStatusDescription; - } else { - $status = $errors->Response->Error->ErrorSeverity; + foreach ($errors->Response->Error as $errorLog) + { + $exception[] = $errorLog->ErrorDescription; + } + + $status = $errors->Response->ResponseStatusDescription; + + if (gettype($errors->Response->Error) !== 'array') + { + $status = $errors->Response->Error->ErrorSeverity; - $exception[] = $errors->Response->Error->ErrorDescription; - } + $exception[] = $errors->Response->Error->ErrorDescription; + } - $logs = ['status' => $status, 'description' => $exception]; + $logs = ['status' => $status, 'description' => $exception]; - $shippingLog = new Logger('shipping'); - $shippingLog->pushHandler(new StreamHandler(storage_path('logs/ups.log')), Logger::INFO); - $shippingLog->info('shipping', $logs); + $shippingLog = new Logger('shipping'); + $shippingLog->pushHandler(new StreamHandler(storage_path('logs/ups.log')), Logger::INFO); + $shippingLog->info('shipping', $logs); - return true; - } else { - return false; - } + return true; } } \ No newline at end of file diff --git a/src/Providers/UpsShippingServiceProvider.php b/src/Providers/UpsShippingServiceProvider.php old mode 100644 new mode 100755 index 764836e..10508df --- a/src/Providers/UpsShippingServiceProvider.php +++ b/src/Providers/UpsShippingServiceProvider.php @@ -14,7 +14,11 @@ class UpsShippingServiceProvider extends ServiceProvider */ public function boot(Router $router) { + $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); + $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'ups'); + + $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'ups'); } /** diff --git a/src/Repositories/UpsRepository.php b/src/Repositories/UpsRepository.php index f63fdbd..5604eeb 100644 --- a/src/Repositories/UpsRepository.php +++ b/src/Repositories/UpsRepository.php @@ -23,14 +23,19 @@ class UpsRepository * * @return mixed */ - public function getSellerAdminData($cartItems) { + public function getSellerAdminData($cartItems) + { $adminProducts = []; - foreach ($cartItems as $item) { + + foreach ($cartItems as $item) + { array_push($adminProducts, $item); } + return $adminProducts; } + /** * Get the Allowde Services * @param $allowedServices @@ -41,32 +46,37 @@ public function validateAllowedMethods($service, $allowedServices) $count = 0; $totalCount = count($allowedServices); - foreach ($allowedServices as $methods) { - if ( in_array($service, $methods) ) { + foreach ($allowedServices as $methods) + { + if ( in_array($service, $methods) ) + { $count += 1; } } - if ( $count == $totalCount ) { + if ( $count == $totalCount ) + { return true; - } else { - return false; } + return false; } /** * Get the Common Services for all the cartProduct * @param $allServices */ - public function getAllowedMethods($allServices) { - - $allowedServices = explode(",", core()->getConfigData('sales.carriers.ups.services')); + public function getAllowedMethods($allServices) + { + $allowedServices = explode(",", core()->getConfigData('sales.carriers.ups.ups_services')); - foreach ($allServices as $services) { + foreach ($allServices as $services) + { $allowedMethod =[]; - foreach ($services as $service) { - - foreach ($service as $serviceType =>$upsService) { - if (in_array($serviceType , $allowedServices)) { + foreach ($services as $service) + { + foreach ($service as $serviceType =>$upsService) + { + if (in_array($serviceType , $allowedServices)) + { $allowedMethod[] = [ $serviceType => $upsService ]; @@ -78,20 +88,20 @@ public function getAllowedMethods($allServices) { } } - if ($allowedMethod == null) { + if ($allowedMethod == null) + { continue; - } else { - $allowedMethods[] = $allowedMethod; } + $allowedMethods[] = $allowedMethod; } - if (isset($allowedMethods)) { - + if (isset($allowedMethods)) + { return $this->getCommonMethods($allowedMethods); - } else { - return false; } + return false; + } @@ -102,11 +112,12 @@ public function getAllowedMethods($allServices) { */ public function getCommonMethods($methods) { - $avilableServicesArray = []; - $countMethods = count($methods); + $countMethods = count($methods); - foreach ($methods as $fedexMethods) { - foreach ($fedexMethods as $key => $fedexMethod) { + foreach ($methods as $fedexMethods) + { + foreach ($fedexMethods as $key => $fedexMethod) + { $avilableServicesArray[] = $key; } } @@ -114,27 +125,30 @@ public function getCommonMethods($methods) $countServices = array_count_values($avilableServicesArray); $finalServices = []; - foreach ($countServices as $serviceType => $servicesCount) { - - foreach ($methods as $fedexMethods) { - foreach ($fedexMethods as $type => $fedexMethod) { - if ($serviceType == $type && $servicesCount == $countMethods) { - + foreach ($countServices as $serviceType => $servicesCount) + { + foreach ($methods as $fedexMethods) + { + foreach ($fedexMethods as $type => $fedexMethod) + { + if ($serviceType == $type && $servicesCount == $countMethods) + { $finalServices[$serviceType][] =$fedexMethod; } } } - if ($finalServices == null) { + if ($finalServices == null) + { continue; } } - if (!empty($finalServices)) { - return $finalServices; - } else { + if (empty($finalServices)) + { return false; } + return $finalServices; } } diff --git a/src/Resources/lang/ar/app.php b/src/Resources/lang/ar/app.php new file mode 100755 index 0000000..ff7c3e2 --- /dev/null +++ b/src/Resources/lang/ar/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'العنوان', + 'description' => 'الوصف', + 'status' => 'الحالة', + 'ups' => 'شحن UPS', + 'ups-description' => 'الشحن عبر الإنترنت مع UPS، قم بإرسال وتوصيل الطرود بشكل أسرع وأسهل من أي وقت مضى.', + 'gateway-url' => 'رابط البوابة', + 'user-id' => 'معرف المستخدم', + 'access-license-number' => 'مفتاح رخصة الوصول', + 'shipper' => 'رقم الشحن', + 'weight-unit' => 'وحدة الوزن', + 'password' => 'كلمة المرور', + 'mode' => 'الوضع', + 'container' => 'الحاوية', + 'size' => 'الحجم', + 'allowed-methods' => 'الخدمات المسموح بها', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/bn/app.php b/src/Resources/lang/bn/app.php new file mode 100644 index 0000000..00a1301 --- /dev/null +++ b/src/Resources/lang/bn/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'শিরোনাম', + 'description' => 'বর্ণনা', + 'status' => 'অবস্থা', + 'ups' => 'ইউপিএস শিপিং', + 'ups-description' => 'ইউপিএস দ্বারা অনলাইন শিপিং, পার্সেল পাঠানো এবং ডেলিভারি করা হোক সহজ এবং দ্রুততর হবে সহজে।', + 'gateway-url' => 'গেটওয়ে ইউআরএল', + 'user-id' => 'ব্যবহারকারী আইডি', + 'access-license-number' => 'অ্যাক্সেস লাইসেন্স কী', + 'shipper' => 'শিপার নম্বর', + 'weight-unit' => 'ওজন ইউনিট', + 'password' => 'পাসওয়ার্ড', + 'mode' => 'মোড', + 'container' => 'কনটেইনার', + 'size' => 'আকার', + 'allowed-methods' => 'অনুমোদিত সেবাসমূহ', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/de/app.php b/src/Resources/lang/de/app.php new file mode 100755 index 0000000..71bf7c4 --- /dev/null +++ b/src/Resources/lang/de/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'Titel', + 'description' => 'Beschreibung', + 'status' => 'Status', + 'ups' => 'UPS Versand', + 'ups-description' => 'Online-Versand mit UPS, Senden und Liefern von Paketen schneller und einfacher als je zuvor.', + 'gateway-url' => 'Gateway URL', + 'user-id' => 'Benutzer-ID', + 'access-license-number' => 'Zugriffslizenzschlüssel', + 'shipper' => 'Versender-Nummer', + 'weight-unit' => 'Gewichtseinheit', + 'password' => 'Passwort', + 'mode' => 'Modus', + 'container' => 'Behälter', + 'size' => 'Größe', + 'allowed-methods' => 'Erlaubte Dienste', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/en/app.php b/src/Resources/lang/en/app.php index d6a5aba..f8ae9e6 100644 --- a/src/Resources/lang/en/app.php +++ b/src/Resources/lang/en/app.php @@ -3,20 +3,21 @@ return [ 'admin' => [ 'system' => [ - 'title' => 'Title', - 'description' => 'Description', - 'status' => 'Status', - 'ups' => 'UPS Shipping', - 'gateway-url' => 'Gateway URL', - 'user-id' => 'User ID' , + 'title' => 'Title', + 'description' => 'Description', + 'status' => 'Status', + 'ups' => 'UPS Shipping', + 'ups-description' => 'Online shipping with UPS, Send and deliver packages faster easier than ever.', + 'gateway-url' => 'Gateway URL', + 'user-id' => 'User ID' , 'access-license-number' => 'Access License Key', - 'shipper' => 'Shipper Number', - 'weight-unit' => 'Weight Unit', - 'password' => 'Password', - 'mode' => 'Mode', - 'container' => 'Container', - 'size' => 'Size', - 'allowed-methods' => 'Allowed Services', + 'shipper' => 'Shipper Number', + 'weight-unit' => 'Weight Unit', + 'password' => 'Password', + 'mode' => 'Mode', + 'container' => 'Container', + 'size' => 'Size', + 'allowed-methods' => 'Allowed Services', ], ] ]; \ No newline at end of file diff --git a/src/Resources/lang/es/app.php b/src/Resources/lang/es/app.php new file mode 100755 index 0000000..d5141df --- /dev/null +++ b/src/Resources/lang/es/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'Título', + 'description' => 'Descripción', + 'status' => 'Estado', + 'ups' => 'Envío UPS', + 'ups-description' => 'Envío en línea con UPS, Envía y entrega paquetes más rápido y más fácil que nunca.', + 'gateway-url' => 'URL del portal', + 'user-id' => 'ID de usuario', + 'access-license-number' => 'Clave de licencia de acceso', + 'shipper' => 'Número de remitente', + 'weight-unit' => 'Unidad de peso', + 'password' => 'Contraseña', + 'mode' => 'Modo', + 'container' => 'Contenedor', + 'size' => 'Tamaño', + 'allowed-methods' => 'Servicios permitidos', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/fa/app.php b/src/Resources/lang/fa/app.php new file mode 100755 index 0000000..cd0ac79 --- /dev/null +++ b/src/Resources/lang/fa/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'عنوان', + 'description' => 'توضیحات', + 'status' => 'وضعیت', + 'ups' => 'حمل و نقل UPS', + 'ups-description' => 'حمل و نقل آنلاین با UPS، ارسال و تحویل بسته‌ها سریع‌تر و آسان‌تر از همیشه.', + 'gateway-url' => 'آدرس دروازه', + 'user-id' => 'شناسه کاربر', + 'access-license-number' => 'کلید لایسنس دسترسی', + 'shipper' => 'شماره فرستنده', + 'weight-unit' => 'واحد وزن', + 'password' => 'گذرواژه', + 'mode' => 'حالت', + 'container' => 'ظرف', + 'size' => 'اندازه', + 'allowed-methods' => 'خدمات مجاز', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/fr/app.php b/src/Resources/lang/fr/app.php new file mode 100755 index 0000000..35c7330 --- /dev/null +++ b/src/Resources/lang/fr/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'Titre', + 'description' => 'Description', + 'status' => 'Statut', + 'ups' => 'Expédition UPS', + 'ups-description' => 'Expédition en ligne avec UPS, Envoyez et livrez des colis plus rapidement et plus facilement que jamais.', + 'gateway-url' => 'URL de la passerelle', + 'user-id' => 'Identifiant utilisateur', + 'access-license-number' => 'Clé de licence d'accès', + 'shipper' => 'Numéro d'expéditeur', + 'weight-unit' => 'Unité de poids', + 'password' => 'Mot de passe', + 'mode' => 'Mode', + 'container' => 'Conteneur', + 'size' => 'Taille', + 'allowed-methods' => 'Services autorisés', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/he/app.php b/src/Resources/lang/he/app.php new file mode 100755 index 0000000..e3cb7f2 --- /dev/null +++ b/src/Resources/lang/he/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'כותרת', + 'description' => 'תיאור', + 'status' => 'מצב', + 'ups' => 'משלוח UPS', + 'ups-description' => 'משלוח דיגיטלי עם UPS, שלח ומסיר חבילות מהיר יותר וקל יותר מתמיד.', + 'gateway-url' => 'כתובת URL של השער', + 'user-id' => 'מזהה משתמש', + 'access-license-number' => 'מפתח רישיון גישה', + 'shipper' => 'מספר שולח', + 'weight-unit' => 'יחידת משקל', + 'password' => 'סיסמה', + 'mode' => 'מצב', + 'container' => 'מיכל', + 'size' => 'גודל', + 'allowed-methods' => 'שירותים מורשים', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/hi_IN/app.php b/src/Resources/lang/hi_IN/app.php new file mode 100755 index 0000000..a6fbdef --- /dev/null +++ b/src/Resources/lang/hi_IN/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'शीर्षक', + 'description' => 'विवरण', + 'status' => 'स्थिति', + 'ups' => 'UPS शिपिंग', + 'ups-description' => 'UPS के साथ ऑनलाइन शिपिंग, पैकेज को तेज़ी से भेजें और डिलीवर करें, कभी भी से भी आसान और तेज़ी से।', + 'gateway-url' => 'गेटवे URL', + 'user-id' => 'उपयोगकर्ता आईडी', + 'access-license-number' => 'पहुंच लाइसेंस कुंजी', + 'shipper' => 'शिपर नंबर', + 'weight-unit' => 'वजन इकाई', + 'password' => 'पासवर्ड', + 'mode' => 'मोड', + 'container' => 'कंटेनर', + 'size' => 'आकार', + 'allowed-methods' => 'अनुमत सेवाएं', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/it/app.php b/src/Resources/lang/it/app.php new file mode 100755 index 0000000..bd350ce --- /dev/null +++ b/src/Resources/lang/it/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'Titolo', + 'description' => 'Descrizione', + 'status' => 'Stato', + 'ups' => 'Spedizione UPS', + 'ups-description' => 'Spedizione online con UPS, Invia e consegna pacchi più velocemente e più facilmente che mai.', + 'gateway-url' => 'URL del gateway', + 'user-id' => 'ID utente', + 'access-license-number' => 'Chiave di licenza di accesso', + 'shipper' => 'Numero del mittente', + 'weight-unit' => 'Unità di peso', + 'password' => 'Password', + 'mode' => 'Modalità', + 'container' => 'Contenitore', + 'size' => 'Dimensione', + 'allowed-methods' => 'Servizi consentiti', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/ja/app.php b/src/Resources/lang/ja/app.php new file mode 100755 index 0000000..cb22204 --- /dev/null +++ b/src/Resources/lang/ja/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'タイトル', + 'description' => '説明', + 'status' => 'ステータス', + 'ups' => 'UPS 配送', + 'ups-description' => 'UPS を使用したオンライン配送、より簡単で迅速なパッケージの送信と配達。', + 'gateway-url' => 'ゲートウェイ URL', + 'user-id' => 'ユーザー ID', + 'access-license-number' => 'アクセス ライセンス キー', + 'shipper' => '出荷者番号', + 'weight-unit' => '重量単位', + 'password' => 'パスワード', + 'mode' => 'モード', + 'container' => 'コンテナ', + 'size' => 'サイズ', + 'allowed-methods' => '許可されたサービス', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/nl/app.php b/src/Resources/lang/nl/app.php new file mode 100755 index 0000000..c71313b --- /dev/null +++ b/src/Resources/lang/nl/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'Titel', + 'description' => 'Omschrijving', + 'status' => 'Status', + 'ups' => 'UPS Verzending', + 'ups-description' => 'Online verzending met UPS, Stuur en bezorg pakketten sneller en gemakkelijker dan ooit.', + 'gateway-url' => 'Gateway URL', + 'user-id' => 'Gebruikers-ID', + 'access-license-number' => 'Toegang Licentiesleutel', + 'shipper' => 'Afzender Nummer', + 'weight-unit' => 'Gewichtseenheid', + 'password' => 'Wachtwoord', + 'mode' => 'Modus', + 'container' => 'Container', + 'size' => 'Grootte', + 'allowed-methods' => 'Toegestane Diensten', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/pl/app.php b/src/Resources/lang/pl/app.php new file mode 100755 index 0000000..2ef9bc2 --- /dev/null +++ b/src/Resources/lang/pl/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'Tytuł', + 'description' => 'Opis', + 'status' => 'Status', + 'ups' => 'Wysyłka UPS', + 'ups-description' => 'Wysyłka online z UPS, Wysyłaj i dostarczaj paczki szybciej i łatwiej niż kiedykolwiek.', + 'gateway-url' => 'URL Bramy', + 'user-id' => 'ID Użytkownika', + 'access-license-number' => 'Klucz Licencji Dostępu', + 'shipper' => 'Numer Nadawcy', + 'weight-unit' => 'Jednostka Wagi', + 'password' => 'Hasło', + 'mode' => 'Tryb', + 'container' => 'Kontener', + 'size' => 'Rozmiar', + 'allowed-methods' => 'Dozwolone Usługi', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/pt_BR/app.php b/src/Resources/lang/pt_BR/app.php new file mode 100755 index 0000000..e596caf --- /dev/null +++ b/src/Resources/lang/pt_BR/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'Título', + 'description' => 'Descrição', + 'status' => 'Status', + 'ups' => 'Envio UPS', + 'ups-description' => 'Envio online com a UPS, Envie e entregue pacotes mais rápido e mais fácil do que nunca.', + 'gateway-url' => 'URL do Gateway', + 'user-id' => 'ID do Usuário', + 'access-license-number' => 'Chave de Licença de Acesso', + 'shipper' => 'Número do Remetente', + 'weight-unit' => 'Unidade de Peso', + 'password' => 'Senha', + 'mode' => 'Modo', + 'container' => 'Contêiner', + 'size' => 'Tamanho', + 'allowed-methods' => 'Serviços Permitidos', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/ru/app.php b/src/Resources/lang/ru/app.php new file mode 100755 index 0000000..1d9192e --- /dev/null +++ b/src/Resources/lang/ru/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'Заголовок', + 'description' => 'Описание', + 'status' => 'Статус', + 'ups' => 'Доставка UPS', + 'ups-description' => 'Онлайн-доставка с UPS, Отправляйте и доставляйте посылки быстрее и проще, чем когда-либо.', + 'gateway-url' => 'URL шлюза', + 'user-id' => 'Идентификатор пользователя', + 'access-license-number' => 'Ключ лицензии доступа', + 'shipper' => 'Номер отправителя', + 'weight-unit' => 'Единица веса', + 'password' => 'Пароль', + 'mode' => 'Режим', + 'container' => 'Контейнер', + 'size' => 'Размер', + 'allowed-methods' => 'Разрешенные услуги', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/sin/app.php b/src/Resources/lang/sin/app.php new file mode 100755 index 0000000..fe6322e --- /dev/null +++ b/src/Resources/lang/sin/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'මාතෘකාව', + 'description' => 'විස්තර', + 'status' => 'ස්ථානය', + 'ups' => 'UPS බෙහෙවිය', + 'ups-description' => 'UPS සමඟ අන්තර්ගත බෙහෙවිය, නිවැරදි හා හොඳයි තැනීම සහ ස්පීඩ් කරන්න.', + 'gateway-url' => 'ගේට්වේ URL', + 'user-id' => 'පරිශීලක හැඳුනුම්', + 'access-license-number' => 'ප්‍රවේශ සහිතවිය අංකය', + 'shipper' => 'හැපවුම් අංකය', + 'weight-unit' => 'බර ඒකකය', + 'password' => 'මුරපදය', + 'mode' => 'සංඛ්යාව', + 'container' => 'කොන්ටේනරය', + 'size' => 'තරම', + 'allowed-methods' => 'සමාවෙන සේවාවන්', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/tr/app.php b/src/Resources/lang/tr/app.php new file mode 100755 index 0000000..f7a9ef0 --- /dev/null +++ b/src/Resources/lang/tr/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'Başlık', + 'description' => 'Açıklama', + 'status' => 'Durum', + 'ups' => 'UPS Kargo', + 'ups-description' => 'UPS ile çevrimiçi kargo, Paketleri daha hızlı ve daha kolay bir şekilde gönderin ve teslim edin.', + 'gateway-url' => 'Ağ Geçidi URL', + 'user-id' => 'Kullanıcı Kimliği', + 'access-license-number' => 'Erişim Lisans Anahtarı', + 'shipper' => 'Gönderici Numarası', + 'weight-unit' => 'Ağırlık Birimi', + 'password' => 'Şifre', + 'mode' => 'Mod', + 'container' => 'Konteyner', + 'size' => 'Boyut', + 'allowed-methods' => 'İzin Verilen Hizmetler', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/uk/app.php b/src/Resources/lang/uk/app.php new file mode 100755 index 0000000..7831ebc --- /dev/null +++ b/src/Resources/lang/uk/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => 'Назва', + 'description' => 'Опис', + 'status' => 'Статус', + 'ups' => 'Відправлення UPS', + 'ups-description' => 'Онлайн-доставка з UPS, Надсилайте та доставляйте пакети швидше та простіше, ніж будь-коли.', + 'gateway-url' => 'URL шлюзу', + 'user-id' => 'Ідентифікатор користувача', + 'access-license-number' => 'Ключ ліцензії доступу', + 'shipper' => 'Номер відправника', + 'weight-unit' => 'Одиниця ваги', + 'password' => 'Пароль', + 'mode' => 'Режим', + 'container' => 'Контейнер', + 'size' => 'Розмір', + 'allowed-methods' => 'Дозволені послуги', + ], + ] +]; \ No newline at end of file diff --git a/src/Resources/lang/zh_CN/app.php b/src/Resources/lang/zh_CN/app.php new file mode 100755 index 0000000..0802feb --- /dev/null +++ b/src/Resources/lang/zh_CN/app.php @@ -0,0 +1,23 @@ + [ + 'system' => [ + 'title' => '标题', + 'description' => '描述', + 'status' => '状态', + 'ups' => 'UPS 邮寄', + 'ups-description' => '使用 UPS 进行在线邮寄,更快、更轻松地发送和递送包裹。', + 'gateway-url' => '网关 URL', + 'user-id' => '用户 ID', + 'access-license-number' => '访问许可证密钥', + 'shipper' => '发货人编号', + 'weight-unit' => '重量单位', + 'password' => '密码', + 'mode' => '模式', + 'container' => '容器', + 'size' => '尺寸', + 'allowed-methods' => '允许的服务', + ], + ] +]; \ No newline at end of file diff --git a/webpack.mix.js b/webpack.mix.js new file mode 100644 index 0000000..6713475 --- /dev/null +++ b/webpack.mix.js @@ -0,0 +1,19 @@ +const { mix } = require("laravel-mix"); +require("laravel-mix-merge-manifest"); + +if (mix.inProduction()) { + var publicPath = 'publishable/assets'; +} else { + var publicPath = "../../../public/themes/default/assets"; +} + +mix.setPublicPath(publicPath).mergeManifest(); +mix.disableNotifications(); + +mix.options({ + processCssUrls: false + }); + +if (mix.inProduction()) { + mix.version(); +} \ No newline at end of file From 519a92cfbb6418d1edbea7e37021fbb33923a2d2 Mon Sep 17 00:00:00 2001 From: antu chaudhary Date: Thu, 4 Jan 2024 16:01:26 +0530 Subject: [PATCH 2/8] Update the composer and Readme files --- README.md | 6 ++++++ composer.json | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c03a9a1..04d4398 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,13 @@ It packs in lots of demanding features that allows your business to scale in no ### 3. Installation: +* Run the following command +~~~ +composer require bagisto/bagisto-ups-shipping +~~~ + * Unzip the respective extension zip and then merge "packages" folders into project root directory. +* Change the module name according to the providers like- (bagisto-ups-shipping) to (UpsShipping) * Goto config/app.php file and add following line under 'providers' ~~~ diff --git a/composer.json b/composer.json index 57d68be..576939a 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,18 @@ { - "name": "bagisto/laravel-ups", + "name": "bagisto/bagisto-ups-shipping", "license": "MIT", "authors": [ { - "name": "Bagisto", - "email": "support@bagisto.com" + "name": "Naresh Verma", + "email": "naresh.verma327@webkul.com" + }, { + "name": "Vivek Sharma", + "email": "viveksh047@webkul.com" } ], - "require": {}, + "require": { + "konekt/concord": "^1.2" + }, "autoload": { "psr-4": { "Webkul\\UpsShipping\\": "src/" @@ -22,4 +27,4 @@ } }, "minimum-stability": "dev" -} +} \ No newline at end of file From 139e5cf01929fbb30862a67a1d9af70836d6f853 Mon Sep 17 00:00:00 2001 From: antu chaudhary Date: Fri, 5 Jan 2024 11:06:32 +0530 Subject: [PATCH 3/8] some changes in upsshipping --- src/Carriers/Ups.php | 41 ++++++------ src/Config/system.php | 47 +++++++------- src/Helpers/ShippingMethodHelper.php | 93 +++++++++++++--------------- src/Repositories/UpsRepository.php | 86 ++++++++++++------------- 4 files changed, 123 insertions(+), 144 deletions(-) diff --git a/src/Carriers/Ups.php b/src/Carriers/Ups.php index 4194cf4..4d1a789 100644 --- a/src/Carriers/Ups.php +++ b/src/Carriers/Ups.php @@ -4,12 +4,9 @@ use Webkul\Checkout\Models\CartShippingRate; use Webkul\Shipping\Carriers\AbstractShipping; +use Webkul\UpsShipping\Helpers\ShippingMethodHelper; use Webkul\Checkout\Facades\Cart; -/** - * Ups Shipping. - * - */ class Ups extends AbstractShipping { /** @@ -32,31 +29,30 @@ public function calculate() $rates = []; - $shippingHelper = app('Webkul\UpsShipping\Helpers\ShippingMethodHelper'); + $shippingHelper = app(ShippingMethodHelper::class); $cart = Cart::getCart(); $address = $cart->shipping_address; - $data = $shippingHelper->getAllCartProducts($address); + $cartProducts = $shippingHelper->getAllCartProducts($address); $marketplaceShipping = session()->get('marketplace_shipping_rates'); - if (! $this->isAvailable()) - return false; + if (! $this->isAvailable()){ - if (isset ($data) && $data == true) - { + return false; + } + if (isset ($cartProducts) && $cartProducts == true) { - foreach ($data as $key => $fedexServices) - { + foreach ($cartProducts as $key => $fedexServices) { $rate = 0; $totalShippingCost = 0; $upsMethod = $key; $methodCode = $key; - foreach ($fedexServices as $methods => $upsRate) - { + foreach ($fedexServices as $methods => $upsRate) { + $rate += $upsRate['rate'] * $upsRate['itemQuantity']; $sellerId = $upsRate['marketplace_seller_id']; @@ -67,12 +63,11 @@ public function calculate() 'base_amount' => $itemShippingCost ]; - if (isset ($rates[$key][$sellerId])) - { + if (isset ($rates[$key][$sellerId])) { $rates[$key][$sellerId] = [ - 'amount' => core()->convertPrice($rates[$key][$sellerId]['amount'] + $itemShippingCost), - 'base_amount' => $rates[$key][$sellerId]['base_amount'] + $itemShippingCost - ]; + 'amount' => core()->convertPrice($rates[$key][$sellerId]['amount'] + $itemShippingCost), + 'base_amount' => $rates[$key][$sellerId]['base_amount'] + $itemShippingCost + ]; } $totalShippingCost += $itemShippingCost; @@ -91,8 +86,8 @@ public function calculate() $marketplaceShippingRates = session()->get('marketplace_shipping_rates'); - if (! is_array($marketplaceShipping)) - { + if (! is_array($marketplaceShipping)) { + $marketplaceShippingRates['mpupsshipping'] = ['mpupsshipping' => $rates]; session()->put('marketplace_shipping_rates', $marketplaceShippingRates); @@ -103,8 +98,8 @@ public function calculate() array_push($shippingMethods, $object); } - if (isset ($marketplaceFedexShipping)) - { + if (isset ($marketplaceFedexShipping)) { + session()->put('marketplace_shipping_rates.mpupshipping', $marketplaceFedexShipping); } diff --git a/src/Config/system.php b/src/Config/system.php index 79a8b43..b29e706 100644 --- a/src/Config/system.php +++ b/src/Config/system.php @@ -13,13 +13,13 @@ 'type' => 'text', 'validation' => 'required', 'channel_based' => false, - 'locale_based' => true + 'locale_based' => true, ], [ 'name' => 'description', 'title' => 'ups::app.admin.system.description', 'type' => 'textarea', 'channel_based' => false, - 'locale_based' => true + 'locale_based' => true, ], [ 'name' => 'ups_active', 'title' => 'ups::app.admin.system.status', @@ -32,10 +32,10 @@ 'options' => [ [ 'title' => 'Development', - 'value' => 'DEVELOPMENT' + 'value' => 'DEVELOPMENT', ], [ 'title' => 'Live', - 'value' => "LIVE" + 'value' => "LIVE", ] ], ], [ @@ -44,27 +44,27 @@ 'type' => 'text', 'validation' => 'required', 'channel_based' => false, - 'locale_based' => true + 'locale_based' => true, ], [ 'name' => 'user_id', 'title' => 'ups::app.admin.system.user-id', 'type' => 'text', 'validation' => 'required', 'channel_based' => false, - 'locale_based' => true + 'locale_based' => true, ], [ 'name' => 'password', 'title' => 'ups::app.admin.system.password', 'type' => 'password', 'validation' => 'required', 'channel_based' => false, - 'locale_based' => true + 'locale_based' => true, ], [ 'name' => 'shipper_number', 'title' => 'ups::app.admin.system.shipper', 'type' => 'text', 'channel_based' => false, - 'locale_based' => true + 'locale_based' => true, ], [ 'name' => 'container', 'title' => 'ups::app.admin.system.container', @@ -78,16 +78,16 @@ 'value' => '02', ], [ 'title' => 'UPS Letter', - 'value' => '01' + 'value' => '01', ], [ 'title' => 'UPS Tube', - 'value' => '03' + 'value' => '03', ], [ 'title' => 'UPS Pak', - 'value' => '04' + 'value' => '04', ], [ 'title' => 'UPS Express Box', - 'value' => '21' + 'value' => '21', ], ], ], [ @@ -118,38 +118,37 @@ 'value' => '14', ], [ 'title' => 'Next Day Air', - 'value' => '01' + 'value' => '01', ], [ 'title' => 'Next Day Air Saver', - 'value' => '13' + 'value' => '13', ], [ 'title' => '2nd Day Air AM', - 'value' => '59' + 'value' => '59', ], [ 'title' => '2nd Day Air', - 'value' => '02' + 'value' => '02', ], [ 'title' => '3 Day Select', - 'value' => '12' + 'value' => '12', ], [ 'title' => 'Ups Ground', - 'value' => '03' + 'value' => '03', ], [ 'title' => 'UPS Worldwide Express', - 'value' => '07' + 'value' => '07', ], [ 'title' => 'UPS Worldwide Express Plus', - 'value' => '54' + 'value' => '54', ], [ 'title' => 'UPS Worldwide Expedited', - 'value' => '08' + 'value' => '08', ], [ 'title' => 'UPS World Wide Saver', - 'value' => '65' + 'value' => '65', ], - ], ], - ] + ], ], ]; \ No newline at end of file diff --git a/src/Helpers/ShippingMethodHelper.php b/src/Helpers/ShippingMethodHelper.php index 82883d8..1cdb8f5 100644 --- a/src/Helpers/ShippingMethodHelper.php +++ b/src/Helpers/ShippingMethodHelper.php @@ -9,7 +9,6 @@ use Webkul\UpsShipping\Repositories\UpsRepository as UpsRepository; use Webkul\Core\Repositories\ChannelRepository as Channel; - class ShippingMethodHelper { /** @@ -37,7 +36,9 @@ class ShippingMethodHelper * Create a new controller instance. * * @param \Webkul\Checkout\Repositories\CartAddressRepository $cartAddress; + * * @param \Webkul\Core\Repositories\ChannelRepository $channel + * * @param \Webkul\Shipping\Repositories\UpsRepository $upsRepository; */ public function __construct( @@ -46,19 +47,14 @@ public function __construct( protected Channel $channel ) { - $this->_config = request('_config'); - - $this->cartAddress = $cartAddress; - - $this->upsRepository = $upsRepository; - - $this->channel = $channel; } /** * display methods * * @return array + * + * @param $address */ public function getAllCartProducts($address) { @@ -72,6 +68,7 @@ public function getAllCartProducts($address) * * @param string $wsdl * @param bool|int $trace + * @param $address * @return \SoapClient */ protected function _createSoapClient($address) @@ -86,33 +83,30 @@ protected function _createSoapClient($address) $adminCompany = $adminData->hostname; - if (! core()->getConfigData('sales.carriers.ups.ups_active')) - { + if (! core()->getConfigData('sales.carriers.ups.ups_active')){ return false; + } else { $status = true; } - if ($status) - { + if ($status) { $sellerAdminData = $this->upsRepository->getSellerAdminData($cart->items()->get(), 'ups_postcode'); } $sellerAdminServices = $allServices = []; - foreach ($sellerAdminData as $cartProduct) - { + + foreach ($sellerAdminData as $cartProduct) { $sellerAdminServices[0] = explode(",", core()->getConfigData('sales.carriers.ups.services')); } - foreach ($sellerAdminData as $cartProduct) - { + foreach ($sellerAdminData as $cartProduct) { $weight = $this->getWeight($cartProduct->weight); $countryId = core()->getConfigData('sales.shipping.origin.country'); - if (! isset($cartProduct->marketplace_seller_id)) - { + if (! isset($cartProduct->marketplace_seller_id)) { //if admin's product $zoneInformation = core()->getConfigData('sales.shipping.origin.state'); $address1 = core()->getConfigData('sales.shipping.origin.address1'); @@ -145,8 +139,7 @@ protected function _createSoapClient($address) $shipment = $rateRequestXML->addChild ( 'Shipment' ); $shipper = $shipment->addChild ( 'Shipper' ); - if (! isset($cartProduct->marketplace_seller_id)) - { + if (! isset($cartProduct->marketplace_seller_id)) { $shipper->addChild ( "Name", $adminName ); $shipper->addChild ( "ShipperNumber", $shipperNumber ); @@ -172,12 +165,14 @@ protected function _createSoapClient($address) $shipToAddress = $shipTo->addChild ( 'Address' ); $shipToAddress->addChild ( "AddressLine1", $address->address1 ); $shipToAddress->addChild ( "City", $address->city ); - if ($address->country == 'PR') - { + + if ($address->country == 'PR') { + $shipToAddress->addChild ( "PostalCode", '00'. $address->postcode ); } else { $shipToAddress->addChild ( "PostalCode", $address->postcode ); } + $shipToAddress->addChild ( "CountryCode", $address->country ); $package = $shipment->addChild ( 'Package' ); $packageType = $package->addChild ( 'PackagingType' ); @@ -206,6 +201,7 @@ protected function _createSoapClient($address) "Cache-Control: no-cache", "Pragma: no-cache", )); + curl_setopt($ch, CURLOPT_POSTFIELDS,$requestXML); $response = curl_exec($ch); @@ -216,22 +212,21 @@ protected function _createSoapClient($address) $upsServices = json_decode(json_encode($upsServiceArray)); - if ( isset($cartProduct->marketplace_seller_id)) - { + if ( isset($cartProduct->marketplace_seller_id)) { $sellerId = $cartProduct->marketplace_seller_id; + } else { $sellerId = 0; } - if ($response) - { + if ($response) { + if ( isset($upsServices->Response->ResponseStatusDescription) - && $upsServices->Response->ResponseStatusDescription == 'Success') - { - if ( isset($upsServices->RatedShipment)) - { - foreach ($upsServices->RatedShipment as $services) - { + && $upsServices->Response->ResponseStatusDescription == 'Success') { + + if ( isset($upsServices->RatedShipment)) { + + foreach ($upsServices->RatedShipment as $services) { $serviceCode = $services->Service->Code; @@ -239,8 +234,7 @@ protected function _createSoapClient($address) $serviceName = $this->getServiceName($serviceCode); - if ($matchResult) - { + if ($matchResult) { $cartProductServices[$serviceName] = [ 'classId' => $serviceCode, 'rate' => $services->RatedPackage->TotalCharges->MonetaryValue, @@ -254,8 +248,7 @@ protected function _createSoapClient($address) } - if ( !empty($cartProductServices)) - { + if ( !empty($cartProductServices)) { $allServices[] = $cartProductServices; } } @@ -276,7 +269,9 @@ protected function _createSoapClient($address) if ( !empty($allServices) ) { return $this->upsRepository->getCommonMethods($allServices); + } else { + return false; } } @@ -308,13 +303,11 @@ protected function getServiceName($serviceCode) '85' => 'Today Express', '86' => 'Today Express Saver', '03' => 'Ups Ground', - ]; - foreach ($mapServices as $key => $service) - { - if ($key == $serviceCode) - { + foreach ($mapServices as $key => $service){ + + if ($key == $serviceCode) { return $service; } } @@ -329,22 +322,21 @@ protected function getServiceName($serviceCode) **/ public function getWeight($weight) { - $coreWeightUnit = strtoupper(core()->getConfigData('general.general.locale_options.weight_unit')); $upsWeightUnit = strtoupper(core()->getConfigData('sales.carriers.ups.weight_unit')); $convertedWeight = ''; - if ($coreWeightUnit == 'LBS') - { - if ($upsWeightUnit == 'LBS') - { + if ($coreWeightUnit == 'LBS') { + + if ($upsWeightUnit == 'LBS') { + $convertedWeight = $weight; + } else { //kgs to lbs $convertedWeight = $weight/0.45359237; - } } else { $convertedWeight = $weight/0.45359237; @@ -360,16 +352,15 @@ public function getWeight($weight) **/ public function getErrorLog($errors) { + foreach ($errors->Response->Error as $errorLog){ - foreach ($errors->Response->Error as $errorLog) - { $exception[] = $errorLog->ErrorDescription; } $status = $errors->Response->ResponseStatusDescription; - if (gettype($errors->Response->Error) !== 'array') - { + if (gettype($errors->Response->Error) !== 'array') { + $status = $errors->Response->Error->ErrorSeverity; $exception[] = $errors->Response->Error->ErrorDescription; diff --git a/src/Repositories/UpsRepository.php b/src/Repositories/UpsRepository.php index 5604eeb..396a230 100644 --- a/src/Repositories/UpsRepository.php +++ b/src/Repositories/UpsRepository.php @@ -2,12 +2,6 @@ namespace Webkul\UpsShipping\Repositories; -/** - * UPS Reposotory - * - * @author Naresh Verma - * @copyright 2019 Webkul Software Pvt Ltd (http://www.webkul.com) - */ class UpsRepository { /** @@ -17,46 +11,47 @@ class UpsRepository */ protected $productRepository; - /** * Get the Admin Product * + * @param $cartItems + * * @return mixed */ public function getSellerAdminData($cartItems) { $adminProducts = []; - foreach ($cartItems as $item) - { + foreach ($cartItems as $item) { array_push($adminProducts, $item); } return $adminProducts; } - /** * Get the Allowde Services * @param $allowedServices + * @param $service * @return $secvices */ public function validateAllowedMethods($service, $allowedServices) { $count = 0; + $totalCount = count($allowedServices); - foreach ($allowedServices as $methods) - { - if ( in_array($service, $methods) ) - { + foreach ($allowedServices as $methods) { + + if ( in_array($service, $methods) ) { $count += 1; } } - if ( $count == $totalCount ) - { + if ( $count == $totalCount ) { + return true; } + return false; } @@ -68,15 +63,15 @@ public function getAllowedMethods($allServices) { $allowedServices = explode(",", core()->getConfigData('sales.carriers.ups.ups_services')); - foreach ($allServices as $services) - { + foreach ($allServices as $services) { + $allowedMethod =[]; - foreach ($services as $service) - { - foreach ($service as $serviceType =>$upsService) - { - if (in_array($serviceType , $allowedServices)) - { + foreach ($services as $service) { + + foreach ($service as $serviceType =>$upsService) { + + if (in_array($serviceType , $allowedServices)) { + $allowedMethod[] = [ $serviceType => $upsService ]; @@ -88,22 +83,20 @@ public function getAllowedMethods($allServices) } } - if ($allowedMethod == null) - { + if ($allowedMethod == null) { + continue; } $allowedMethods[] = $allowedMethod; - } - if (isset($allowedMethods)) - { + if (isset($allowedMethods)) { + return $this->getCommonMethods($allowedMethods); } - return false; - - } + return false; + } /** * get the Common method @@ -114,10 +107,10 @@ public function getCommonMethods($methods) { $countMethods = count($methods); - foreach ($methods as $fedexMethods) - { - foreach ($fedexMethods as $key => $fedexMethod) - { + foreach ($methods as $fedexMethods) { + + foreach ($fedexMethods as $key => $fedexMethod) { + $avilableServicesArray[] = $key; } } @@ -125,29 +118,30 @@ public function getCommonMethods($methods) $countServices = array_count_values($avilableServicesArray); $finalServices = []; - foreach ($countServices as $serviceType => $servicesCount) - { - foreach ($methods as $fedexMethods) - { + foreach ($countServices as $serviceType => $servicesCount) { + + foreach ($methods as $fedexMethods) { + foreach ($fedexMethods as $type => $fedexMethod) { - if ($serviceType == $type && $servicesCount == $countMethods) - { + if ($serviceType == $type && $servicesCount == $countMethods) { + $finalServices[$serviceType][] =$fedexMethod; } } } - if ($finalServices == null) - { + if ($finalServices == null) { + continue; } } - if (empty($finalServices)) - { + if (empty($finalServices)) { + return false; } + return $finalServices; } } From e4b0c14f6bf8056f3f075ccebb948b8662253886 Mon Sep 17 00:00:00 2001 From: antu chaudhary Date: Fri, 5 Jan 2024 12:50:44 +0530 Subject: [PATCH 4/8] some changes in upsshipping v2.0 --- README.md | 2 +- src/Carriers/Ups.php | 63 +++++++++------------ src/Config/system.php | 4 +- src/Helpers/ShippingMethodHelper.php | 82 +++++++++------------------- src/Repositories/UpsRepository.php | 21 ++----- src/Resources/lang/ar/app.php | 2 +- src/Resources/lang/bn/app.php | 2 +- src/Resources/lang/de/app.php | 2 +- src/Resources/lang/en/app.php | 2 +- src/Resources/lang/es/app.php | 2 +- src/Resources/lang/fa/app.php | 2 +- src/Resources/lang/fr/app.php | 2 +- src/Resources/lang/he/app.php | 2 +- src/Resources/lang/hi_IN/app.php | 2 +- src/Resources/lang/it/app.php | 2 +- src/Resources/lang/ja/app.php | 2 +- src/Resources/lang/nl/app.php | 2 +- src/Resources/lang/pl/app.php | 2 +- src/Resources/lang/pt_BR/app.php | 2 +- src/Resources/lang/ru/app.php | 2 +- src/Resources/lang/sin/app.php | 2 +- src/Resources/lang/tr/app.php | 2 +- src/Resources/lang/uk/app.php | 2 +- src/Resources/lang/zh_CN/app.php | 2 +- 24 files changed, 79 insertions(+), 131 deletions(-) diff --git a/README.md b/README.md index 04d4398..4ca82d1 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ It packs in lots of demanding features that allows your business to scale in no ### 2. Requirements: -* **Bagisto**: v0.1.6 or higher. +* **Bagisto**: v2.0.0 ### 3. Installation: diff --git a/src/Carriers/Ups.php b/src/Carriers/Ups.php index 4d1a789..1ecbce5 100644 --- a/src/Carriers/Ups.php +++ b/src/Carriers/Ups.php @@ -13,60 +13,53 @@ class Ups extends AbstractShipping * Payment method code * * @var string - */ + */ protected $code = 'ups'; /** - * Returns rate for flatrate + * Returns rate for ups * * @return array - */ + */ public function calculate() { - $uspsMethod = ''; - - $shippingMethods = []; - - $rates = []; + if (! $this->isAvailable()) { + return false; + } - $shippingHelper = app(ShippingMethodHelper::class); + $shippingMethods = $rates = []; $cart = Cart::getCart(); - + $address = $cart->shipping_address; - - $cartProducts = $shippingHelper->getAllCartProducts($address); + + $cartProducts = app(ShippingMethodHelper::class)->getAllCartProducts($address); $marketplaceShipping = session()->get('marketplace_shipping_rates'); - if (! $this->isAvailable()){ - - return false; - } - if (isset ($cartProducts) && $cartProducts == true) { + if (isset($cartProducts) + && $cartProducts == true) { foreach ($cartProducts as $key => $fedexServices) { - $rate = 0; - $totalShippingCost = 0; - $upsMethod = $key; - $methodCode = $key; + $rate = $totalShippingCost = 0; + $upsMethod = $methodCode = $key; foreach ($fedexServices as $methods => $upsRate) { - $rate += $upsRate['rate'] * $upsRate['itemQuantity']; + $sellerId = $upsRate['marketplace_seller_id']; - $itemShippingCost = $upsRate['rate'] * $upsRate['itemQuantity']; + $itemShippingCost = $upsRate['rate'] * $upsRate['itemQuantity']; $rates[$key][$sellerId] = [ - 'amount' => core()->convertPrice($itemShippingCost), - 'base_amount' => $itemShippingCost + 'amount' => core()->convertPrice($itemShippingCost), + 'base_amount' => $itemShippingCost, ]; - if (isset ($rates[$key][$sellerId])) { + if (isset($rates[$key][$sellerId])) { $rates[$key][$sellerId] = [ - 'amount' => core()->convertPrice($rates[$key][$sellerId]['amount'] + $itemShippingCost), - 'base_amount' => $rates[$key][$sellerId]['base_amount'] + $itemShippingCost + 'amount' => core()->convertPrice($rates[$key][$sellerId]['amount'] + $itemShippingCost), + 'base_amount' => $rates[$key][$sellerId]['base_amount'] + $itemShippingCost, ]; } @@ -76,21 +69,18 @@ public function calculate() $object = new CartShippingRate; $object->carrier = 'mpups'; - $object->carrier_title = $this->getConfigData('title'); - $object->method = 'mpups_' . '' . $methodCode; - $object->method_title = $this->getConfigData('title'); + $object->carrier_title = $this->getConfigData('title'); + $object->method = 'mpups_' . '' . $methodCode; + $object->method_title = $this->getConfigData('title'); $object->method_description = $upsMethod; - $object->price = core()->convertPrice($totalShippingCost); $object->base_price = $totalShippingCost; $marketplaceShippingRates = session()->get('marketplace_shipping_rates'); if (! is_array($marketplaceShipping)) { - $marketplaceShippingRates['mpupsshipping'] = ['mpupsshipping' => $rates]; session()->put('marketplace_shipping_rates', $marketplaceShippingRates); - } else { $marketplaceFedexShipping = ['mpupshipping' => $rates]; } @@ -98,12 +88,11 @@ public function calculate() array_push($shippingMethods, $object); } - if (isset ($marketplaceFedexShipping)) { - + if (isset($marketplaceFedexShipping)) { session()->put('marketplace_shipping_rates.mpupshipping', $marketplaceFedexShipping); } return $shippingMethods; } } -} +} \ No newline at end of file diff --git a/src/Config/system.php b/src/Config/system.php index b29e706..1180c09 100644 --- a/src/Config/system.php +++ b/src/Config/system.php @@ -36,7 +36,7 @@ ], [ 'title' => 'Live', 'value' => "LIVE", - ] + ], ], ], [ 'name' => 'access_license_key', @@ -104,7 +104,7 @@ ], [ 'title' => 'KGS', 'value' => 'KGS', - ] + ], ], ], [ 'name' => 'services', diff --git a/src/Helpers/ShippingMethodHelper.php b/src/Helpers/ShippingMethodHelper.php index 1cdb8f5..1de4449 100644 --- a/src/Helpers/ShippingMethodHelper.php +++ b/src/Helpers/ShippingMethodHelper.php @@ -11,13 +11,6 @@ class ShippingMethodHelper { - /** - * Contains route related configuration - * - * @var array - */ - protected $_config; - /** * RateServiceWsdl * @@ -36,9 +29,7 @@ class ShippingMethodHelper * Create a new controller instance. * * @param \Webkul\Checkout\Repositories\CartAddressRepository $cartAddress; - * * @param \Webkul\Core\Repositories\ChannelRepository $channel - * * @param \Webkul\Shipping\Repositories\UpsRepository $upsRepository; */ public function __construct( @@ -50,28 +41,25 @@ public function __construct( } /** - * display methods + * display cart products * - * @return array - * * @param $address + * + * @return array */ public function getAllCartProducts($address) { - $data = $this->_createSoapClient($address); - - return $data; + return $this->createSoapClient($address); } /** * Soap client for wsdl * - * @param string $wsdl - * @param bool|int $trace * @param $address + * * @return \SoapClient */ - protected function _createSoapClient($address) + protected function createSoapClient($address) { $cart = Cart::getCart(); @@ -83,17 +71,12 @@ protected function _createSoapClient($address) $adminCompany = $adminData->hostname; - if (! core()->getConfigData('sales.carriers.ups.ups_active')){ + if (! core()->getConfigData('sales.carriers.ups.ups_active')) { return false; - - } else { - $status = true; } - if ($status) { - $sellerAdminData = $this->upsRepository->getSellerAdminData($cart->items()->get(), 'ups_postcode'); - } + $sellerAdminData = $this->upsRepository->getSellerAdminData($cart->items()->get(), 'ups_postcode'); $sellerAdminServices = $allServices = []; @@ -167,8 +150,8 @@ protected function _createSoapClient($address) $shipToAddress->addChild ( "City", $address->city ); if ($address->country == 'PR') { - $shipToAddress->addChild ( "PostalCode", '00'. $address->postcode ); + } else { $shipToAddress->addChild ( "PostalCode", $address->postcode ); } @@ -203,7 +186,7 @@ protected function _createSoapClient($address) )); curl_setopt($ch, CURLOPT_POSTFIELDS,$requestXML); - + $response = curl_exec($ch); curl_close($ch); @@ -212,22 +195,19 @@ protected function _createSoapClient($address) $upsServices = json_decode(json_encode($upsServiceArray)); - if ( isset($cartProduct->marketplace_seller_id)) { + if (isset($cartProduct->marketplace_seller_id)) { $sellerId = $cartProduct->marketplace_seller_id; - } else { $sellerId = 0; } if ($response) { - - if ( isset($upsServices->Response->ResponseStatusDescription) + if (isset($upsServices->Response->ResponseStatusDescription) && $upsServices->Response->ResponseStatusDescription == 'Success') { - if ( isset($upsServices->RatedShipment)) { + if (isset($upsServices->RatedShipment)) { foreach ($upsServices->RatedShipment as $services) { - $serviceCode = $services->Service->Code; $matchResult = $this->upsRepository->validateAllowedMethods($serviceCode, $sellerAdminServices); @@ -236,19 +216,19 @@ protected function _createSoapClient($address) if ($matchResult) { $cartProductServices[$serviceName] = [ - 'classId' => $serviceCode, - 'rate' => $services->RatedPackage->TotalCharges->MonetaryValue, - 'currency' => $services->RatedPackage->TotalCharges->CurrencyCode, - 'weight' => $services->BillingWeight->Weight, - 'weightUnit' => $services->BillingWeight->UnitOfMeasurement->Code, + 'classId' => $serviceCode, + 'rate' => $services->RatedPackage->TotalCharges->MonetaryValue, + 'currency' => $services->RatedPackage->TotalCharges->CurrencyCode, + 'weight' => $services->BillingWeight->Weight, + 'weightUnit' => $services->BillingWeight->UnitOfMeasurement->Code, 'marketplace_seller_id' => $sellerId, - 'itemQuantity' => $cartProduct->quantity + 'itemQuantity' => $cartProduct->quantity, ]; } } - if ( !empty($cartProductServices)) { + if (! empty($cartProductServices)) { $allServices[] = $cartProductServices; } } @@ -256,27 +236,21 @@ protected function _createSoapClient($address) } else { $errorLog = $this->getErrorLog($upsServices); - return false; - //to check the error generated in the method; + return false; //to check the error generated in the method; } } } catch (\Exception $e) { - return false; } } - if ( !empty($allServices) ) - { + if (! empty($allServices) ) { return $this->upsRepository->getCommonMethods($allServices); - } else { - return false; } } - /** * Map service code * @@ -305,13 +279,12 @@ protected function getServiceName($serviceCode) '03' => 'Ups Ground', ]; - foreach ($mapServices as $key => $service){ + foreach ($mapServices as $key => $service) { if ($key == $serviceCode) { return $service; } } - return $serviceCode; } @@ -331,9 +304,7 @@ public function getWeight($weight) if ($coreWeightUnit == 'LBS') { if ($upsWeightUnit == 'LBS') { - $convertedWeight = $weight; - } else { //kgs to lbs $convertedWeight = $weight/0.45359237; @@ -341,7 +312,6 @@ public function getWeight($weight) } else { $convertedWeight = $weight/0.45359237; } - return $convertedWeight; } @@ -352,15 +322,13 @@ public function getWeight($weight) **/ public function getErrorLog($errors) { - foreach ($errors->Response->Error as $errorLog){ - + foreach ($errors->Response->Error as $errorLog) { $exception[] = $errorLog->ErrorDescription; } $status = $errors->Response->ResponseStatusDescription; - if (gettype($errors->Response->Error) !== 'array') { - + if (gettype($errors->Response->Error) !== 'array') { $status = $errors->Response->Error->ErrorSeverity; $exception[] = $errors->Response->Error->ErrorDescription; diff --git a/src/Repositories/UpsRepository.php b/src/Repositories/UpsRepository.php index 396a230..07964e9 100644 --- a/src/Repositories/UpsRepository.php +++ b/src/Repositories/UpsRepository.php @@ -33,6 +33,7 @@ public function getSellerAdminData($cartItems) * Get the Allowde Services * @param $allowedServices * @param $service + * * @return $secvices */ public function validateAllowedMethods($service, $allowedServices) @@ -59,19 +60,16 @@ public function validateAllowedMethods($service, $allowedServices) * Get the Common Services for all the cartProduct * @param $allServices */ - public function getAllowedMethods($allServices) - { - $allowedServices = explode(",", core()->getConfigData('sales.carriers.ups.ups_services')); + public function getAllowedMethods($allServices) { - foreach ($allServices as $services) { + $allowedServices = explode(",", core()->getConfigData('sales.carriers.ups.services')); + foreach ($allServices as $services) { $allowedMethod =[]; foreach ($services as $service) { foreach ($service as $serviceType =>$upsService) { - if (in_array($serviceType , $allowedServices)) { - $allowedMethod[] = [ $serviceType => $upsService ]; @@ -84,14 +82,12 @@ public function getAllowedMethods($allServices) } if ($allowedMethod == null) { - continue; } $allowedMethods[] = $allowedMethod; } if (isset($allowedMethods)) { - return $this->getCommonMethods($allowedMethods); } @@ -110,7 +106,6 @@ public function getCommonMethods($methods) foreach ($methods as $fedexMethods) { foreach ($fedexMethods as $key => $fedexMethod) { - $avilableServicesArray[] = $key; } } @@ -122,23 +117,19 @@ public function getCommonMethods($methods) foreach ($methods as $fedexMethods) { - foreach ($fedexMethods as $type => $fedexMethod) - { - if ($serviceType == $type && $servicesCount == $countMethods) { + foreach ($fedexMethods as $type => $fedexMethod) { + if ($serviceType == $type && $servicesCount == $countMethods) { $finalServices[$serviceType][] =$fedexMethod; } } } - if ($finalServices == null) { - continue; } } if (empty($finalServices)) { - return false; } diff --git a/src/Resources/lang/ar/app.php b/src/Resources/lang/ar/app.php index ff7c3e2..b83b9f0 100755 --- a/src/Resources/lang/ar/app.php +++ b/src/Resources/lang/ar/app.php @@ -19,5 +19,5 @@ 'size' => 'الحجم', 'allowed-methods' => 'الخدمات المسموح بها', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/bn/app.php b/src/Resources/lang/bn/app.php index 00a1301..d7e81c4 100644 --- a/src/Resources/lang/bn/app.php +++ b/src/Resources/lang/bn/app.php @@ -19,5 +19,5 @@ 'size' => 'আকার', 'allowed-methods' => 'অনুমোদিত সেবাসমূহ', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/de/app.php b/src/Resources/lang/de/app.php index 71bf7c4..aab7b71 100755 --- a/src/Resources/lang/de/app.php +++ b/src/Resources/lang/de/app.php @@ -19,5 +19,5 @@ 'size' => 'Größe', 'allowed-methods' => 'Erlaubte Dienste', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/en/app.php b/src/Resources/lang/en/app.php index f8ae9e6..f46b45f 100644 --- a/src/Resources/lang/en/app.php +++ b/src/Resources/lang/en/app.php @@ -19,5 +19,5 @@ 'size' => 'Size', 'allowed-methods' => 'Allowed Services', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/es/app.php b/src/Resources/lang/es/app.php index d5141df..180a3c1 100755 --- a/src/Resources/lang/es/app.php +++ b/src/Resources/lang/es/app.php @@ -19,5 +19,5 @@ 'size' => 'Tamaño', 'allowed-methods' => 'Servicios permitidos', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/fa/app.php b/src/Resources/lang/fa/app.php index cd0ac79..edd0fbc 100755 --- a/src/Resources/lang/fa/app.php +++ b/src/Resources/lang/fa/app.php @@ -19,5 +19,5 @@ 'size' => 'اندازه', 'allowed-methods' => 'خدمات مجاز', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/fr/app.php b/src/Resources/lang/fr/app.php index 35c7330..838aa85 100755 --- a/src/Resources/lang/fr/app.php +++ b/src/Resources/lang/fr/app.php @@ -19,5 +19,5 @@ 'size' => 'Taille', 'allowed-methods' => 'Services autorisés', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/he/app.php b/src/Resources/lang/he/app.php index e3cb7f2..5093454 100755 --- a/src/Resources/lang/he/app.php +++ b/src/Resources/lang/he/app.php @@ -19,5 +19,5 @@ 'size' => 'גודל', 'allowed-methods' => 'שירותים מורשים', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/hi_IN/app.php b/src/Resources/lang/hi_IN/app.php index a6fbdef..97018ed 100755 --- a/src/Resources/lang/hi_IN/app.php +++ b/src/Resources/lang/hi_IN/app.php @@ -19,5 +19,5 @@ 'size' => 'आकार', 'allowed-methods' => 'अनुमत सेवाएं', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/it/app.php b/src/Resources/lang/it/app.php index bd350ce..a7cd36c 100755 --- a/src/Resources/lang/it/app.php +++ b/src/Resources/lang/it/app.php @@ -19,5 +19,5 @@ 'size' => 'Dimensione', 'allowed-methods' => 'Servizi consentiti', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/ja/app.php b/src/Resources/lang/ja/app.php index cb22204..2860fcf 100755 --- a/src/Resources/lang/ja/app.php +++ b/src/Resources/lang/ja/app.php @@ -19,5 +19,5 @@ 'size' => 'サイズ', 'allowed-methods' => '許可されたサービス', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/nl/app.php b/src/Resources/lang/nl/app.php index c71313b..186813a 100755 --- a/src/Resources/lang/nl/app.php +++ b/src/Resources/lang/nl/app.php @@ -19,5 +19,5 @@ 'size' => 'Grootte', 'allowed-methods' => 'Toegestane Diensten', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/pl/app.php b/src/Resources/lang/pl/app.php index 2ef9bc2..30e8f9a 100755 --- a/src/Resources/lang/pl/app.php +++ b/src/Resources/lang/pl/app.php @@ -19,5 +19,5 @@ 'size' => 'Rozmiar', 'allowed-methods' => 'Dozwolone Usługi', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/pt_BR/app.php b/src/Resources/lang/pt_BR/app.php index e596caf..32918f8 100755 --- a/src/Resources/lang/pt_BR/app.php +++ b/src/Resources/lang/pt_BR/app.php @@ -19,5 +19,5 @@ 'size' => 'Tamanho', 'allowed-methods' => 'Serviços Permitidos', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/ru/app.php b/src/Resources/lang/ru/app.php index 1d9192e..caed43d 100755 --- a/src/Resources/lang/ru/app.php +++ b/src/Resources/lang/ru/app.php @@ -19,5 +19,5 @@ 'size' => 'Размер', 'allowed-methods' => 'Разрешенные услуги', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/sin/app.php b/src/Resources/lang/sin/app.php index fe6322e..abd8b70 100755 --- a/src/Resources/lang/sin/app.php +++ b/src/Resources/lang/sin/app.php @@ -19,5 +19,5 @@ 'size' => 'තරම', 'allowed-methods' => 'සමාවෙන සේවාවන්', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/tr/app.php b/src/Resources/lang/tr/app.php index f7a9ef0..ad38620 100755 --- a/src/Resources/lang/tr/app.php +++ b/src/Resources/lang/tr/app.php @@ -19,5 +19,5 @@ 'size' => 'Boyut', 'allowed-methods' => 'İzin Verilen Hizmetler', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/uk/app.php b/src/Resources/lang/uk/app.php index 7831ebc..6696e1c 100755 --- a/src/Resources/lang/uk/app.php +++ b/src/Resources/lang/uk/app.php @@ -19,5 +19,5 @@ 'size' => 'Розмір', 'allowed-methods' => 'Дозволені послуги', ], - ] + ], ]; \ No newline at end of file diff --git a/src/Resources/lang/zh_CN/app.php b/src/Resources/lang/zh_CN/app.php index 0802feb..ab90f59 100755 --- a/src/Resources/lang/zh_CN/app.php +++ b/src/Resources/lang/zh_CN/app.php @@ -19,5 +19,5 @@ 'size' => '尺寸', 'allowed-methods' => '允许的服务', ], - ] + ], ]; \ No newline at end of file From 0bf6e7466706ed2bce231aeba9803c31bdab931d Mon Sep 17 00:00:00 2001 From: antu chaudhary Date: Fri, 5 Jan 2024 13:15:47 +0530 Subject: [PATCH 5/8] some changes in upsshipping v2.0 --- src/Carriers/Ups.php | 6 ++---- src/Helpers/ShippingMethodHelper.php | 12 ++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Carriers/Ups.php b/src/Carriers/Ups.php index 1ecbce5..a9176a8 100644 --- a/src/Carriers/Ups.php +++ b/src/Carriers/Ups.php @@ -13,7 +13,7 @@ class Ups extends AbstractShipping * Payment method code * * @var string - */ + */ protected $code = 'ups'; /** @@ -37,9 +37,7 @@ public function calculate() $marketplaceShipping = session()->get('marketplace_shipping_rates'); - if (isset($cartProducts) - && $cartProducts == true) { - + if (isset($cartProducts)) { foreach ($cartProducts as $key => $fedexServices) { $rate = $totalShippingCost = 0; $upsMethod = $methodCode = $key; diff --git a/src/Helpers/ShippingMethodHelper.php b/src/Helpers/ShippingMethodHelper.php index 1de4449..391e61e 100644 --- a/src/Helpers/ShippingMethodHelper.php +++ b/src/Helpers/ShippingMethodHelper.php @@ -61,6 +61,10 @@ public function getAllCartProducts($address) */ protected function createSoapClient($address) { + if (! core()->getConfigData('sales.carriers.ups.ups_active')) { + return false; + } + $cart = Cart::getCart(); $defaultChannel = core()->getCurrentChannelCode(); @@ -71,11 +75,6 @@ protected function createSoapClient($address) $adminCompany = $adminData->hostname; - if (! core()->getConfigData('sales.carriers.ups.ups_active')) { - - return false; - } - $sellerAdminData = $this->upsRepository->getSellerAdminData($cart->items()->get(), 'ups_postcode'); $sellerAdminServices = $allServices = []; @@ -280,11 +279,11 @@ protected function getServiceName($serviceCode) ]; foreach ($mapServices as $key => $service) { - if ($key == $serviceCode) { return $service; } } + return $serviceCode; } @@ -312,6 +311,7 @@ public function getWeight($weight) } else { $convertedWeight = $weight/0.45359237; } + return $convertedWeight; } From 940103a05518b36ab74eaa2042921778f58ca233 Mon Sep 17 00:00:00 2001 From: antu chaudhary Date: Mon, 15 Apr 2024 18:34:44 +0530 Subject: [PATCH 6/8] update the ups shipping module in v2.0 --- CHANGELOG for v1.3.x.md | 7 - ...G for v0.1.x.md => CHANGELOG for v2.0.0.md | 4 +- LICENSE | 21 - README.md | 6 +- package.json | 23 - packages/Webkul/UpsShipping/.gitignore | 3 + .../Webkul/UpsShipping/composer.json | 15 +- packages/Webkul/UpsShipping/package.json | 13 + packages/Webkul/UpsShipping/postcss.config.js | 6 + .../Webkul/UpsShipping/src}/Carriers/Ups.php | 56 ++- .../UpsShipping/src/Config/carriers.php | 11 + .../Webkul/UpsShipping/src}/Config/system.php | 110 ++-- .../src}/Helpers/ShippingMethodHelper.php | 196 ++++---- .../Providers/UpsShippingServiceProvider.php | 5 + .../src/Repositories/UpsRepository.php | 95 ++++ .../src/Resources/assets/css/app.css | 3 + .../src/Resources/assets/js/app.js | 4 + .../src}/Resources/lang/ar/app.php | 0 .../src}/Resources/lang/bn/app.php | 0 .../src}/Resources/lang/de/app.php | 0 .../src}/Resources/lang/en/app.php | 0 .../src}/Resources/lang/es/app.php | 0 .../src}/Resources/lang/fa/app.php | 0 .../src}/Resources/lang/fr/app.php | 0 .../src}/Resources/lang/he/app.php | 0 .../src}/Resources/lang/hi_IN/app.php | 0 .../src}/Resources/lang/it/app.php | 0 .../src}/Resources/lang/ja/app.php | 0 .../src}/Resources/lang/nl/app.php | 0 .../src}/Resources/lang/pl/app.php | 0 .../src}/Resources/lang/pt_BR/app.php | 0 .../src}/Resources/lang/ru/app.php | 0 .../src}/Resources/lang/sin/app.php | 0 .../src}/Resources/lang/tr/app.php | 0 .../src}/Resources/lang/uk/app.php | 0 .../src}/Resources/lang/zh_CN/app.php | 0 .../views/configurations/field-type.blade.php | 473 ++++++++++++++++++ .../Webkul/UpsShipping/tailwind.config.js | 10 + packages/Webkul/UpsShipping/vite.config.js | 43 ++ src/Config/carriers.php | 11 - src/Repositories/UpsRepository.php | 139 ----- webpack.mix.js | 19 - 42 files changed, 858 insertions(+), 415 deletions(-) delete mode 100644 CHANGELOG for v1.3.x.md rename CHANGELOG for v0.1.x.md => CHANGELOG for v2.0.0.md (88%) delete mode 100644 LICENSE delete mode 100644 package.json create mode 100644 packages/Webkul/UpsShipping/.gitignore rename composer.json => packages/Webkul/UpsShipping/composer.json (58%) create mode 100644 packages/Webkul/UpsShipping/package.json create mode 100644 packages/Webkul/UpsShipping/postcss.config.js rename {src => packages/Webkul/UpsShipping/src}/Carriers/Ups.php (72%) create mode 100755 packages/Webkul/UpsShipping/src/Config/carriers.php rename {src => packages/Webkul/UpsShipping/src}/Config/system.php (55%) rename {src => packages/Webkul/UpsShipping/src}/Helpers/ShippingMethodHelper.php (75%) rename {src => packages/Webkul/UpsShipping/src}/Providers/UpsShippingServiceProvider.php (81%) create mode 100644 packages/Webkul/UpsShipping/src/Repositories/UpsRepository.php create mode 100644 packages/Webkul/UpsShipping/src/Resources/assets/css/app.css create mode 100644 packages/Webkul/UpsShipping/src/Resources/assets/js/app.js rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/ar/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/bn/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/de/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/en/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/es/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/fa/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/fr/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/he/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/hi_IN/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/it/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/ja/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/nl/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/pl/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/pt_BR/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/ru/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/sin/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/tr/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/uk/app.php (100%) rename {src => packages/Webkul/UpsShipping/src}/Resources/lang/zh_CN/app.php (100%) create mode 100644 packages/Webkul/UpsShipping/src/Resources/views/configurations/field-type.blade.php create mode 100644 packages/Webkul/UpsShipping/tailwind.config.js create mode 100644 packages/Webkul/UpsShipping/vite.config.js delete mode 100755 src/Config/carriers.php delete mode 100644 src/Repositories/UpsRepository.php delete mode 100644 webpack.mix.js diff --git a/CHANGELOG for v1.3.x.md b/CHANGELOG for v1.3.x.md deleted file mode 100644 index a10e212..0000000 --- a/CHANGELOG for v1.3.x.md +++ /dev/null @@ -1,7 +0,0 @@ -# CHANGELOG for v1.3.x - -#### This changelog consists the bug & security fixes and new features being included in the releases listed below. - -## **v1.3.3(10th of Jan, 2022)** - *Release* - -* [compatible] Compatible for v1.3.3 \ No newline at end of file diff --git a/CHANGELOG for v0.1.x.md b/CHANGELOG for v2.0.0.md similarity index 88% rename from CHANGELOG for v0.1.x.md rename to CHANGELOG for v2.0.0.md index 04aaf35..c59799a 100644 --- a/CHANGELOG for v0.1.x.md +++ b/CHANGELOG for v2.0.0.md @@ -1,8 +1,8 @@ -# CHANGELOG for v0.1.x +# CHANGELOG for v2.0.0 #### This changelog consists the bug & security fixes and new features being included in the releases listed below. -## **v0.1.0(23 of Feb, 2020)** - *Release* +## **v2.0.0** - *Development* * [feature] The admin can enable or disable the usps Shipping method. diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 4a07d99..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Bagisto - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.md b/README.md index 4ca82d1..4c3156e 100644 --- a/README.md +++ b/README.md @@ -45,11 +45,7 @@ composer dump-autoload ~~~ ~~~ -php artisan route:cache -~~~ - -~~~ -php artisan config:clear +php artisan optimize:clear ~~~ ~~~ diff --git a/package.json b/package.json deleted file mode 100644 index 782f295..0000000 --- a/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "private": true, - "scripts": { - "dev": "vite", - "build": "vite build" - }, - "devDependencies": { - "autoprefixer": "^10.4.14", - "axios": "^1.1.2", - "laravel-vite-plugin": "^0.7.2", - "postcss": "^8.4.23", - "tailwindcss": "^3.3.2", - "vite": "^4.0.0", - "vue": "^3.2.47" - }, - "dependencies": { - "@vee-validate/i18n": "^4.9.1", - "@vee-validate/rules": "^4.9.1", - "mitt": "^3.0.0", - "vee-validate": "^4.9.1", - "vue-flatpickr": "^2.3.0" - } -} diff --git a/packages/Webkul/UpsShipping/.gitignore b/packages/Webkul/UpsShipping/.gitignore new file mode 100644 index 0000000..2dc6ccf --- /dev/null +++ b/packages/Webkul/UpsShipping/.gitignore @@ -0,0 +1,3 @@ +/node_modules +/npm-debug.log +/package-lock.json \ No newline at end of file diff --git a/composer.json b/packages/Webkul/UpsShipping/composer.json similarity index 58% rename from composer.json rename to packages/Webkul/UpsShipping/composer.json index 576939a..57d68be 100644 --- a/composer.json +++ b/packages/Webkul/UpsShipping/composer.json @@ -1,18 +1,13 @@ { - "name": "bagisto/bagisto-ups-shipping", + "name": "bagisto/laravel-ups", "license": "MIT", "authors": [ { - "name": "Naresh Verma", - "email": "naresh.verma327@webkul.com" - }, { - "name": "Vivek Sharma", - "email": "viveksh047@webkul.com" + "name": "Bagisto", + "email": "support@bagisto.com" } ], - "require": { - "konekt/concord": "^1.2" - }, + "require": {}, "autoload": { "psr-4": { "Webkul\\UpsShipping\\": "src/" @@ -27,4 +22,4 @@ } }, "minimum-stability": "dev" -} \ No newline at end of file +} diff --git a/packages/Webkul/UpsShipping/package.json b/packages/Webkul/UpsShipping/package.json new file mode 100644 index 0000000..e69795f --- /dev/null +++ b/packages/Webkul/UpsShipping/package.json @@ -0,0 +1,13 @@ +{ + "private": true, + "scripts": { + "dev": "vite", + "build": "vite build" + }, + "devDependencies": { + "axios": "^1.4.0", + "laravel-vite-plugin": "^0.7.2", + "postcss": "^8.4.23", + "vite": "^4.0.0" + } +} \ No newline at end of file diff --git a/packages/Webkul/UpsShipping/postcss.config.js b/packages/Webkul/UpsShipping/postcss.config.js new file mode 100644 index 0000000..63889e7 --- /dev/null +++ b/packages/Webkul/UpsShipping/postcss.config.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +}; \ No newline at end of file diff --git a/src/Carriers/Ups.php b/packages/Webkul/UpsShipping/src/Carriers/Ups.php similarity index 72% rename from src/Carriers/Ups.php rename to packages/Webkul/UpsShipping/src/Carriers/Ups.php index a9176a8..7ae7f39 100644 --- a/src/Carriers/Ups.php +++ b/packages/Webkul/UpsShipping/src/Carriers/Ups.php @@ -2,25 +2,37 @@ namespace Webkul\UpsShipping\Carriers; +use Webkul\Checkout\Facades\Cart; use Webkul\Checkout\Models\CartShippingRate; use Webkul\Shipping\Carriers\AbstractShipping; use Webkul\UpsShipping\Helpers\ShippingMethodHelper; -use Webkul\Checkout\Facades\Cart; class Ups extends AbstractShipping { + /** + * The shipping method helper instance. + * + * @var \Webkul\UpsShipping\Helpers\ShippingMethodHelper $shippingMethodHelper + * @return void + */ + public function __construct( + protected ShippingMethodHelper $shippingMethodHelper, + ) + { + } + /** * Payment method code * * @var string */ - protected $code = 'ups'; + protected $code = 'ups'; /** - * Returns rate for ups + * Calculate shipping rates. * - * @return array - */ + * @return array|false + */ public function calculate() { if (! $this->isAvailable()) { @@ -30,34 +42,37 @@ public function calculate() $shippingMethods = $rates = []; $cart = Cart::getCart(); - + $address = $cart->shipping_address; - - $cartProducts = app(ShippingMethodHelper::class)->getAllCartProducts($address); + + $data = $this->shippingMethodHelper->getAllCartProducts($address); $marketplaceShipping = session()->get('marketplace_shipping_rates'); - if (isset($cartProducts)) { - foreach ($cartProducts as $key => $fedexServices) { + if (! $this->isAvailable()) + return false; + + if (isset ($data) && $data == true) { + foreach ($data as $key => $fedexServices) { $rate = $totalShippingCost = 0; - $upsMethod = $methodCode = $key; + + $upsMethod = $methodCode = $key; foreach ($fedexServices as $methods => $upsRate) { $rate += $upsRate['rate'] * $upsRate['itemQuantity']; - $sellerId = $upsRate['marketplace_seller_id']; - $itemShippingCost = $upsRate['rate'] * $upsRate['itemQuantity']; + $itemShippingCost = $upsRate['rate'] * $upsRate['itemQuantity']; $rates[$key][$sellerId] = [ 'amount' => core()->convertPrice($itemShippingCost), - 'base_amount' => $itemShippingCost, + 'base_amount' => $itemShippingCost ]; - if (isset($rates[$key][$sellerId])) { + if (isset ($rates[$key][$sellerId])) { $rates[$key][$sellerId] = [ 'amount' => core()->convertPrice($rates[$key][$sellerId]['amount'] + $itemShippingCost), - 'base_amount' => $rates[$key][$sellerId]['base_amount'] + $itemShippingCost, + 'base_amount' => $rates[$key][$sellerId]['base_amount'] + $itemShippingCost ]; } @@ -67,11 +82,17 @@ public function calculate() $object = new CartShippingRate; $object->carrier = 'mpups'; + $object->carrier_title = $this->getConfigData('title'); + $object->method = 'mpups_' . '' . $methodCode; + $object->method_title = $this->getConfigData('title'); + $object->method_description = $upsMethod; + $object->price = core()->convertPrice($totalShippingCost); + $object->base_price = $totalShippingCost; $marketplaceShippingRates = session()->get('marketplace_shipping_rates'); @@ -79,6 +100,7 @@ public function calculate() if (! is_array($marketplaceShipping)) { $marketplaceShippingRates['mpupsshipping'] = ['mpupsshipping' => $rates]; session()->put('marketplace_shipping_rates', $marketplaceShippingRates); + } else { $marketplaceFedexShipping = ['mpupshipping' => $rates]; } @@ -86,7 +108,7 @@ public function calculate() array_push($shippingMethods, $object); } - if (isset($marketplaceFedexShipping)) { + if (isset ($marketplaceFedexShipping)) { session()->put('marketplace_shipping_rates.mpupshipping', $marketplaceFedexShipping); } diff --git a/packages/Webkul/UpsShipping/src/Config/carriers.php b/packages/Webkul/UpsShipping/src/Config/carriers.php new file mode 100755 index 0000000..2244459 --- /dev/null +++ b/packages/Webkul/UpsShipping/src/Config/carriers.php @@ -0,0 +1,11 @@ + [ + 'code' => 'ups', + 'title' => 'UPS Shipping', + 'description' => 'UPS Shipping', + 'active' => true, + 'class' => 'Webkul\UpsShipping\Carriers\Ups', + ], +]; \ No newline at end of file diff --git a/src/Config/system.php b/packages/Webkul/UpsShipping/src/Config/system.php similarity index 55% rename from src/Config/system.php rename to packages/Webkul/UpsShipping/src/Config/system.php index 1180c09..ff6ebc7 100644 --- a/src/Config/system.php +++ b/packages/Webkul/UpsShipping/src/Config/system.php @@ -2,11 +2,11 @@ return [ [ - 'key' => 'sales.carriers.ups', - 'name' => 'ups::app.admin.system.ups', - 'info' => 'ups::app.admin.system.ups-description', - 'sort' => 4, - 'fields' => [ + 'key' => 'sales.carriers.ups', + 'name' => 'ups::app.admin.system.ups', + 'info' => 'ups::app.admin.system.ups-description', + 'sort' => 4, + 'fields' => [ [ 'name' => 'title', 'title' => 'ups::app.admin.system.title', @@ -21,21 +21,21 @@ 'channel_based' => false, 'locale_based' => true, ], [ - 'name' => 'ups_active', - 'title' => 'ups::app.admin.system.status', - 'type' => 'boolean', + 'name' => 'ups_active', + 'title' => 'ups::app.admin.system.status', + 'type' => 'boolean', ], [ - 'name' => 'mode', - 'title' => 'ups::app.admin.system.mode', - 'type' => 'select', - 'validation' => 'required', - 'options' => [ + 'name' => 'mode', + 'title' => 'ups::app.admin.system.mode', + 'type' => 'select', + 'validation' => 'required', + 'options' => [ [ - 'title' => 'Development', - 'value' => 'DEVELOPMENT', + 'title' => 'Development', + 'value' => 'DEVELOPMENT', ], [ - 'title' => 'Live', - 'value' => "LIVE", + 'title' => 'Live', + 'value' => "LIVE", ], ], ], [ @@ -74,78 +74,78 @@ 'locale_based' => true, 'options' => [ [ - 'title' => 'Package', - 'value' => '02', + 'title' => 'Package', + 'value' => '02', ], [ - 'title' => 'UPS Letter', - 'value' => '01', + 'title' => 'UPS Letter', + 'value' => '01', ], [ - 'title' => 'UPS Tube', - 'value' => '03', + 'title' => 'UPS Tube', + 'value' => '03', ], [ - 'title' => 'UPS Pak', - 'value' => '04', + 'title' => 'UPS Pak', + 'value' => '04', ], [ - 'title' => 'UPS Express Box', - 'value' => '21', + 'title' => 'UPS Express Box', + 'value' => '21', ], ], ], [ 'name' => 'weight_unit', 'title' => 'ups::app.admin.system.weight-unit', - 'type' => 'select', + 'type' => 'multiselect', 'validation' => 'required', 'channel_based' => false, 'locale_based' => true, 'options' => [ [ - 'title' => 'LBS', - 'value' => 'LBS' + 'title' => 'LBS', + 'value' => 'LBS', ], [ - 'title' => 'KGS', - 'value' => 'KGS', + 'title' => 'KGS', + 'value' => 'KGS', ], ], ], [ 'name' => 'services', 'title' => 'ups::app.admin.system.allowed-methods', 'type' => 'multiselect', - 'channel_based' => false, + 'channel_based' => true, 'locale_based' => true, 'options' => [ [ - 'title' => 'Next Day Air Early AM', - 'value' => '14', + 'title' => 'Next Day Air Early AM', + 'value' => '14', ], [ - 'title' => 'Next Day Air', - 'value' => '01', + 'title' => 'Next Day Air', + 'value' => '01', ], [ - 'title' => 'Next Day Air Saver', - 'value' => '13', + 'title' => 'Next Day Air Saver', + 'value' => '13', ], [ - 'title' => '2nd Day Air AM', - 'value' => '59', + 'title' => '2nd Day Air AM', + 'value' => '59', ], [ - 'title' => '2nd Day Air', - 'value' => '02', + 'title' => '2nd Day Air', + 'value' => '02', ], [ - 'title' => '3 Day Select', - 'value' => '12', + 'title' => '3 Day Select', + 'value' => '12', ], [ - 'title' => 'Ups Ground', - 'value' => '03', + 'title' => 'Ups Ground', + 'value' => '03', ], [ - 'title' => 'UPS Worldwide Express', - 'value' => '07', + 'title' => 'UPS Worldwide Express', + 'value' => '07', ], [ - 'title' => 'UPS Worldwide Express Plus', - 'value' => '54', + 'title' => 'UPS Worldwide Express Plus', + 'value' => '54', ], [ - 'title' => 'UPS Worldwide Expedited', - 'value' => '08', + 'title' => 'UPS Worldwide Expedited', + 'value' => '08', ], [ - 'title' => 'UPS World Wide Saver', - 'value' => '65', + 'title' => 'UPS World Wide Saver', + 'value' => '65', ], ], ], diff --git a/src/Helpers/ShippingMethodHelper.php b/packages/Webkul/UpsShipping/src/Helpers/ShippingMethodHelper.php similarity index 75% rename from src/Helpers/ShippingMethodHelper.php rename to packages/Webkul/UpsShipping/src/Helpers/ShippingMethodHelper.php index 391e61e..616e4a5 100644 --- a/src/Helpers/ShippingMethodHelper.php +++ b/packages/Webkul/UpsShipping/src/Helpers/ShippingMethodHelper.php @@ -3,28 +3,15 @@ namespace Webkul\UpsShipping\Helpers; use Monolog\Logger; -use Monolog\Handler\StreamHandler; use Webkul\Checkout\Facades\Cart; -use Webkul\Checkout\Repositories\CartAddressRepository as CartAddress; -use Webkul\UpsShipping\Repositories\UpsRepository as UpsRepository; +use Monolog\Handler\StreamHandler; use Webkul\Core\Repositories\ChannelRepository as Channel; +use Webkul\UpsShipping\Repositories\UpsRepository as UpsRepository; +use Webkul\Checkout\Repositories\CartAddressRepository as CartAddress; + class ShippingMethodHelper { - /** - * RateServiceWsdl - * - * @var string - */ - protected $rateServiceWsdl; - - /** - * ShipServiceWsdl - * - * @var string - */ - protected $shipServiceWsdl; - /** * Create a new controller instance. * @@ -41,88 +28,89 @@ public function __construct( } /** - * display cart products + * display methods * - * @param $address - * * @return array */ public function getAllCartProducts($address) { - return $this->createSoapClient($address); + $data = $this->_createSoapClient($address); + + return $data; } /** * Soap client for wsdl * - * @param $address - * + * @param string $wsdl + * @param bool|int $trace * @return \SoapClient */ - protected function createSoapClient($address) + protected function _createSoapClient($address) { - if (! core()->getConfigData('sales.carriers.ups.ups_active')) { - return false; - } - $cart = Cart::getCart(); - + $defaultChannel = core()->getCurrentChannelCode(); - + $adminData = $this->channel->findByField('code', $defaultChannel)->first(); - + $adminName = $adminData->name; - + $adminCompany = $adminData->hostname; - - $sellerAdminData = $this->upsRepository->getSellerAdminData($cart->items()->get(), 'ups_postcode'); - + + if (! core()->getConfigData('sales.carriers.ups.ups_active')) { + return false; + } else { + $status = true; + } + + if ($status) { + $sellerAdminData = $this->upsRepository->getSellerAdminData($cart->items()->get(), 'ups_postcode'); + } + $sellerAdminServices = $allServices = []; - foreach ($sellerAdminData as $cartProduct) { $sellerAdminServices[0] = explode(",", core()->getConfigData('sales.carriers.ups.services')); } - + foreach ($sellerAdminData as $cartProduct) { $weight = $this->getWeight($cartProduct->weight); - + $countryId = core()->getConfigData('sales.shipping.origin.country'); - - if (! isset($cartProduct->marketplace_seller_id)) { + + if (! empty($cartProduct->marketplace_seller_id)) { //if admin's product $zoneInformation = core()->getConfigData('sales.shipping.origin.state'); $address1 = core()->getConfigData('sales.shipping.origin.address1'); $city = core()->getConfigData('sales.shipping.origin.city'); } - + // Get The User Credentials $accessKey = core()->getConfigData('sales.carriers.ups.access_license_key'); $userId = core()->getConfigData('sales.carriers.ups.user_id'); $password = core()->getConfigData('sales.carriers.ups.password'); - $url = core()->getConfigData('sales.carriers.ups.gateway_url'); $shipperNumber = core()->getConfigData('sales.carriers.ups.shipper_number'); - - $shipperNumber = $shipperNumber ? $shipperNumber: ''; - + + $shipperNumber = $shipperNumber ?? ''; + // create a simple xml object for AccessRequest & RateRequest $accessRequesttXML = new \SimpleXMLElement ( "" ); $rateRequestXML = new \SimpleXMLElement ( "" ); - + // create AccessRequest XML $accessRequesttXML->addChild ( "AccessLicenseNumber", $accessKey ); $accessRequesttXML->addChild ( "UserId", $userId ); $accessRequesttXML->addChild ( "Password", $password ); - + // create RateRequest XML $request = $rateRequestXML->addChild ( 'Request' ); $request->addChild ( "RequestAction", "Rate" ); $request->addChild ( "RequestOption", "Shop" ); - + $shipment = $rateRequestXML->addChild ( 'Shipment' ); $shipper = $shipment->addChild ( 'Shipper' ); - - if (! isset($cartProduct->marketplace_seller_id)) { - + + if (! empty($cartProduct->marketplace_seller_id)) { $shipper->addChild ( "Name", $adminName ); $shipper->addChild ( "ShipperNumber", $shipperNumber ); @@ -144,30 +132,30 @@ protected function createSoapClient($address) $shipTo = $shipment->addChild ( 'ShipTo' ); $shipTo->addChild ( "CompanyName", $address->first_name . ' ' . $address->last_name ); + $shipToAddress = $shipTo->addChild ( 'Address' ); $shipToAddress->addChild ( "AddressLine1", $address->address1 ); $shipToAddress->addChild ( "City", $address->city ); - + if ($address->country == 'PR') { $shipToAddress->addChild ( "PostalCode", '00'. $address->postcode ); - } else { $shipToAddress->addChild ( "PostalCode", $address->postcode ); } - + $shipToAddress->addChild ( "CountryCode", $address->country ); + $package = $shipment->addChild ( 'Package' ); $packageType = $package->addChild ( 'PackagingType' ); $packageType->addChild ( "Code", core()->getConfigData('sales.carriers.ups.container') ); - + $packageWeight = $package->addChild ( 'PackageWeight' ); $unitOfMeasurement = $packageWeight->addChild ( 'UnitOfMeasurement' ); $unitOfMeasurement->addChild ( "Code", "LBS" ); $packageWeight->addChild ( "Weight", $weight ); - + $requestXML = $accessRequesttXML->asXML () . $rateRequestXML->asXML (); - $endpointurl = 'https://onlinetools.ups.com/ups.app/xml/Rate'; - + try { $url = 'https://onlinetools.ups.com/ups.app/xml/Rate'; @@ -178,66 +166,60 @@ protected function createSoapClient($address) curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array( - "Content-type: text/xml", - "Accept: text/xml", - "Cache-Control: no-cache", - "Pragma: no-cache", + "Content-type: text/xml", + "Accept: text/xml", + "Cache-Control: no-cache", + "Pragma: no-cache", )); - curl_setopt($ch, CURLOPT_POSTFIELDS,$requestXML); - + $response = curl_exec($ch); - + curl_close($ch); - + $upsServiceArray = simplexml_load_string($response); $upsServices = json_decode(json_encode($upsServiceArray)); - - if (isset($cartProduct->marketplace_seller_id)) { + + $sellerId = 0; + if (! empty($cartProduct->marketplace_seller_id)) { $sellerId = $cartProduct->marketplace_seller_id; - } else { - $sellerId = 0; } - if ($response) { - if (isset($upsServices->Response->ResponseStatusDescription) - && $upsServices->Response->ResponseStatusDescription == 'Success') { - - if (isset($upsServices->RatedShipment)) { - - foreach ($upsServices->RatedShipment as $services) { - $serviceCode = $services->Service->Code; - - $matchResult = $this->upsRepository->validateAllowedMethods($serviceCode, $sellerAdminServices); - - $serviceName = $this->getServiceName($serviceCode); - - if ($matchResult) { - $cartProductServices[$serviceName] = [ - 'classId' => $serviceCode, - 'rate' => $services->RatedPackage->TotalCharges->MonetaryValue, - 'currency' => $services->RatedPackage->TotalCharges->CurrencyCode, - 'weight' => $services->BillingWeight->Weight, - 'weightUnit' => $services->BillingWeight->UnitOfMeasurement->Code, - 'marketplace_seller_id' => $sellerId, - 'itemQuantity' => $cartProduct->quantity, - ]; - } - - } - - if (! empty($cartProductServices)) { - $allServices[] = $cartProductServices; + if ( $response + && isset($upsServices->Response->ResponseStatusDescription) + && $upsServices->Response->ResponseStatusDescription == 'Success' + ) { + if ( isset($upsServices->RatedShipment)) { + foreach ($upsServices->RatedShipment as $services) { + $serviceCode = $services->Service->Code; + $matchResult = $this->upsRepository->validateAllowedMethods($serviceCode, $sellerAdminServices); + $serviceName = $this->getServiceName($serviceCode); + + if ($matchResult) { + $cartProductServices[$serviceName] = [ + 'classId' => $serviceCode, + 'rate' => $services->RatedPackage->TotalCharges->MonetaryValue, + 'currency' => $services->RatedPackage->TotalCharges->CurrencyCode, + 'weight' => $services->BillingWeight->Weight, + 'weightUnit' => $services->BillingWeight->UnitOfMeasurement->Code, + 'marketplace_seller_id' => $sellerId, + 'itemQuantity' => $cartProduct->quantity + ]; } } - } else { - $errorLog = $this->getErrorLog($upsServices); - - return false; //to check the error generated in the method; + if (! empty($cartProductServices)) { + $allServices[] = $cartProductServices; + } } + } else { + $errorLog = $this->getErrorLog($upsServices); + + return false; + //to check the error generated in the method; } + } catch (\Exception $e) { return false; } @@ -250,6 +232,7 @@ protected function createSoapClient($address) } } + /** * Map service code * @@ -301,12 +284,12 @@ public function getWeight($weight) $convertedWeight = ''; if ($coreWeightUnit == 'LBS') { - if ($upsWeightUnit == 'LBS') { $convertedWeight = $weight; } else { //kgs to lbs $convertedWeight = $weight/0.45359237; + } } else { $convertedWeight = $weight/0.45359237; @@ -322,13 +305,14 @@ public function getWeight($weight) **/ public function getErrorLog($errors) { - foreach ($errors->Response->Error as $errorLog) { + + foreach ($errors->Response->Error as $errorLog){ $exception[] = $errorLog->ErrorDescription; } $status = $errors->Response->ResponseStatusDescription; - if (gettype($errors->Response->Error) !== 'array') { + if (gettype($errors->Response->Error) !== 'array') { $status = $errors->Response->Error->ErrorSeverity; $exception[] = $errors->Response->Error->ErrorDescription; diff --git a/src/Providers/UpsShippingServiceProvider.php b/packages/Webkul/UpsShipping/src/Providers/UpsShippingServiceProvider.php similarity index 81% rename from src/Providers/UpsShippingServiceProvider.php rename to packages/Webkul/UpsShipping/src/Providers/UpsShippingServiceProvider.php index 10508df..3ecfdb3 100755 --- a/src/Providers/UpsShippingServiceProvider.php +++ b/packages/Webkul/UpsShipping/src/Providers/UpsShippingServiceProvider.php @@ -19,6 +19,11 @@ public function boot(Router $router) $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'ups'); $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'ups'); + + $this->publishes([ + __DIR__ . '/../Resources/views/configurations/field-type.blade.php' => + __DIR__ . '/../../../Admin/src/Resources/views/configuration/field-type.blade.php', + ]); } /** diff --git a/packages/Webkul/UpsShipping/src/Repositories/UpsRepository.php b/packages/Webkul/UpsShipping/src/Repositories/UpsRepository.php new file mode 100644 index 0000000..25f203e --- /dev/null +++ b/packages/Webkul/UpsShipping/src/Repositories/UpsRepository.php @@ -0,0 +1,95 @@ +getConfigData('sales.carriers.ups.ups_services')); + $allowedMethods = []; + + foreach ($allServices as $services) { + $allowedMethod = []; + foreach ($services as $serviceType => $upsService) { + if (in_array($serviceType, $allowedServices)) { + $allowedMethod[] = [$serviceType => $upsService]; + } + } + + if (! empty($allowedMethod)) { + $allowedMethods[] = $allowedMethod; + } + } + + return (! empty($allowedMethods)) ? $this->getCommonMethods($allowedMethods) : false; + } + + /** + * Get the common methods among provided methods + * + * @param array $methods + * @return array|false + */ + public function getCommonMethods($methods) + { + $avilableServicesArray = []; + + foreach ($methods as $fedexMethods) { + foreach ($fedexMethods as $key => $fedexMethod) { + $avilableServicesArray[] = $key; + } + } + + $countMethods = count($methods); + $countServices = array_count_values($avilableServicesArray); + $finalServices = []; + + foreach ($countServices as $serviceType => $servicesCount) { + if ($servicesCount == $countMethods) { + foreach ($methods as $fedexMethods) { + foreach ($fedexMethods as $type => $fedexMethod) { + if ($serviceType == $type) { + $finalServices[$serviceType][] = $fedexMethod; + } + } + } + } + } + + return (! empty($finalServices)) ? $finalServices : false; + } +} \ No newline at end of file diff --git a/packages/Webkul/UpsShipping/src/Resources/assets/css/app.css b/packages/Webkul/UpsShipping/src/Resources/assets/css/app.css new file mode 100644 index 0000000..bd6213e --- /dev/null +++ b/packages/Webkul/UpsShipping/src/Resources/assets/css/app.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; \ No newline at end of file diff --git a/packages/Webkul/UpsShipping/src/Resources/assets/js/app.js b/packages/Webkul/UpsShipping/src/Resources/assets/js/app.js new file mode 100644 index 0000000..82fc4ad --- /dev/null +++ b/packages/Webkul/UpsShipping/src/Resources/assets/js/app.js @@ -0,0 +1,4 @@ +/** + * This will track all the images and fonts for publishing. + */ +import.meta.glob(["../images/**", "../fonts/**"]); \ No newline at end of file diff --git a/src/Resources/lang/ar/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/ar/app.php similarity index 100% rename from src/Resources/lang/ar/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/ar/app.php diff --git a/src/Resources/lang/bn/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/bn/app.php similarity index 100% rename from src/Resources/lang/bn/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/bn/app.php diff --git a/src/Resources/lang/de/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/de/app.php similarity index 100% rename from src/Resources/lang/de/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/de/app.php diff --git a/src/Resources/lang/en/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/en/app.php similarity index 100% rename from src/Resources/lang/en/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/en/app.php diff --git a/src/Resources/lang/es/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/es/app.php similarity index 100% rename from src/Resources/lang/es/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/es/app.php diff --git a/src/Resources/lang/fa/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/fa/app.php similarity index 100% rename from src/Resources/lang/fa/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/fa/app.php diff --git a/src/Resources/lang/fr/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/fr/app.php similarity index 100% rename from src/Resources/lang/fr/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/fr/app.php diff --git a/src/Resources/lang/he/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/he/app.php similarity index 100% rename from src/Resources/lang/he/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/he/app.php diff --git a/src/Resources/lang/hi_IN/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/hi_IN/app.php similarity index 100% rename from src/Resources/lang/hi_IN/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/hi_IN/app.php diff --git a/src/Resources/lang/it/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/it/app.php similarity index 100% rename from src/Resources/lang/it/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/it/app.php diff --git a/src/Resources/lang/ja/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/ja/app.php similarity index 100% rename from src/Resources/lang/ja/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/ja/app.php diff --git a/src/Resources/lang/nl/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/nl/app.php similarity index 100% rename from src/Resources/lang/nl/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/nl/app.php diff --git a/src/Resources/lang/pl/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/pl/app.php similarity index 100% rename from src/Resources/lang/pl/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/pl/app.php diff --git a/src/Resources/lang/pt_BR/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/pt_BR/app.php similarity index 100% rename from src/Resources/lang/pt_BR/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/pt_BR/app.php diff --git a/src/Resources/lang/ru/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/ru/app.php similarity index 100% rename from src/Resources/lang/ru/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/ru/app.php diff --git a/src/Resources/lang/sin/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/sin/app.php similarity index 100% rename from src/Resources/lang/sin/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/sin/app.php diff --git a/src/Resources/lang/tr/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/tr/app.php similarity index 100% rename from src/Resources/lang/tr/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/tr/app.php diff --git a/src/Resources/lang/uk/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/uk/app.php similarity index 100% rename from src/Resources/lang/uk/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/uk/app.php diff --git a/src/Resources/lang/zh_CN/app.php b/packages/Webkul/UpsShipping/src/Resources/lang/zh_CN/app.php similarity index 100% rename from src/Resources/lang/zh_CN/app.php rename to packages/Webkul/UpsShipping/src/Resources/lang/zh_CN/app.php diff --git a/packages/Webkul/UpsShipping/src/Resources/views/configurations/field-type.blade.php b/packages/Webkul/UpsShipping/src/Resources/views/configurations/field-type.blade.php new file mode 100644 index 0000000..fefd168 --- /dev/null +++ b/packages/Webkul/UpsShipping/src/Resources/views/configurations/field-type.blade.php @@ -0,0 +1,473 @@ +@inject('coreConfigRepository', 'Webkul\Core\Repositories\CoreConfigRepository') + +@php + $nameKey = $item['key'] . '.' . $field['name']; + + $name = $coreConfigRepository->getNameField($nameKey); + + $value = $coreConfigRepository->getValueByRepository($field); + + $validations = $coreConfigRepository->getValidations($field); + + $isRequired = Str::contains($validations, 'required') ? 'required' : ''; + + $channelLocaleInfo = $coreConfigRepository->getChannelLocaleInfo($field, $currentChannel->code, $currentLocale->code); +@endphp + + + + + @if ($field['type'] == 'depends') + @include('admin::configuration.dependent-field-type') + @else + +
+ + {!! __($field['title']) . ( __($field['title']) ? '' : '') !!} + + @if ( + ! empty($field['channel_based']) + && $channels->count() > 1 + ) + + {{ $currentChannel->name }} + + @endif + + @if (! empty($field['locale_based'])) + + {{ $currentLocale->name }} + + @endif + +
+ + + @if ($field['type'] == 'text') + + + + + @elseif ($field['type'] == 'password') + + + + + @elseif ($field['type'] == 'number') + + + + + @elseif ($field['type'] == 'color') + + + + + @elseif ($field['type'] == 'textarea') + + + + + @elseif ($field['type'] == 'editor') + + + + + + @elseif ($field['type'] == 'select') + @php $selectedOption = core()->getConfigData($nameKey, $currentChannel->code, $currentLocale->code) ?? ''; @endphp + + + @if (isset($field['repository'])) + @foreach ($value as $key => $option) + + @endforeach + @else + @foreach ($field['options'] as $option) + @php + $value = ! isset($option['value']) ? null : ( $value = ! $option['value'] ? 0 : $option['value'] ); + @endphp + + + @endforeach + @endif + + + + @elseif ($field['type'] == 'multiselect') + @php $selectedOption = core()->getConfigData($nameKey, $currentChannel->code, $currentLocale->code) ?? ''; @endphp + + + + + + + + @elseif ($field['type'] == 'boolean') + @php + $selectedOption = core()->getConfigData($nameKey, $currentChannel->code, $currentLocale->code) ?? ($field['default_value'] ?? ''); + @endphp + + + + + + @elseif ($field['type'] == 'image') + + @php + $src = Storage::url(core()->getConfigData($nameKey, $currentChannel->code, $currentLocale->code)); + $result = core()->getConfigData($nameKey, $currentChannel->code, $currentLocale->code); + @endphp + +
+ @if ($result) + + + + @endif + + + +
+ + @if ($result) + + + + + @lang('admin::app.configuration.index.delete') + + + @endif + + @elseif ($field['type'] == 'file') + @php + $result = core()->getConfigData($nameKey, $currentChannel->code, $currentLocale->code); + $src = explode("/", $result); + $path = end($src); + @endphp + + @if ($result) + + + + @endif + + + + + @if ($result) +
+ + + + @lang('admin::app.configuration.index.delete') + +
+ @endif + + + @elseif ($field['type'] == 'country') + + + + + + @elseif ($field['type'] == 'state') + + + + @endif + + @endif + + @if (isset($field['info'])) + + @endif + + + + +
+ +@if ($field['type'] == 'country') + @pushOnce('scripts') + + + + + + + + @endPushOnce +@endif \ No newline at end of file diff --git a/packages/Webkul/UpsShipping/tailwind.config.js b/packages/Webkul/UpsShipping/tailwind.config.js new file mode 100644 index 0000000..56c3a70 --- /dev/null +++ b/packages/Webkul/UpsShipping/tailwind.config.js @@ -0,0 +1,10 @@ +/** @type {import('tailwindcss').Config} */ +module.exports = { + content: ["./src/Resources/**/*.blade.php", "./src/Resources/**/*.js"], + + theme: { + extend: {}, + }, + + plugins: [], +}; \ No newline at end of file diff --git a/packages/Webkul/UpsShipping/vite.config.js b/packages/Webkul/UpsShipping/vite.config.js new file mode 100644 index 0000000..6f038dc --- /dev/null +++ b/packages/Webkul/UpsShipping/vite.config.js @@ -0,0 +1,43 @@ +import { defineConfig, loadEnv } from "vite"; +import laravel from "laravel-vite-plugin"; +import path from "path"; + +export default defineConfig(({ mode }) => { + const envDir = "../../../"; + + Object.assign(process.env, loadEnv(mode, envDir)); + + return { + build: { + emptyOutDir: true, + }, + + envDir, + + server: { + host: process.env.VITE_HOST || "localhost", + port: process.env.VITE_PORT || 5173, + }, + + plugins: [ + laravel({ + hotFile: "../../../public/ups-module-vite.hot", + publicDirectory: "../../../public", + buildDirectory: "themes/ups-module/build", + input: [ + "src/Resources/assets/css/app.css", + "src/Resources/assets/js/app.js", + ], + refresh: true, + }), + ], + + experimental: { + renderBuiltUrl(filename, { hostId, hostType, type }) { + if (hostType === "css") { + return path.basename(filename); + } + }, + }, + }; +}); \ No newline at end of file diff --git a/src/Config/carriers.php b/src/Config/carriers.php deleted file mode 100755 index 515b479..0000000 --- a/src/Config/carriers.php +++ /dev/null @@ -1,11 +0,0 @@ - [ - 'code' => 'ups', - 'title' => 'UPS Shipping', - 'description' => 'UPS Shipping', - 'active' => true, - 'class' => 'Webkul\UpsShipping\Carriers\Ups', - ] -]; \ No newline at end of file diff --git a/src/Repositories/UpsRepository.php b/src/Repositories/UpsRepository.php deleted file mode 100644 index 07964e9..0000000 --- a/src/Repositories/UpsRepository.php +++ /dev/null @@ -1,139 +0,0 @@ -getConfigData('sales.carriers.ups.services')); - - foreach ($allServices as $services) { - $allowedMethod =[]; - foreach ($services as $service) { - - foreach ($service as $serviceType =>$upsService) { - if (in_array($serviceType , $allowedServices)) { - $allowedMethod[] = [ - $serviceType => $upsService - ]; - } else { - $notAllowed[] = [ - $serviceType => $upsService - ]; - } - } - } - - if ($allowedMethod == null) { - continue; - } - $allowedMethods[] = $allowedMethod; - } - - if (isset($allowedMethods)) { - return $this->getCommonMethods($allowedMethods); - } - - return false; - } - - /** - * get the Common method - * - * @param $Methods - */ - public function getCommonMethods($methods) - { - $countMethods = count($methods); - - foreach ($methods as $fedexMethods) { - - foreach ($fedexMethods as $key => $fedexMethod) { - $avilableServicesArray[] = $key; - } - } - - $countServices = array_count_values($avilableServicesArray); - $finalServices = []; - - foreach ($countServices as $serviceType => $servicesCount) { - - foreach ($methods as $fedexMethods) { - - foreach ($fedexMethods as $type => $fedexMethod) { - - if ($serviceType == $type && $servicesCount == $countMethods) { - $finalServices[$serviceType][] =$fedexMethod; - } - } - } - if ($finalServices == null) { - continue; - } - } - - if (empty($finalServices)) { - return false; - } - - return $finalServices; - } -} - diff --git a/webpack.mix.js b/webpack.mix.js deleted file mode 100644 index 6713475..0000000 --- a/webpack.mix.js +++ /dev/null @@ -1,19 +0,0 @@ -const { mix } = require("laravel-mix"); -require("laravel-mix-merge-manifest"); - -if (mix.inProduction()) { - var publicPath = 'publishable/assets'; -} else { - var publicPath = "../../../public/themes/default/assets"; -} - -mix.setPublicPath(publicPath).mergeManifest(); -mix.disableNotifications(); - -mix.options({ - processCssUrls: false - }); - -if (mix.inProduction()) { - mix.version(); -} \ No newline at end of file From f17320283b1a339afba3e625937c58e3a6207aa8 Mon Sep 17 00:00:00 2001 From: antu chaudhary Date: Tue, 16 Apr 2024 18:51:05 +0530 Subject: [PATCH 7/8] optimized the code of ups shipping --- .../Webkul/UpsShipping/src/Carriers/Ups.php | 111 ++++++------------ .../Webkul/UpsShipping/src/Config/system.php | 2 +- .../src/Helpers/ShippingMethodHelper.php | 90 +++++++------- .../src/Repositories/UpsRepository.php | 15 ++- 4 files changed, 90 insertions(+), 128 deletions(-) diff --git a/packages/Webkul/UpsShipping/src/Carriers/Ups.php b/packages/Webkul/UpsShipping/src/Carriers/Ups.php index 7ae7f39..d60bf78 100644 --- a/packages/Webkul/UpsShipping/src/Carriers/Ups.php +++ b/packages/Webkul/UpsShipping/src/Carriers/Ups.php @@ -9,18 +9,6 @@ class Ups extends AbstractShipping { - /** - * The shipping method helper instance. - * - * @var \Webkul\UpsShipping\Helpers\ShippingMethodHelper $shippingMethodHelper - * @return void - */ - public function __construct( - protected ShippingMethodHelper $shippingMethodHelper, - ) - { - } - /** * Payment method code * @@ -39,80 +27,59 @@ public function calculate() return false; } - $shippingMethods = $rates = []; + $shippingMethods = []; $cart = Cart::getCart(); $address = $cart->shipping_address; - - $data = $this->shippingMethodHelper->getAllCartProducts($address); - - $marketplaceShipping = session()->get('marketplace_shipping_rates'); + + $data = app('Webkul\UpsShipping\Helpers\ShippingMethodHelper')->getAllCartProducts($address); - if (! $this->isAvailable()) + if (! $data) { return false; + } - if (isset ($data) && $data == true) { - foreach ($data as $key => $fedexServices) { - $rate = $totalShippingCost = 0; - - $upsMethod = $methodCode = $key; - - foreach ($fedexServices as $methods => $upsRate) { - $rate += $upsRate['rate'] * $upsRate['itemQuantity']; - $sellerId = $upsRate['marketplace_seller_id']; - - $itemShippingCost = $upsRate['rate'] * $upsRate['itemQuantity']; - - $rates[$key][$sellerId] = [ - 'amount' => core()->convertPrice($itemShippingCost), - 'base_amount' => $itemShippingCost - ]; - - if (isset ($rates[$key][$sellerId])) { - $rates[$key][$sellerId] = [ - 'amount' => core()->convertPrice($rates[$key][$sellerId]['amount'] + $itemShippingCost), - 'base_amount' => $rates[$key][$sellerId]['base_amount'] + $itemShippingCost - ]; - } - - $totalShippingCost += $itemShippingCost; - } - - $object = new CartShippingRate; - - $object->carrier = 'mpups'; - - $object->carrier_title = $this->getConfigData('title'); - - $object->method = 'mpups_' . '' . $methodCode; - - $object->method_title = $this->getConfigData('title'); - - $object->method_description = $upsMethod; - - $object->price = core()->convertPrice($totalShippingCost); + foreach ($data as $key => $fedexServices) { + $totalShippingCost = 0; + + $rates = []; + + foreach ($fedexServices as $methods => $upsRate) { + $itemShippingCost = $upsRate['rate'] * $upsRate['itemQuantity']; + $sellerId = $upsRate['marketplace_seller_id']; + + $rates[$sellerId] = [ + 'amount' => core()->convertPrice($itemShippingCost), + 'base_amount' => $itemShippingCost, + ]; + + $totalShippingCost += $itemShippingCost; + } + + $object = new CartShippingRate; - $object->base_price = $totalShippingCost; + $object->carrier = 'mpups'; - $marketplaceShippingRates = session()->get('marketplace_shipping_rates'); + $object->carrier_title = $this->getConfigData('title'); - if (! is_array($marketplaceShipping)) { - $marketplaceShippingRates['mpupsshipping'] = ['mpupsshipping' => $rates]; - session()->put('marketplace_shipping_rates', $marketplaceShippingRates); + $object->method = 'mpups_' . $key; - } else { - $marketplaceFedexShipping = ['mpupshipping' => $rates]; - } + $object->method_title = $this->getConfigData('title'); - array_push($shippingMethods, $object); - } + $object->method_description = $key; + + $object->price = core()->convertPrice($totalShippingCost); - if (isset ($marketplaceFedexShipping)) { - session()->put('marketplace_shipping_rates.mpupshipping', $marketplaceFedexShipping); - } + $object->base_price = $totalShippingCost; - return $shippingMethods; + $shippingMethods[] = $object; + // Store rates in session + $marketplaceShippingRates = session()->get('marketplace_shipping_rates', []); + + $marketplaceShippingRates['mpupsshipping'][$key] = $rates; + session()->put('marketplace_shipping_rates', $marketplaceShippingRates); } + + return $shippingMethods; } } \ No newline at end of file diff --git a/packages/Webkul/UpsShipping/src/Config/system.php b/packages/Webkul/UpsShipping/src/Config/system.php index ff6ebc7..efc3e30 100644 --- a/packages/Webkul/UpsShipping/src/Config/system.php +++ b/packages/Webkul/UpsShipping/src/Config/system.php @@ -93,7 +93,7 @@ ], [ 'name' => 'weight_unit', 'title' => 'ups::app.admin.system.weight-unit', - 'type' => 'multiselect', + 'type' => 'select', 'validation' => 'required', 'channel_based' => false, 'locale_based' => true, diff --git a/packages/Webkul/UpsShipping/src/Helpers/ShippingMethodHelper.php b/packages/Webkul/UpsShipping/src/Helpers/ShippingMethodHelper.php index 616e4a5..f329c10 100644 --- a/packages/Webkul/UpsShipping/src/Helpers/ShippingMethodHelper.php +++ b/packages/Webkul/UpsShipping/src/Helpers/ShippingMethodHelper.php @@ -48,31 +48,28 @@ public function getAllCartProducts($address) */ protected function _createSoapClient($address) { - $cart = Cart::getCart(); + if (! core()->getConfigData('sales.carriers.ups.ups_active')) { + return false; + } + $cart = Cart::getCart(); + $defaultChannel = core()->getCurrentChannelCode(); $adminData = $this->channel->findByField('code', $defaultChannel)->first(); $adminName = $adminData->name; - + $adminCompany = $adminData->hostname; - - if (! core()->getConfigData('sales.carriers.ups.ups_active')) { - return false; - } else { - $status = true; - } - - if ($status) { - $sellerAdminData = $this->upsRepository->getSellerAdminData($cart->items()->get(), 'ups_postcode'); - } + + $sellerAdminData = $this->upsRepository->getSellerAdminData($cart->items()->get(), 'ups_postcode'); $sellerAdminServices = $allServices = []; + foreach ($sellerAdminData as $cartProduct) { $sellerAdminServices[0] = explode(",", core()->getConfigData('sales.carriers.ups.services')); } - + foreach ($sellerAdminData as $cartProduct) { $weight = $this->getWeight($cartProduct->weight); @@ -186,11 +183,11 @@ protected function _createSoapClient($address) $sellerId = $cartProduct->marketplace_seller_id; } - if ( $response + if ($response && isset($upsServices->Response->ResponseStatusDescription) && $upsServices->Response->ResponseStatusDescription == 'Success' ) { - if ( isset($upsServices->RatedShipment)) { + if (isset($upsServices->RatedShipment)) { foreach ($upsServices->RatedShipment as $services) { $serviceCode = $services->Service->Code; $matchResult = $this->upsRepository->validateAllowedMethods($serviceCode, $sellerAdminServices); @@ -204,7 +201,7 @@ protected function _createSoapClient($address) 'weight' => $services->BillingWeight->Weight, 'weightUnit' => $services->BillingWeight->UnitOfMeasurement->Code, 'marketplace_seller_id' => $sellerId, - 'itemQuantity' => $cartProduct->quantity + 'itemQuantity' => $cartProduct->quantity, ]; } } @@ -219,7 +216,6 @@ protected function _createSoapClient($address) return false; //to check the error generated in the method; } - } catch (\Exception $e) { return false; } @@ -232,7 +228,6 @@ protected function _createSoapClient($address) } } - /** * Map service code * @@ -241,24 +236,24 @@ protected function _createSoapClient($address) protected function getServiceName($serviceCode) { $mapServices = [ - '01' => 'Next Day Air', - '02' => '2nd Day Air', - '03' => 'Ups Ground', - '07' => 'Ups Worldwide Express', - '08' => 'Ups Worldwide Expedited', - '11' => 'Standard', - '12' => '3 Day Select', - '13' => 'Next Day Air Saver', - '14' => 'Next Day Air Early A.M.', - '54' => 'Ups Worldwide Express Plus', - '59' => '2nd Day Air A.M.', - '65' => 'UPS World Wide Saver', - '82' => 'Today Standard', - '83' => 'Today Dedicated Courier', - '84' => 'Today Intercity', - '85' => 'Today Express', - '86' => 'Today Express Saver', - '03' => 'Ups Ground', + '01' => 'Next Day Air', + '02' => '2nd Day Air', + '03' => 'Ups Ground', + '07' => 'Ups Worldwide Express', + '08' => 'Ups Worldwide Expedited', + '11' => 'Standard', + '12' => '3 Day Select', + '13' => 'Next Day Air Saver', + '14' => 'Next Day Air Early A.M.', + '54' => 'Ups Worldwide Express Plus', + '59' => '2nd Day Air A.M.', + '65' => 'UPS World Wide Saver', + '82' => 'Today Standard', + '83' => 'Today Dedicated Courier', + '84' => 'Today Intercity', + '85' => 'Today Express', + '86' => 'Today Express Saver', + '03' => 'Ups Ground', ]; foreach ($mapServices as $key => $service) { @@ -289,7 +284,6 @@ public function getWeight($weight) } else { //kgs to lbs $convertedWeight = $weight/0.45359237; - } } else { $convertedWeight = $weight/0.45359237; @@ -305,20 +299,22 @@ public function getWeight($weight) **/ public function getErrorLog($errors) { + $exception = []; - foreach ($errors->Response->Error as $errorLog){ - $exception[] = $errorLog->ErrorDescription; - } - - $status = $errors->Response->ResponseStatusDescription; - - if (gettype($errors->Response->Error) !== 'array') { - $status = $errors->Response->Error->ErrorSeverity; - + if (is_array($errors->Response->Error)) { + foreach ($errors->Response->Error as $errorLog) { + $exception[] = $errorLog->ErrorDescription; + } + } else { $exception[] = $errors->Response->Error->ErrorDescription; } - $logs = ['status' => $status, 'description' => $exception]; + $status = is_array($errors->Response->Error) ? $errors->Response->ResponseStatusDescription : $errors->Response->Error->ErrorSeverity; + + $logs = [ + 'status' => $status, + 'description' => $exception, + ]; $shippingLog = new Logger('shipping'); $shippingLog->pushHandler(new StreamHandler(storage_path('logs/ups.log')), Logger::INFO); diff --git a/packages/Webkul/UpsShipping/src/Repositories/UpsRepository.php b/packages/Webkul/UpsShipping/src/Repositories/UpsRepository.php index 25f203e..bcdfe3b 100644 --- a/packages/Webkul/UpsShipping/src/Repositories/UpsRepository.php +++ b/packages/Webkul/UpsShipping/src/Repositories/UpsRepository.php @@ -28,6 +28,7 @@ public function validateAllowedMethods($service, $allowedServices) return true; } } + return false; } @@ -66,25 +67,23 @@ public function getAllowedMethods($allServices) */ public function getCommonMethods($methods) { - $avilableServicesArray = []; + $availableServicesArray = []; foreach ($methods as $fedexMethods) { - foreach ($fedexMethods as $key => $fedexMethod) { - $avilableServicesArray[] = $key; + foreach (array_keys($fedexMethods) as $serviceType) { + $availableServicesArray[] = $serviceType; } } $countMethods = count($methods); - $countServices = array_count_values($avilableServicesArray); + $countServices = array_count_values($availableServicesArray); $finalServices = []; foreach ($countServices as $serviceType => $servicesCount) { if ($servicesCount == $countMethods) { foreach ($methods as $fedexMethods) { - foreach ($fedexMethods as $type => $fedexMethod) { - if ($serviceType == $type) { - $finalServices[$serviceType][] = $fedexMethod; - } + if (isset($fedexMethods[$serviceType])) { + $finalServices[$serviceType][] = $fedexMethods[$serviceType]; } } } From ae594d0896fac0d5fd2d6a0bbccc0bb685c03206 Mon Sep 17 00:00:00 2001 From: antu chaudhary Date: Wed, 17 Apr 2024 16:36:03 +0530 Subject: [PATCH 8/8] Added the further changes according to the code standard --- .../Webkul/UpsShipping/src/Carriers/Ups.php | 46 +-- .../src/Helpers/ShippingMethodHelper.php | 292 +++++++++--------- .../src/Repositories/UpsRepository.php | 43 ++- .../views/configurations/field-type.blade.php | 1 - 4 files changed, 194 insertions(+), 188 deletions(-) diff --git a/packages/Webkul/UpsShipping/src/Carriers/Ups.php b/packages/Webkul/UpsShipping/src/Carriers/Ups.php index d60bf78..279bda4 100644 --- a/packages/Webkul/UpsShipping/src/Carriers/Ups.php +++ b/packages/Webkul/UpsShipping/src/Carriers/Ups.php @@ -27,28 +27,30 @@ public function calculate() return false; } - $shippingMethods = []; + $shippingRates = []; $cart = Cart::getCart(); $address = $cart->shipping_address; - $data = app('Webkul\UpsShipping\Helpers\ShippingMethodHelper')->getAllCartProducts($address); + $shippingMethodHelper = app(ShippingMethodHelper::class); + + $cartProductsShippingData = $shippingMethodHelper->getAllCartProducts($address); - if (! $data) { + if (! $cartProductsShippingData) { return false; } - foreach ($data as $key => $fedexServices) { + foreach ($cartProductsShippingData as $sellerId => $shippingMethods) { $totalShippingCost = 0; + + $sellerRates = []; - $rates = []; - - foreach ($fedexServices as $methods => $upsRate) { - $itemShippingCost = $upsRate['rate'] * $upsRate['itemQuantity']; - $sellerId = $upsRate['marketplace_seller_id']; + foreach ($shippingMethods as $methodCode => $methodData) { + $itemShippingCost = $methodData['rate'] * $methodData['itemQuantity']; + $marketplaceSellerId = $methodData['marketplace_seller_id']; - $rates[$sellerId] = [ + $sellerRates[$marketplaceSellerId] = [ 'amount' => core()->convertPrice($itemShippingCost), 'base_amount' => $itemShippingCost, ]; @@ -56,30 +58,32 @@ public function calculate() $totalShippingCost += $itemShippingCost; } - $object = new CartShippingRate; + $cartShippingRate = new CartShippingRate; - $object->carrier = 'mpups'; + $cartShippingRate->carrier = 'mpups'; - $object->carrier_title = $this->getConfigData('title'); + $cartShippingRate->carrier_title = $this->getConfigData('title'); - $object->method = 'mpups_' . $key; + $cartShippingRate->method = 'mpups_' . $sellerId; - $object->method_title = $this->getConfigData('title'); + $cartShippingRate->method_title = $this->getConfigData('title'); - $object->method_description = $key; + $cartShippingRate->method_description = $sellerId; - $object->price = core()->convertPrice($totalShippingCost); + $cartShippingRate->price = core()->convertPrice($totalShippingCost); - $object->base_price = $totalShippingCost; + $cartShippingRate->base_price = $totalShippingCost; - $shippingMethods[] = $object; + $shippingRates[] = $cartShippingRate; + // Store rates in session $marketplaceShippingRates = session()->get('marketplace_shipping_rates', []); - $marketplaceShippingRates['mpupsshipping'][$key] = $rates; + $marketplaceShippingRates['mpupsshipping'][$sellerId] = $sellerRates; + session()->put('marketplace_shipping_rates', $marketplaceShippingRates); } - return $shippingMethods; + return $shippingRates; } } \ No newline at end of file diff --git a/packages/Webkul/UpsShipping/src/Helpers/ShippingMethodHelper.php b/packages/Webkul/UpsShipping/src/Helpers/ShippingMethodHelper.php index f329c10..d4bfe39 100644 --- a/packages/Webkul/UpsShipping/src/Helpers/ShippingMethodHelper.php +++ b/packages/Webkul/UpsShipping/src/Helpers/ShippingMethodHelper.php @@ -28,136 +28,136 @@ public function __construct( } /** - * display methods + * Get shipping methods for all products in the cart. * - * @return array - */ + * @param object $address + * @return array|false + */ public function getAllCartProducts($address) { - $data = $this->_createSoapClient($address); - - return $data; + return $this->getShippingRates($address); } /** - * Soap client for wsdl + * Retrieve shipping rates via SOAP client. * - * @param string $wsdl - * @param bool|int $trace - * @return \SoapClient + * @param object $address + * @return array|false */ - protected function _createSoapClient($address) + protected function getShippingRates($address) { if (! core()->getConfigData('sales.carriers.ups.ups_active')) { return false; } $cart = Cart::getCart(); - + $defaultChannel = core()->getCurrentChannelCode(); $adminData = $this->channel->findByField('code', $defaultChannel)->first(); $adminName = $adminData->name; - + $adminCompany = $adminData->hostname; - + $sellerAdminData = $this->upsRepository->getSellerAdminData($cart->items()->get(), 'ups_postcode'); $sellerAdminServices = $allServices = []; - + foreach ($sellerAdminData as $cartProduct) { $sellerAdminServices[0] = explode(",", core()->getConfigData('sales.carriers.ups.services')); } foreach ($sellerAdminData as $cartProduct) { - $weight = $this->getWeight($cartProduct->weight); - + $weight = $this->convertWeightToLbs($cartProduct->weight); $countryId = core()->getConfigData('sales.shipping.origin.country'); - + if (! empty($cartProduct->marketplace_seller_id)) { - //if admin's product $zoneInformation = core()->getConfigData('sales.shipping.origin.state'); $address1 = core()->getConfigData('sales.shipping.origin.address1'); $city = core()->getConfigData('sales.shipping.origin.city'); } - - // Get The User Credentials + $accessKey = core()->getConfigData('sales.carriers.ups.access_license_key'); $userId = core()->getConfigData('sales.carriers.ups.user_id'); $password = core()->getConfigData('sales.carriers.ups.password'); $shipperNumber = core()->getConfigData('sales.carriers.ups.shipper_number'); $shipperNumber = $shipperNumber ?? ''; - - // create a simple xml object for AccessRequest & RateRequest - $accessRequesttXML = new \SimpleXMLElement ( "" ); - $rateRequestXML = new \SimpleXMLElement ( "" ); - - // create AccessRequest XML - $accessRequesttXML->addChild ( "AccessLicenseNumber", $accessKey ); - $accessRequesttXML->addChild ( "UserId", $userId ); - $accessRequesttXML->addChild ( "Password", $password ); - - // create RateRequest XML - $request = $rateRequestXML->addChild ( 'Request' ); - $request->addChild ( "RequestAction", "Rate" ); - $request->addChild ( "RequestOption", "Shop" ); - - $shipment = $rateRequestXML->addChild ( 'Shipment' ); - $shipper = $shipment->addChild ( 'Shipper' ); - - if (! empty($cartProduct->marketplace_seller_id)) { - $shipper->addChild ( "Name", $adminName ); - $shipper->addChild ( "ShipperNumber", $shipperNumber ); - - $shipperddress = $shipper->addChild ( 'Address' ); - $shipperddress->addChild ( "AddressLine1", $address1 ? $address1 : '' ); - $shipperddress->addChild ( "City", $city ? $city : '' ); - $shipperddress->addChild ( "PostalCode", core()->getConfigData('sales.shipping.origin.zipcode') ); - $shipperddress->addChild ( "CountryCode", $countryId ); - - $shipFrom = $shipment->addChild ( 'ShipFrom' ); - $shipFrom->addChild ( "CompanyName", $adminCompany ); - $shipFromAddress = $shipFrom->addChild ( 'Address' ); - $shipFromAddress->addChild ( "AddressLine1", $address1 ? $address1 : '' ); - $shipFromAddress->addChild ( "City", $city ? $city : '' ); - $shipFromAddress->addChild ( "StateProvinceCode", $zoneInformation ); - $shipFromAddress->addChild ( "PostalCode", core()->getConfigData('sales.shipping.origin.zipcode') ); - $shipFromAddress->addChild ( "CountryCode", $countryId ); + + // Build XML request for SOAP + $accessRequestXML = new \SimpleXMLElement(""); + $rateRequestXML = new \SimpleXMLElement(""); + + // Build AccessRequest XML + $accessRequestXML->addChild("AccessLicenseNumber", $accessKey); + $accessRequestXML->addChild("UserId", $userId); + $accessRequestXML->addChild("Password", $password); + + // Build RateRequest XML + $request = $rateRequestXML->addChild('Request'); + $request->addChild("RequestAction", "Rate"); + $request->addChild("RequestOption", "Shop"); + + // Build Shipper section + $shipment = $rateRequestXML->addChild('Shipment'); + $shipper = $shipment->addChild('Shipper'); + + // Shipper details + if (!empty($cartProduct->marketplace_seller_id)) { + $shipper->addChild("Name", $adminName); + $shipper->addChild("ShipperNumber", $shipperNumber); + + $shipperAddress = $shipper->addChild('Address'); + $shipperAddress->addChild("AddressLine1", $address1 ? $address1 : ''); + $shipperAddress->addChild("City", $city ? $city : ''); + $shipperAddress->addChild("PostalCode", core()->getConfigData('sales.shipping.origin.zipcode')); + $shipperAddress->addChild("CountryCode", $countryId); + + $shipFrom = $shipment->addChild('ShipFrom'); + $shipFrom->addChild("CompanyName", $adminCompany); + + $shipFromAddress = $shipFrom->addChild('Address'); + $shipFromAddress->addChild("AddressLine1", $address1 ? $address1 : ''); + $shipFromAddress->addChild("City", $city ? $city : ''); + $shipFromAddress->addChild("StateProvinceCode", $zoneInformation); + $shipFromAddress->addChild("PostalCode", core()->getConfigData('sales.shipping.origin.zipcode')); + $shipFromAddress->addChild("CountryCode", $countryId); } - $shipTo = $shipment->addChild ( 'ShipTo' ); - $shipTo->addChild ( "CompanyName", $address->first_name . ' ' . $address->last_name ); - - $shipToAddress = $shipTo->addChild ( 'Address' ); - $shipToAddress->addChild ( "AddressLine1", $address->address1 ); - $shipToAddress->addChild ( "City", $address->city ); - + // ShipTo details + $shipTo = $shipment->addChild('ShipTo'); + $shipTo->addChild("CompanyName", $address->first_name . ' ' . $address->last_name); + + $shipToAddress = $shipTo->addChild('Address'); + $shipToAddress->addChild("AddressLine1", $address->address1); + $shipToAddress->addChild("City", $address->city); + if ($address->country == 'PR') { - $shipToAddress->addChild ( "PostalCode", '00'. $address->postcode ); + $shipToAddress->addChild("PostalCode", '00' . $address->postcode); } else { - $shipToAddress->addChild ( "PostalCode", $address->postcode ); + $shipToAddress->addChild("PostalCode", $address->postcode); } - - $shipToAddress->addChild ( "CountryCode", $address->country ); - $package = $shipment->addChild ( 'Package' ); - $packageType = $package->addChild ( 'PackagingType' ); - $packageType->addChild ( "Code", core()->getConfigData('sales.carriers.ups.container') ); - - $packageWeight = $package->addChild ( 'PackageWeight' ); - $unitOfMeasurement = $packageWeight->addChild ( 'UnitOfMeasurement' ); - $unitOfMeasurement->addChild ( "Code", "LBS" ); - $packageWeight->addChild ( "Weight", $weight ); - - $requestXML = $accessRequesttXML->asXML () . $rateRequestXML->asXML (); - + $shipToAddress->addChild("CountryCode", $address->country); + + // Package details + $package = $shipment->addChild('Package'); + $packageType = $package->addChild('PackagingType'); + $packageType->addChild("Code", core()->getConfigData('sales.carriers.ups.container')); + + $packageWeight = $package->addChild('PackageWeight'); + $unitOfMeasurement = $packageWeight->addChild('UnitOfMeasurement'); + $unitOfMeasurement->addChild("Code", "LBS"); + $packageWeight->addChild("Weight", $weight); + + $requestXML = $accessRequestXML->asXML() . $rateRequestXML->asXML(); + try { $url = 'https://onlinetools.ups.com/ups.app/xml/Rate'; - + $ch = curl_init(); - curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_POST, true); @@ -168,38 +168,39 @@ protected function _createSoapClient($address) "Cache-Control: no-cache", "Pragma: no-cache", )); - curl_setopt($ch, CURLOPT_POSTFIELDS,$requestXML); - + curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXML); + $response = curl_exec($ch); curl_close($ch); - - $upsServiceArray = simplexml_load_string($response); - $upsServices = json_decode(json_encode($upsServiceArray)); + $upsServiceArray = simplexml_load_string($response); + $upsServices = json_decode(json_encode($upsServiceArray)); + $sellerId = 0; if (! empty($cartProduct->marketplace_seller_id)) { $sellerId = $cartProduct->marketplace_seller_id; } if ($response - && isset($upsServices->Response->ResponseStatusDescription) + && isset($upsServices->Response->ResponseStatusDescription) && $upsServices->Response->ResponseStatusDescription == 'Success' ) { + if (isset($upsServices->RatedShipment)) { - foreach ($upsServices->RatedShipment as $services) { - $serviceCode = $services->Service->Code; + foreach ($upsServices->RatedShipment as $service) { + $serviceCode = $service->Service->Code; $matchResult = $this->upsRepository->validateAllowedMethods($serviceCode, $sellerAdminServices); $serviceName = $this->getServiceName($serviceCode); if ($matchResult) { $cartProductServices[$serviceName] = [ 'classId' => $serviceCode, - 'rate' => $services->RatedPackage->TotalCharges->MonetaryValue, - 'currency' => $services->RatedPackage->TotalCharges->CurrencyCode, - 'weight' => $services->BillingWeight->Weight, - 'weightUnit' => $services->BillingWeight->UnitOfMeasurement->Code, + 'rate' => $service->RatedPackage->TotalCharges->MonetaryValue, + 'currency' => $service->RatedPackage->TotalCharges->CurrencyCode, + 'weight' => $service->BillingWeight->Weight, + 'weightUnit' => $service->BillingWeight->UnitOfMeasurement->Code, 'marketplace_seller_id' => $sellerId, 'itemQuantity' => $cartProduct->quantity, ]; @@ -212,7 +213,7 @@ protected function _createSoapClient($address) } } else { $errorLog = $this->getErrorLog($upsServices); - + return false; //to check the error generated in the method; } @@ -221,7 +222,7 @@ protected function _createSoapClient($address) } } - if (! empty($allServices) ) { + if (! empty($allServices)) { return $this->upsRepository->getCommonMethods($allServices); } else { return false; @@ -229,75 +230,40 @@ protected function _createSoapClient($address) } /** - * Map service code - * - * @param $serviceCode - */ - protected function getServiceName($serviceCode) - { - $mapServices = [ - '01' => 'Next Day Air', - '02' => '2nd Day Air', - '03' => 'Ups Ground', - '07' => 'Ups Worldwide Express', - '08' => 'Ups Worldwide Expedited', - '11' => 'Standard', - '12' => '3 Day Select', - '13' => 'Next Day Air Saver', - '14' => 'Next Day Air Early A.M.', - '54' => 'Ups Worldwide Express Plus', - '59' => '2nd Day Air A.M.', - '65' => 'UPS World Wide Saver', - '82' => 'Today Standard', - '83' => 'Today Dedicated Courier', - '84' => 'Today Intercity', - '85' => 'Today Express', - '86' => 'Today Express Saver', - '03' => 'Ups Ground', - ]; - - foreach ($mapServices as $key => $service) { - if ($key == $serviceCode) { - return $service; - } - } - - return $serviceCode; - } - - /** - * convert current weight unit to LBS + * Convert weight to LBS if necessary. * * @param string $weight - **/ - public function getWeight($weight) + * @return float + */ + public function convertWeightToLbs($weight) { $coreWeightUnit = strtoupper(core()->getConfigData('general.general.locale_options.weight_unit')); - + $upsWeightUnit = strtoupper(core()->getConfigData('sales.carriers.ups.weight_unit')); - + $convertedWeight = ''; if ($coreWeightUnit == 'LBS') { if ($upsWeightUnit == 'LBS') { $convertedWeight = $weight; } else { - //kgs to lbs - $convertedWeight = $weight/0.45359237; + // Convert kgs to lbs + $convertedWeight = $weight / 0.45359237; } } else { - $convertedWeight = $weight/0.45359237; + $convertedWeight = $weight / 0.45359237; } return $convertedWeight; } /** - * Get The Current Error + * Log the error. * - * @param string $error - **/ - public function getErrorLog($errors) + * @param object $errors + * @return bool + */ + public function getErrorLog($errors) { $exception = []; @@ -322,4 +288,42 @@ public function getErrorLog($errors) return true; } + + /** + * Map service code to service name. + * + * @param string $serviceCode + * @return string + */ + protected function getServiceName($serviceCode) + { + $mapServices = [ + '01' => 'Next Day Air', + '02' => '2nd Day Air', + '03' => 'Ups Ground', + '07' => 'Ups Worldwide Express', + '08' => 'Ups Worldwide Expedited', + '11' => 'Standard', + '12' => '3 Day Select', + '13' => 'Next Day Air Saver', + '14' => 'Next Day Air Early A.M.', + '54' => 'Ups Worldwide Express Plus', + '59' => '2nd Day Air A.M.', + '65' => 'UPS World Wide Saver', + '82' => 'Today Standard', + '83' => 'Today Dedicated Courier', + '84' => 'Today Intercity', + '85' => 'Today Express', + '86' => 'Today Express Saver', + '03' => 'Ups Ground', + ]; + + foreach ($mapServices as $key => $service) { + if ($key == $serviceCode) { + return $service; + } + } + + return $serviceCode; + } } \ No newline at end of file diff --git a/packages/Webkul/UpsShipping/src/Repositories/UpsRepository.php b/packages/Webkul/UpsShipping/src/Repositories/UpsRepository.php index bcdfe3b..73b6cf7 100644 --- a/packages/Webkul/UpsShipping/src/Repositories/UpsRepository.php +++ b/packages/Webkul/UpsShipping/src/Repositories/UpsRepository.php @@ -7,6 +7,7 @@ class UpsRepository /** * Get the Admin Products * + * @param array $cartItems * @return array */ public function getSellerAdminData($cartItems) @@ -17,14 +18,14 @@ public function getSellerAdminData($cartItems) /** * Validate if a service is allowed * - * @param string $service + * @param string $serviceCode * @param array $allowedServices * @return bool */ - public function validateAllowedMethods($service, $allowedServices) + public function validateAllowedMethods($serviceCode, $allowedServices) { foreach ($allowedServices as $methods) { - if (in_array($service, $methods)) { + if (in_array($serviceCode, $methods)) { return true; } } @@ -40,16 +41,14 @@ public function validateAllowedMethods($service, $allowedServices) */ public function getAllowedMethods($allServices) { - $allowedServices = explode(",", core()->getConfigData('sales.carriers.ups.ups_services')); + $allowedServiceCodes = explode(",", core()->getConfigData('sales.carriers.ups.ups_services')); + $allowedMethods = []; foreach ($allServices as $services) { - $allowedMethod = []; - foreach ($services as $serviceType => $upsService) { - if (in_array($serviceType, $allowedServices)) { - $allowedMethod[] = [$serviceType => $upsService]; - } - } + $allowedMethod = array_filter($services, function ($serviceCode) use ($allowedServiceCodes) { + return in_array($serviceCode, $allowedServiceCodes); + }, ARRAY_FILTER_USE_KEY); if (! empty($allowedMethod)) { $allowedMethods[] = $allowedMethod; @@ -67,23 +66,23 @@ public function getAllowedMethods($allServices) */ public function getCommonMethods($methods) { - $availableServicesArray = []; + $availableServiceCodes = []; - foreach ($methods as $fedexMethods) { - foreach (array_keys($fedexMethods) as $serviceType) { - $availableServicesArray[] = $serviceType; - } + foreach ($methods as $upsMethods) { + $availableServiceCodes = array_merge($availableServiceCodes, array_keys($upsMethods)); } - $countMethods = count($methods); - $countServices = array_count_values($availableServicesArray); + $methodsCount = count($methods); + + $serviceCounts = array_count_values($availableServiceCodes); + $finalServices = []; - foreach ($countServices as $serviceType => $servicesCount) { - if ($servicesCount == $countMethods) { - foreach ($methods as $fedexMethods) { - if (isset($fedexMethods[$serviceType])) { - $finalServices[$serviceType][] = $fedexMethods[$serviceType]; + foreach ($serviceCounts as $serviceCode => $serviceCount) { + if ($serviceCount == $methodsCount) { + foreach ($methods as $upsMethods) { + if (isset($upsMethods[$serviceCode])) { + $finalServices[$serviceCode][] = $upsMethods[$serviceCode]; } } } diff --git a/packages/Webkul/UpsShipping/src/Resources/views/configurations/field-type.blade.php b/packages/Webkul/UpsShipping/src/Resources/views/configurations/field-type.blade.php index fefd168..e1a57ce 100644 --- a/packages/Webkul/UpsShipping/src/Resources/views/configurations/field-type.blade.php +++ b/packages/Webkul/UpsShipping/src/Resources/views/configurations/field-type.blade.php @@ -108,7 +108,6 @@ class="text-gray-600 dark:text-gray-300" @elseif ($field['type'] == 'editor') -