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