diff --git a/README.md b/README.md index 2aa11d1..2d10113 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,9 @@ 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. @@ -87,8 +87,6 @@ _* 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. diff --git a/src/Model/Carrier.php b/src/Model/Carrier.php index 0ea580d..adf228a 100644 --- a/src/Model/Carrier.php +++ b/src/Model/Carrier.php @@ -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, @@ -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, @@ -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, @@ -387,6 +361,32 @@ 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 */ @@ -394,15 +394,6 @@ 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() @@ -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']; diff --git a/src/Model/Config/Source/CustomerAddressAttributes.php b/src/Model/Config/Source/CustomerAddressAttributes.php new file mode 100644 index 0000000..776461b --- /dev/null +++ b/src/Model/Config/Source/CustomerAddressAttributes.php @@ -0,0 +1,82 @@ +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; + } +} diff --git a/src/Model/OcaApi.php b/src/Model/OcaApi.php index bd93a4b..5ccfac3 100644 --- a/src/Model/OcaApi.php +++ b/src/Model/OcaApi.php @@ -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(), diff --git a/src/etc/adminhtml/di.xml b/src/etc/adminhtml/di.xml index cbad6d1..e298fb8 100644 --- a/src/etc/adminhtml/di.xml +++ b/src/etc/adminhtml/di.xml @@ -1,6 +1,6 @@ + xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> Gento_Oca::operatories @@ -10,10 +10,11 @@ Gento\Oca\Model\Operatory\CollectionProvider + xsi:type="object">Gento\Oca\Model\Operatory\CollectionProvider Gento\Oca\Model\Operatory\Executor\Delete A total of %1 Operatories have been deleted. - An error occurred while deleting Operatories. + An error occurred while deleting Operatories. @@ -21,8 +22,10 @@ Gento\Oca\Model\Operatory\Executor\Delete operatory_id Operatory was deleted - Requested Operatory for delete does not exist. - There was a problem deleting the Operatory + Requested Operatory for delete does not exist. + There was a problem deleting the Operatory @@ -37,7 +40,7 @@ Gento\Oca\Model\Branch\Executor\Delete A total of %1 Branches have been deleted. An error occurred while deleting Branches. + translate="true">An error occurred while deleting Branches. @@ -45,8 +48,10 @@ Gento\Oca\Model\Branch\Executor\Delete branch_id Branch was deleted - Requested Branch for delete does not exist. - There was a problem deleting the Branch + Requested Branch for delete does not exist. + There was a problem deleting the Branch diff --git a/src/etc/adminhtml/system.xml b/src/etc/adminhtml/system.xml index 25da515..29df575 100644 --- a/src/etc/adminhtml/system.xml +++ b/src/etc/adminhtml/system.xml @@ -1,159 +1,14 @@ + xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
+ showInStore="1"> - - - Enable to edit specific values - Magento\Config\Model\Config\Source\Yesno - - - - - - - Magento\Payment\Model\Config\Source\Allspecificcountries - - - - Magento\Directory\Model\Config\Source\Country - - 1 - - - - - Magento\Config\Model\Config\Source\Yesno - - - - - - - - - - OCA E-Pak account number - - - - OCA E-Pak username - - - - Magento\Config\Model\Config\Backend\Encrypted - OCA E-Pak password - - - - Ingrese el numero sin guiones. Ej: 30536259194 - - - - - - - - - - Ej: https://www5.oca.com.ar/ocaepakNet/Views/ConsultaTracking/TrackingConsult.aspx?numberTracking= - - - - - Days between the order is received and the package is sent to OCA - - - - This will add only on checkout info, and will not be informed to OCA - - - - Enable the display of days on carrier - Magento\Config\Model\Config\Source\Yesno - - - - The time frame when the shipment should be picked up by OCA - Gento\Oca\Model\Config\Source\ReceptionTime - - - - Enable draft to shippings (If true, need to be confirmed on OCA Epak Dashboard) - Magento\Config\Model\Config\Source\Yesno - - - - One by line - - - - Variables: code, short_name, address_street, address_number, address_floor, address_dpt, address_tower, telephone, email, city, zipcode - - - - Enable to auto populate branches - Magento\Config\Model\Config\Source\Yesno - - - - 1 - - - Default volume of a shipping box (in cubic meters) - - - - Gento\Oca\Model\Config\Source\ProductAttribute - - - - Gento\Oca\Model\Config\Source\ProductAttribute - - - - Gento\Oca\Model\Config\Source\ProductAttribute - - - - Gento\Oca\Model\Config\Source\UnitsAttribute - - + + +
diff --git a/src/etc/adminhtml/system/customer_address.xml b/src/etc/adminhtml/system/customer_address.xml new file mode 100644 index 0000000..3a03f10 --- /dev/null +++ b/src/etc/adminhtml/system/customer_address.xml @@ -0,0 +1,28 @@ + + + + + + + Gento\Oca\Model\Config\Source\CustomerAddressAttributes + + + + Gento\Oca\Model\Config\Source\CustomerAddressAttributes + + + + Gento\Oca\Model\Config\Source\CustomerAddressAttributes + + + + Gento\Oca\Model\Config\Source\CustomerAddressAttributes + + + diff --git a/src/etc/adminhtml/system/general.xml b/src/etc/adminhtml/system/general.xml new file mode 100644 index 0000000..92c3c7d --- /dev/null +++ b/src/etc/adminhtml/system/general.xml @@ -0,0 +1,146 @@ + + + + + 1 + + + Enable to edit specific values + Magento\Config\Model\Config\Source\Yesno + carriers/gento_oca/active + + + + carriers/gento_oca/title + + + + Magento\Payment\Model\Config\Source\Allspecificcountries + carriers/gento_oca/allowspecific + + + + Magento\Directory\Model\Config\Source\Country + + 1 + + carriers/gento_oca/specificcountry + + + + Magento\Config\Model\Config\Source\Yesno + carriers/gento_oca/showmethod + + + + carriers/gento_oca/specificerrmsg + + + + carriers/gento_oca/sort_order + + + + OCA E-Pak account number + carriers/gento_oca/account_number + + + + OCA E-Pak username + carriers/gento_oca/username + + + + Magento\Config\Model\Config\Backend\Encrypted + OCA E-Pak password + carriers/gento_oca/password + + + + Ingrese el numero sin guiones. Ej: 30536259194 + carriers/gento_oca/cuit + + + + carriers/gento_oca/service_url + + + + carriers/gento_oca/elocker_service_url + + + + Ej: https://www5.oca.com.ar/ocaepakNet/Views/ConsultaTracking/TrackingConsult.aspx?numberTracking= + carriers/gento_oca/tracking_url + + + + Days between the order is received and the package is sent to OCA + carriers/gento_oca/days + + + + This will add only on checkout info, and will not be informed to OCA + carriers/gento_oca/days_extra + + + + Enable the display of days on carrier + Magento\Config\Model\Config\Source\Yesno + carriers/gento_oca/show_days + + + + The time frame when the shipment should be picked up by OCA + Gento\Oca\Model\Config\Source\ReceptionTime + carriers/gento_oca/reception_time + + + + Enable draft to shippings (If true, need to be confirmed on OCA Epak Dashboard) + Magento\Config\Model\Config\Source\Yesno + carriers/gento_oca/confirm + + + + One by line + carriers/gento_oca/disabled_cp + + + + Variables: code, short_name, address_street, address_number, address_floor, address_dpt, address_tower, telephone, email, city, zipcode + carriers/gento_oca/branch_description + + + + Enable to auto populate branches + Magento\Config\Model\Config\Source\Yesno + carriers/gento_oca/branch_autopopulate + + + diff --git a/src/etc/adminhtml/system/volume.xml b/src/etc/adminhtml/system/volume.xml new file mode 100644 index 0000000..69184a5 --- /dev/null +++ b/src/etc/adminhtml/system/volume.xml @@ -0,0 +1,33 @@ + + + + + + + Default volume of a shipping box (in cubic meters) + + + + Gento\Oca\Model\Config\Source\ProductAttribute + + + + Gento\Oca\Model\Config\Source\ProductAttribute + + + + Gento\Oca\Model\Config\Source\ProductAttribute + + + + Gento\Oca\Model\Config\Source\UnitsAttribute + + + diff --git a/src/etc/config.xml b/src/etc/config.xml index 2f795c9..06a5ab7 100644 --- a/src/etc/config.xml +++ b/src/etc/config.xml @@ -1,13 +1,13 @@ + xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd"> 0 Gento\Oca\Model\Carrier OCA - 50 + 100 http://webservice.oca.com.ar/oep_tracking_test/Oep_Track.asmx http://webservice.oca.com.ar/epak_tracking_test/Oep_TrackEPak.asmx https://www5.oca.com.ar/ocaepakNet/Views/ConsultaTracking/TrackingConsult.aspx?numberTracking= @@ -18,6 +18,12 @@ {{/if}}{{if address_tower}}Torre: {{var address_tower}} {{/if}}{{if telephone}}{{var telephone}} {{/if}}{{if email}}{{var email}} {{/if}}]]> + + 0 + + + __street_line_1 + diff --git a/src/i18n/es_AR.csv b/src/i18n/es_AR.csv index b04bb6e..75828f8 100644 --- a/src/i18n/es_AR.csv +++ b/src/i18n/es_AR.csv @@ -1,6 +1,10 @@ +"< Street Line %1 >","< Street Line %1 >" +"Customer Address","Dirección del cliente" "Delete Branch","Borrar sucursal" "Delete Operatory","Delete operatoria" Branches,Sucursales +Floor,Piso +Department,Departmento "New Branch","Nueva sucursal" "Something went wrong while saving the Branch.","Ocurrió un error al intentar guardar la sucursal." "You saved the Branch","La sucursal fue guardada"