-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit de5dec5
Showing
10 changed files
with
699 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Correios para Bagisto | ||
|
||
Módulo desenvolvido para adicionar o método de entrega dos Correios na ferramenta de e-Commerce Bagisto | ||
|
||
## Instalação | ||
|
||
@todo | ||
|
||
## Configurações | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "cagartner/bagisto-correios", | ||
"description": "Shipping Method for Correios", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Carlos Gartner", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"cagartner/phpquery": "0.9.10" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Cagartner\\Correios\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Cagartner\\Correios\\Providers\\CorreiosServiceProvider" | ||
], | ||
"aliases": {} | ||
} | ||
}, | ||
"minimum-stability": "dev" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
namespace Cagartner\Correios\Carriers; | ||
|
||
use Cagartner\Correios\Helpers\Consult; | ||
use Config; | ||
use Illuminate\Support\Collection; | ||
use Webkul\Checkout\Models\CartShippingRate; | ||
use Webkul\Checkout\Facades\Cart; | ||
use Webkul\Shipping\Carriers\AbstractShipping; | ||
|
||
/** | ||
* Correios Shipping Methods. | ||
* | ||
* @author Carlos Gartner <[email protected]> | ||
*/ | ||
class Correios extends AbstractShipping | ||
{ | ||
/** | ||
* Correios methods map | ||
*/ | ||
const METHODS_TITLE = [ | ||
'sedex' => 'Sedex', | ||
'sedex_a_cobrar' => 'Sedex a Cobrar', | ||
'sedex_10' => 'Sedex 10', | ||
'sedex_hoje' => 'Sedex Hoje', | ||
'pac' => 'PAC', | ||
'pac_contrato' => 'PAC', | ||
'sedex_contrato' => 'Sedex', | ||
'esedex' => 'e-Sedex', | ||
]; | ||
|
||
/** | ||
* Payment method code | ||
* | ||
* @var string | ||
*/ | ||
protected $code = 'cagartner_correios'; | ||
|
||
/** | ||
* Returns rate for correios | ||
* | ||
* @return array | ||
*/ | ||
public function calculate() | ||
{ | ||
if (!$this->isAvailable()) | ||
return false; | ||
|
||
/** @var \Webkul\Checkout\Models\Cart $cart */ | ||
$cart = Cart::getCart(); | ||
$total_weight = $cart->items->sum('total_weight'); | ||
|
||
$data = [ | ||
'tipo' => $this->getConfigData('methods'), | ||
'formato' => $this->getConfigData('package_type'), // opções: `caixa`, `rolo`, `envelope` | ||
'cep_destino' => $cart->shipping_address->postcode, | ||
'cep_origem' => core()->getConfigData('sales.shipping.origin.zipcode'), | ||
'peso' => $total_weight, // Peso em kilos | ||
'comprimento' => $this->getConfigData('package_length'), // Em centímetros | ||
'altura' => $this->getConfigData('package_height'), // Em centímetros | ||
'largura' => $this->getConfigData('package_width'), // Em centímetros | ||
'diametro' => $this->getConfigData('roll_diameter'), // Em centímetros, no caso de rolo | ||
]; | ||
|
||
if ($this->getConfigData('cod_company') && $this->getConfigData('password')) { | ||
$data['empresa'] = $this->getConfigData('cod_company'); | ||
$data['senha'] = $this->getConfigData('password'); | ||
} | ||
|
||
$consult = new Consult(); | ||
/** @var Collection $result */ | ||
$result = $consult->carriers($data); | ||
$rates = []; | ||
$tax_handling = (int)core()->convertPrice($this->getConfigData('tax_handling')) ?: 0; | ||
|
||
foreach ($result as $item) { | ||
$object = new CartShippingRate; | ||
$object->carrier = 'correios'; | ||
$object->carrier_title = $this->getConfigData('title'); | ||
$object->method = 'cagartner_correios_' . Consult::getTipoIndex($item['codigo']); | ||
$object->method_title = $this->getMethodTitle($item['codigo']); | ||
$object->method_description = $this->getMethodDescription($item['prazo']); | ||
$object->price = core()->convertPrice($item['valor']) + $tax_handling; | ||
$object->base_price = core()->convertPrice($item['valor']) + $tax_handling; | ||
array_push($rates, $object); | ||
} | ||
return $rates; | ||
} | ||
|
||
/** | ||
* @param $code | ||
* @return mixed | ||
*/ | ||
protected function getMethodTitle($code) | ||
{ | ||
$method = Consult::getTipoIndex($code); | ||
return self::METHODS_TITLE[$method]; | ||
} | ||
|
||
/** | ||
* @param $deadline | ||
* @return mixed | ||
*/ | ||
protected function getMethodDescription($deadline) | ||
{ | ||
$template = $this->getConfigData('method_template'); | ||
$extra_time = (int)core()->convertPrice($this->getConfigData('extra_time')) ?: 0; | ||
if (strpos($template, ':dia')) { | ||
$template = str_replace(':dia', ($deadline + $extra_time), $template); | ||
} | ||
return $template; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
return [ | ||
'cagartner_correios' => [ | ||
'code' => 'correios', | ||
'title' => 'Correios', | ||
'description' => 'Correios', | ||
'active' => true, | ||
'class' => \Cagartner\Correios\Carriers\Correios::class, | ||
'methods' => 'sedex,pac', | ||
'tax_handling' => 0, | ||
'extra_time' => 1, | ||
'method_template' => 'Entrega em até :dia dia úteis(s)', | ||
'package_type' => 'caixa', | ||
'package_length' => 16, | ||
'package_height' => 11, | ||
'package_width' => 11, | ||
'roll_diameter' => 0 | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<?php | ||
return [ | ||
[ | ||
'key' => 'sales.carriers.cagartner_correios', | ||
'name' => 'Correios', | ||
'sort' => 1, | ||
'fields' => [ | ||
[ | ||
'name' => 'title', | ||
'title' => 'Title', | ||
'type' => 'text', | ||
'validation' => 'required', | ||
'channel_based' => false, | ||
'locale_based' => true | ||
], [ | ||
'name' => 'description', | ||
'title' => 'Description', | ||
'type' => 'textarea', | ||
'channel_based' => false, | ||
'locale_based' => true | ||
], [ | ||
'name' => 'tax_handling', | ||
'title' => 'Taxa de Manuseio', | ||
'type' => 'text', | ||
'channel_based' => false, | ||
'locale_based' => true, | ||
'validation' => 'required', | ||
], [ | ||
'name' => 'methods', | ||
'title' => 'Methods', | ||
'type' => 'multiselect', | ||
'options' => [ | ||
[ | ||
'title' => 'Sedex', | ||
'value' => 'sedex' | ||
], [ | ||
'title' => 'Sedex a Cobrar', | ||
'value' => 'sedex_a_cobrar' | ||
], [ | ||
'title' => 'Sedex 10', | ||
'value' => 'sedex_10' | ||
], [ | ||
'title' => 'Sedex Hoje', | ||
'value' => 'sedex_hoje' | ||
], [ | ||
'title' => 'PAC', | ||
'value' => 'pac' | ||
], [ | ||
'title' => 'PAC Contrato', | ||
'value' => 'pac_contrato' | ||
], [ | ||
'title' => 'Sedex Contrato', | ||
'value' => 'sedex_contrato' | ||
], [ | ||
'title' => 'e-Sedex', | ||
'value' => 'esedex' | ||
] | ||
], | ||
'validation' => 'required' | ||
], [ | ||
'name' => 'extra_time', | ||
'title' => 'Dias Extras ao Prazo de Entrega', | ||
'type' => 'text', | ||
'channel_based' => false, | ||
'locale_based' => true, | ||
'validation' => 'required', | ||
], [ | ||
'name' => 'method_template', | ||
'title' => 'Template do Retorno', | ||
'type' => 'text', | ||
'channel_based' => false, | ||
'locale_based' => true, | ||
'validation' => 'required', | ||
'info' => 'A variável :dia será substituído pelo retorno dos Correios + os Dias Extras ao Prazo de Entrega definido' | ||
], | ||
[ | ||
'name' => 'package_type', | ||
'title' => 'Formato do Pacote', | ||
'type' => 'select', | ||
'options' => [ | ||
[ | ||
'title' => 'Caixa', | ||
'value' => 'caixa' | ||
], [ | ||
'title' => 'Rolo', | ||
'value' => 'rolo' | ||
], [ | ||
'title' => 'Envelope', | ||
'value' => 'envelope' | ||
] | ||
], | ||
'channel_based' => false, | ||
'locale_based' => true, | ||
'validation' => 'required' | ||
], | ||
[ | ||
'name' => 'package_length', | ||
'title' => 'Comprimento do Pacote', | ||
'type' => 'text', | ||
'channel_based' => false, | ||
'locale_based' => true, | ||
'info' => 'Válido apenas para Formato Caixa', | ||
'validation' => 'required', | ||
], | ||
[ | ||
'name' => 'package_height', | ||
'title' => 'Altura do Pacote', | ||
'type' => 'text', | ||
'channel_based' => false, | ||
'locale_based' => true, | ||
'validation' => 'required', | ||
'info' => 'Válido apenas para Formato Caixa' | ||
], | ||
[ | ||
'name' => 'package_width', | ||
'title' => 'Largura do Pacote', | ||
'type' => 'text', | ||
'channel_based' => false, | ||
'locale_based' => true, | ||
'info' => 'Válido apenas para Formato Caixa', | ||
'validation' => 'required', | ||
], | ||
[ | ||
'name' => 'roll_diameter', | ||
'title' => 'Diâmetro do Rôlo', | ||
'type' => 'text', | ||
'channel_based' => false, | ||
'locale_based' => true, | ||
'info' => 'Válido apenas para Formato Rolo, Manter 0 se não aplicável.', | ||
'validation' => 'required', | ||
], | ||
[ | ||
'name' => 'cod_company', | ||
'title' => 'Código Da Empresa', | ||
'type' => 'text', | ||
'channel_based' => false, | ||
'locale_based' => true, | ||
'info' => 'Código da Empresa junto aos Correios' | ||
], | ||
[ | ||
'name' => 'password', | ||
'title' => 'Senha', | ||
'type' => 'text', | ||
'channel_based' => false, | ||
'locale_based' => true, | ||
'info' => 'Senha da Empresa junto aos Correios' | ||
], | ||
[ | ||
'name' => 'active', | ||
'title' => 'Status', | ||
'type' => 'select', | ||
'options' => [ | ||
[ | ||
'title' => 'Active', | ||
'value' => true | ||
], [ | ||
'title' => 'Inactive', | ||
'value' => false | ||
] | ||
], | ||
'validation' => 'required' | ||
] | ||
] | ||
] | ||
]; |
Oops, something went wrong.