Skip to content

Commit

Permalink
Merge pull request #16 from gento-arg/feature/15-configuracion-atribu…
Browse files Browse the repository at this point in the history
…tos-direccion

#15 Configuracion de atributos de direccion
  • Loading branch information
manuelcanepa authored Jul 21, 2021
2 parents 3a39511 + 11a0234 commit c5a20ca
Show file tree
Hide file tree
Showing 11 changed files with 373 additions and 213 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,16 @@ contratos y estimar los costos de envío. A continuación se explican los difere
- **Tracking URL:** Ésta URL será a la que se le concatenará el número de seguimiento para rastreo. Por
defecto: `https://www5.oca.com.ar/ocaepakNet/Views/ConsultaTracking/TrackingConsult.aspx?numberTracking=`. Tener en
cuenta que OCA suele cambiar esta URL.
- **Min box volume:** (***) Para calcular los costos de envío, OCA requiere que se le indique el volumen de lo que se va
- **Min box volume:** Para calcular los costos de envío, OCA requiere que se le indique el volumen de lo que se va
a enviar, en caso de no tener atributos en los productos con los que se pueda calcular el volumen, se utilizará este
valor.
valor. Dependiendo el contrato con OCA puede que este valor no sea necesario y se utilice el peso.
- **Product (width|height|length) attribute:** Atributo del producto que se utilizará para calcular el volumen.
- **Unit product attribute:** Unidad de medida en la que está expresada la dimensión del producto.

_* Valor requerido para el cálculo de costo de envío_

_** Valor requerido para impresión de etiquetas_

_*** Valor requerido en caso de no tener atributos de dimensiones en los productos_

### Operatorias

En el menú `GENTo -> Operatories` se deben agregar las operatorias con las que se desea trabajar.
Expand Down
95 changes: 49 additions & 46 deletions src/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ public function collectRates(RateRequest $request)
return $rateResult;
}

protected function calculateVolume(Product $product)
{
/** @var Product $product */
$product = $this->productRepository->getById($product->getId());

list($width, $height, $length) = $this->helper->getProductSize($product);

return $width * $height * $length;
}

public function processOperatory(
$operatory,
Result $rateResult,
Expand Down Expand Up @@ -273,7 +283,7 @@ public function processOperatory(
$quoteValue = 0;
}

$plazoEntrega = $tarifa->PlazoEntrega + (int)$this->_scopeConfig->getValue('carriers/gento_oca/days_extra');
$plazoEntrega = $tarifa->PlazoEntrega + (int) $this->_scopeConfig->getValue('carriers/gento_oca/days_extra');
$this->_addRate(
$rateResult,
$operatory,
Expand All @@ -285,42 +295,6 @@ public function processOperatory(
return $rateResult;
}

/**
* @inheritdoc
*/
public function isTrackingAvailable()
{
return true;
}

/**
* @inheritdoc
*/
public function isShippingLabelsAvailable()
{
return true;
}

/**
* @inheritdoc
*/
public function getContainerTypes(DataObject $params = null): array
{
return [
'gento_oca' => $this->getConfigData('title')
];
}

protected function calculateVolume(Product $product)
{
/** @var Product $product */
$product = $this->productRepository->getById($product->getId());

list($width, $height, $length) = $this->helper->getProductSize($product);

return $width * $height * $length;
}

protected function _addRate(
$rateResult,
$operatory,
Expand Down Expand Up @@ -387,22 +361,39 @@ protected function getStoreConfig($path)
);
}

/**
* @inheritdoc
*/
public function isTrackingAvailable()
{
return true;
}

/**
* @inheritdoc
*/
public function isShippingLabelsAvailable()
{
return true;
}

/**
* @inheritdoc
*/
public function getContainerTypes(DataObject $params = null): array
{
return [
'gento_oca' => $this->getConfigData('title')
];
}

/**
* @inheritdoc
*/
protected function _doShipmentRequest(DataObject $request)
{
$result = new DataObject();
try {
/**
* WIP
* ✅ Domicilio a Domicilio
* ✅ Domicilio a Sucursal
*
* ❌ Sucursal a Sucursal
* ❌ Sucursal a Domicilio
*/

$shipperProvinceCode = $request->getData('shipper_address_state_or_province_code');
$shipperCountryCode = $request->getData('shipper_address_country_code');
$shipperProvince = $this->_regionFactory->create()
Expand Down Expand Up @@ -435,6 +426,18 @@ protected function _doShipmentRequest(DataObject $request)
}
$request->setCentroImposicionOrigen($originBranch);

$fields = ['street', 'number', 'floor', 'dept'];
$shippingAddress = $order->getShippingAddress();
foreach ($fields as $field) {
$fieldData = $this->getConfigData('customer_address/' . $field);
if (preg_match('/^\_\_street\_line\_([0-9]+)/', $fieldData, $matches)) {
$value = $shippingAddress->getStreetLine($matches[1]);
} else {
$value = $shippingAddress->getData($fieldData);
}
$request->{'setRecipientAddress' . ucfirst($field)}($value);
}

$admision = $this->ocaApi->requestShipment($request);

$data = $admision['data'];
Expand Down
82 changes: 82 additions & 0 deletions src/Model/Config/Source/CustomerAddressAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Gento\Oca\Model\Config\Source;

use Magento\Customer\Api\AddressMetadataInterface;
use Magento\Eav\Api\AttributeRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\Api\SortOrderBuilder;
use Magento\Framework\App\Config\ScopeConfigInterface;

class CustomerAddressAttributes extends AbstractSource
{
/**
* @var SearchCriteriaBuilder
*/
protected $searchCriteriaBuilder;
/**
* @var AttributeRepositoryInterface
*/
protected $attributeRepository;
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var SortOrderBuilder
*/
private $sortOrderBuilder;

/**
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param AttributeRepositoryInterface $attributeRepository
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
SearchCriteriaBuilder $searchCriteriaBuilder,
AttributeRepositoryInterface $attributeRepository,
ScopeConfigInterface $scopeConfig,
SortOrderBuilder $sortOrderBuilder
) {
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->attributeRepository = $attributeRepository;
$this->scopeConfig = $scopeConfig;
$this->sortOrderBuilder = $sortOrderBuilder;
}

/**
* @inheridoc
*/
public function toArray()
{
$attributes = [
'' => __('-- No selected --'),
];
$lineQtys = $this->scopeConfig->getValue('customer/address/street_lines');
for ($i = 1; $i <= $lineQtys; $i++) {
$attributes['__street_line_' . $i] = __('< Street Line %1 >', $i);
}

$sortOrder = $this->sortOrderBuilder
->setField('frontend_label')
->setDirection(SortOrder::SORT_ASC)
->create();
$searchCriteria = $this->searchCriteriaBuilder
->addSortOrder($sortOrder)
->create();

$attributeRepository = $this->attributeRepository->getList(
AddressMetadataInterface::ENTITY_TYPE_ADDRESS,
$searchCriteria
);

foreach ($attributeRepository->getItems() as $attribute) {
$attributes[$attribute->getAttributeCode()] = sprintf('%s (%s)',
$attribute->getFrontendLabel(),
$attribute->getAttributeCode()
);
}
return $attributes;
}
}
6 changes: 3 additions & 3 deletions src/Model/OcaApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,9 @@ protected function getXmlOR(DataObject $request)
'@apellido' => $request->getRecipientContactPersonLastName(),
'@nombre' => $request->getRecipientContactPersonFirstName(),
'@calle' => $request->getRecipientAddressStreet(),
'@nro' => '',
'@piso' => '',
'@depto' => '',
'@nro' => $request->getRecipientAddressNumber(),
'@piso' => $request->getRecipientAddressFloor(),
'@depto' => $request->getRecipientAddressDept(),
'@localidad' => $request->getRecipientAddressCity(),
'@provincia' => $request->getRecipientAddressProvince(),
'@cp' => $request->getRecipientAddressPostalCode(),
Expand Down
21 changes: 13 additions & 8 deletions src/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Gento\Oca\Controller\Adminhtml\Operatory\Index">
<arguments>
<argument name="activeMenuItem" xsi:type="string">Gento_Oca::operatories</argument>
Expand All @@ -10,19 +10,22 @@
<type name="Gento\Oca\Controller\Adminhtml\Operatory\MassDelete">
<arguments>
<argument name="collectionProvider"
xsi:type="object">Gento\Oca\Model\Operatory\CollectionProvider</argument>
xsi:type="object">Gento\Oca\Model\Operatory\CollectionProvider</argument>
<argument name="executor" xsi:type="object">Gento\Oca\Model\Operatory\Executor\Delete</argument>
<argument name="successMessage" xsi:type="string">A total of %1 Operatories have been deleted.</argument>
<argument name="errorMessage" xsi:type="string" translate="true">An error occurred while deleting Operatories.</argument>
<argument name="errorMessage" xsi:type="string"
translate="true">An error occurred while deleting Operatories.</argument>
</arguments>
</type>
<type name="Gento\Oca\Controller\Adminhtml\Operatory\Delete">
<arguments>
<argument name="executor" xsi:type="object">Gento\Oca\Model\Operatory\Executor\Delete</argument>
<argument name="paramName" xsi:type="string">operatory_id</argument>
<argument name="successMessage" xsi:type="string" translate="true">Operatory was deleted</argument>
<argument name="missingEntityErrorMessage" xsi:type="string" translate="true">Requested Operatory for delete does not exist.</argument>
<argument name="generalErrorMessage" xsi:type="string" translate="true">There was a problem deleting the Operatory</argument>
<argument name="missingEntityErrorMessage" xsi:type="string"
translate="true">Requested Operatory for delete does not exist.</argument>
<argument name="generalErrorMessage" xsi:type="string"
translate="true">There was a problem deleting the Operatory</argument>
</arguments>
</type>
<type name="Gento\Oca\Controller\Adminhtml\Branch\Index">
Expand All @@ -37,16 +40,18 @@
<argument name="executor" xsi:type="object">Gento\Oca\Model\Branch\Executor\Delete</argument>
<argument name="successMessage" xsi:type="string">A total of %1 Branches have been deleted.</argument>
<argument name="errorMessage" xsi:type="string"
translate="true">An error occurred while deleting Branches.</argument>
translate="true">An error occurred while deleting Branches.</argument>
</arguments>
</type>
<type name="Gento\Oca\Controller\Adminhtml\Branch\Delete">
<arguments>
<argument name="executor" xsi:type="object">Gento\Oca\Model\Branch\Executor\Delete</argument>
<argument name="paramName" xsi:type="string">branch_id</argument>
<argument name="successMessage" xsi:type="string" translate="true">Branch was deleted</argument>
<argument name="missingEntityErrorMessage" xsi:type="string" translate="true">Requested Branch for delete does not exist.</argument>
<argument name="generalErrorMessage" xsi:type="string" translate="true">There was a problem deleting the Branch</argument>
<argument name="missingEntityErrorMessage" xsi:type="string"
translate="true">Requested Branch for delete does not exist.</argument>
<argument name="generalErrorMessage" xsi:type="string"
translate="true">There was a problem deleting the Branch</argument>
</arguments>
</type>
<type name="Magento\Backend\Block\GlobalSearch">
Expand Down
Loading

0 comments on commit c5a20ca

Please sign in to comment.