From 194dea05ecdf6757710f1a78260fcfae05c262f1 Mon Sep 17 00:00:00 2001 From: drubu Date: Tue, 1 Feb 2022 16:01:32 -0300 Subject: [PATCH] Logistica inversa + servicio bigger --- .../Andreani/Api/Data/RLAddressInterface.php | 212 +++++++++++ .../Andreani/Api/Data/RLItemInterface.php | 77 ++++ .../Andreani/Api/Data/RLOrderInterface.php | 143 +++++++ .../Api/Data/ReverseLogisticsInterface.php | 109 ++++++ .../Andreani/Block/Adminhtml/Edit/Edit.php | 92 +++++ .../Edit/Tab/View/ReverseLogistics.php | 195 ++++++++++ .../Adminhtml/Order/Tab/ReverseLogistics.php | 103 +++++ .../Block/Adminhtml/Order/View/Info.php | 358 ++++++++++++++++++ .../Adminhtml/ReverseLogistics/Create.php | 101 +++++ .../ReverseLogistics/Create/Form.php | 158 ++++++++ .../ReverseLogistics/Create/Items.php | 209 ++++++++++ .../Controller/Adminhtml/Order/Operations.php | 143 ++++++- .../Adminhtml/Pages/ReverseLogistics.php | 70 ++++ .../Adminhtml/Tab/ReverseLogistics.php | 89 +++++ .../Controller/Checkout/PickupRates.php | 2 +- app/code/DrubuNet/Andreani/Helper/Data.php | 16 + .../Andreani/Model/Carrier/BiggerDelivery.php | 172 +++++++++ .../Andreani/Model/Carrier/PickupDelivery.php | 3 + .../Model/Carrier/PriorityDelivery.php | 3 + .../Model/Carrier/StandardDelivery.php | 3 + .../DrubuNet/Andreani/Model/RLAddress.php | 305 +++++++++++++++ app/code/DrubuNet/Andreani/Model/RLItem.php | 118 ++++++ app/code/DrubuNet/Andreani/Model/RLOrder.php | 318 ++++++++++++++++ .../Model/ResourceModel/RLAddress.php | 24 ++ .../ResourceModel/RLAddress/Collection.php | 29 ++ .../Andreani/Model/ResourceModel/RLItem.php | 24 ++ .../Model/ResourceModel/RLItem/Collection.php | 31 ++ .../Andreani/Model/ResourceModel/RLOrder.php | 130 +++++++ .../ResourceModel/RLOrder/Collection.php | 29 ++ .../Model/ReverseLogisticsRepository.php | 183 +++++++++ .../Andreani/Model/ShippingProcessor.php | 181 ++++++++- .../Model/Source/AttributesOptions.php | 36 ++ .../Andreani/Service/AndreaniApiService.php | 10 +- .../DrubuNet/Andreani/Setup/UpgradeSchema.php | 88 +++++ .../Listing/OrderDataProvider.php | 1 + .../DrubuNet/Andreani/etc/adminhtml/menu.xml | 9 - .../Andreani/etc/adminhtml/system.xml | 68 ++++ app/code/DrubuNet/Andreani/etc/config.xml | 14 + app/code/DrubuNet/Andreani/etc/module.xml | 2 +- .../andreani_pages_reverselogistics.xml | 16 + .../layout/andreani_tab_reverselogistics.xml | 12 + .../adminhtml/layout/sales_order_view.xml | 21 + .../adminhtml/templates/create/form.phtml | 337 +++++++++++++++++ .../adminhtml/templates/create/items.phtml | 161 ++++++++ .../templates/order/tab/view/order_info.phtml | 1 + .../tab/view/reverse_logistics_grid.phtml | 0 .../adminhtml/templates/order/view/info.phtml | 188 +++++++++ .../andreani_reverse_logistics_grid.xml | 209 ++++++++++ .../view/checkout/pickup/pickup-andreani.js | 2 +- 49 files changed, 4782 insertions(+), 23 deletions(-) create mode 100644 app/code/DrubuNet/Andreani/Api/Data/RLAddressInterface.php create mode 100644 app/code/DrubuNet/Andreani/Api/Data/RLItemInterface.php create mode 100644 app/code/DrubuNet/Andreani/Api/Data/RLOrderInterface.php create mode 100644 app/code/DrubuNet/Andreani/Api/Data/ReverseLogisticsInterface.php create mode 100644 app/code/DrubuNet/Andreani/Block/Adminhtml/Edit/Edit.php create mode 100644 app/code/DrubuNet/Andreani/Block/Adminhtml/Edit/Tab/View/ReverseLogistics.php create mode 100644 app/code/DrubuNet/Andreani/Block/Adminhtml/Order/Tab/ReverseLogistics.php create mode 100644 app/code/DrubuNet/Andreani/Block/Adminhtml/Order/View/Info.php create mode 100644 app/code/DrubuNet/Andreani/Block/Adminhtml/ReverseLogistics/Create.php create mode 100644 app/code/DrubuNet/Andreani/Block/Adminhtml/ReverseLogistics/Create/Form.php create mode 100644 app/code/DrubuNet/Andreani/Block/Adminhtml/ReverseLogistics/Create/Items.php create mode 100644 app/code/DrubuNet/Andreani/Controller/Adminhtml/Pages/ReverseLogistics.php create mode 100644 app/code/DrubuNet/Andreani/Controller/Adminhtml/Tab/ReverseLogistics.php create mode 100644 app/code/DrubuNet/Andreani/Model/Carrier/BiggerDelivery.php create mode 100644 app/code/DrubuNet/Andreani/Model/RLAddress.php create mode 100644 app/code/DrubuNet/Andreani/Model/RLItem.php create mode 100644 app/code/DrubuNet/Andreani/Model/RLOrder.php create mode 100644 app/code/DrubuNet/Andreani/Model/ResourceModel/RLAddress.php create mode 100644 app/code/DrubuNet/Andreani/Model/ResourceModel/RLAddress/Collection.php create mode 100644 app/code/DrubuNet/Andreani/Model/ResourceModel/RLItem.php create mode 100644 app/code/DrubuNet/Andreani/Model/ResourceModel/RLItem/Collection.php create mode 100644 app/code/DrubuNet/Andreani/Model/ResourceModel/RLOrder.php create mode 100644 app/code/DrubuNet/Andreani/Model/ResourceModel/RLOrder/Collection.php create mode 100644 app/code/DrubuNet/Andreani/Model/ReverseLogisticsRepository.php create mode 100644 app/code/DrubuNet/Andreani/Model/Source/AttributesOptions.php create mode 100644 app/code/DrubuNet/Andreani/view/adminhtml/layout/andreani_pages_reverselogistics.xml create mode 100644 app/code/DrubuNet/Andreani/view/adminhtml/layout/andreani_tab_reverselogistics.xml create mode 100644 app/code/DrubuNet/Andreani/view/adminhtml/layout/sales_order_view.xml create mode 100644 app/code/DrubuNet/Andreani/view/adminhtml/templates/create/form.phtml create mode 100644 app/code/DrubuNet/Andreani/view/adminhtml/templates/create/items.phtml create mode 100644 app/code/DrubuNet/Andreani/view/adminhtml/templates/order/tab/view/order_info.phtml create mode 100644 app/code/DrubuNet/Andreani/view/adminhtml/templates/order/tab/view/reverse_logistics_grid.phtml create mode 100644 app/code/DrubuNet/Andreani/view/adminhtml/templates/order/view/info.phtml create mode 100644 app/code/DrubuNet/Andreani/view/adminhtml/ui_component/andreani_reverse_logistics_grid.xml diff --git a/app/code/DrubuNet/Andreani/Api/Data/RLAddressInterface.php b/app/code/DrubuNet/Andreani/Api/Data/RLAddressInterface.php new file mode 100644 index 0000000..023a37b --- /dev/null +++ b/app/code/DrubuNet/Andreani/Api/Data/RLAddressInterface.php @@ -0,0 +1,212 @@ +registry = $registry; + $this->_objectId = 'id'; + $this->_blockGroup = 'Dotdigitalgroup_Email'; + $this->_controller = 'adminhtml_rules'; + $data = []; + parent::__construct($context, $data); + $orderId = $registry->registry('current_order')->getId(); + $isResendConfigured = $andreaniHelper->getRlContractByType('resend_contract') != ''; + $isChangeConfigured = $andreaniHelper->getRlContractByType('change_contract') != ''; + $isWithdrawConfigured = $andreaniHelper->getRlContractByType('withdraw_contract') != ''; + + if($isResendConfigured) { + $resendOrderUrl = $this->getUrl('andreani/pages/reverselogistics/operation/resend_order',['order_id' => $orderId]); + $this->addButton( + 'resend_order', + [ + 'label' => __('Generar Reenvio'), + 'onclick' => 'setLocation(\'' . $resendOrderUrl . '\')', + 'class' => 'reset' + ], + -1 + ); + } + if($isChangeConfigured) { + $changeOrderUrl = $this->getUrl('andreani/pages/reverselogistics/operation/change_order',['order_id' => $orderId]); + $this->addButton( + 'change_order', + [ + 'label' => __('Generar Cambio'), + 'onclick' => 'setLocation(\'' . $changeOrderUrl . '\')', + 'class' => 'reset' + ], + -1 + ); + } + if($isWithdrawConfigured) { + $withdrawOrderUrl = $this->getUrl('andreani/pages/reverselogistics/operation/withdraw_order',['order_id' => $orderId]); + $this->addButton( + 'withdraw_order', + [ + 'label' => __('Generar Retiro/Devolución'), + 'onclick' => 'setLocation(\'' . $withdrawOrderUrl . '\')', + 'class' => 'reset' + ], + -1 + ); + } + + if(!$isResendConfigured && !$isChangeConfigured && !$isWithdrawConfigured){ + $configureAndreaniRlUrl = $this->getUrl('adminhtml/system_config/edit/section/shipping'); + $this->addButton( + 'configure_andreani_rl', + [ + 'label' => __('Configurar contratos de logistica inversa'), + 'onclick' => 'setLocation(\'' . $configureAndreaniRlUrl . '\')', + 'class' => 'reset' + ], + -1 + ); + } + + $this->buttonList->remove('save'); + $this->buttonList->remove('back'); + $this->buttonList->remove('reset'); + + + } +} diff --git a/app/code/DrubuNet/Andreani/Block/Adminhtml/Edit/Tab/View/ReverseLogistics.php b/app/code/DrubuNet/Andreani/Block/Adminhtml/Edit/Tab/View/ReverseLogistics.php new file mode 100644 index 0000000..daf9597 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Block/Adminhtml/Edit/Tab/View/ReverseLogistics.php @@ -0,0 +1,195 @@ +_logger = $logger; + $this->_coreRegistry = $coreRegistry; + $this->_collectionFactory = $collectionFactory; + parent::__construct($context, $backendHelper, $data); + } + + /** + * Initialize the orders grid. + * + * @return void + */ + protected function _construct() + { + parent::_construct(); + $this->setUseAjax(true); + $this->setId('andreani_order_reverselogisticsgrid'); + $this->setDefaultSort('created_at', 'desc'); + $this->setSortable(false); +// $this->setPagerVisibility(false); + + $this->setFilterVisibility(false); + $this->setEmptyText(__('No Shipments Found')); + } + + /** + * {@inheritdoc} + */ + protected function _prepareCollection() + { + $orderId = $this->getParam('order_id'); + $collection = $this->_collectionFactory->create(); + $collection->addFieldToFilter(RLOrderInterface::ORDER_ID, ['eq' => $orderId]); + $this->setCollection($collection); + return parent::_prepareCollection(); + } + + /** + * {@inheritdoc} + */ + protected function _prepareColumns() + { + $this->addColumn( + RLOrderInterface::ID, + ['header' => __('ID'), 'index' => RLOrderInterface::ID, 'filter_index' => 'e.id', 'type' => 'number', 'width' => '100px'] + ); + $this->addColumn( + 'operation_label', + [ + 'header' => __('Tipo de envio'), + 'index' => 'operation_label', + ] + ); +// $this->addColumn( +// RLOrderInterface::OPERATION, +// [ +// 'header' => __('Tipo de envio'), +// 'index' => RLOrderInterface::OPERATION, +// ] +// ); + $this->addColumn( + RLOrderInterface::TRACKING_NUMBER, + [ + 'header' => __('Numero de tracking'), + 'index' => RLOrderInterface::TRACKING_NUMBER, + ] + ); + $this->addColumn( + RLOrderInterface::CREATED_AT, + [ + 'header' => __('Fecha de creacion'), + 'index' => RLOrderInterface::CREATED_AT, + ] + ); + + $this->addColumn('action', + array( + 'header'=> __('Action'), + 'width' => '100', + 'type' => 'action', + 'getter'=> 'getId', + 'actions' => array( + array( + 'caption' => __('View'), + 'url' => array('base'=> 'andreani/pages/reverselogistics/operation/view'), + 'field' => 'andreani_order_id' + ) + ), + 'filter'=> false, + 'is_system' => true, + 'sortable' => false, + )); + + return parent::_prepareColumns(); + } + + /** + * Prepare grid mass actions + * + * @return void + */ + protected function _prepareMassaction() + { + $this->setMassactionIdField('id'); + $this->setMassactionIdFilter('e.id'); + $this->getMassactionBlock()->setUseAjax(false); + $this->getMassactionBlock()->setFormFieldName('andreani_rl_orders_ids'); + + $this->getMassactionBlock()->addItem( + 'mass_print_rl_labels', + [ + 'label' => __('Imprimir Guias'), + 'url' => $this->getUrl( + 'andreani/order/operations/', ['operation' => 'mass_print_rl_labels','_current' => true,'form_key' => $this->getFormKey()] + ), + ] + ); + } + + /** + * @inheritdoc + */ + protected function _prepareMassactionColumn() + { + parent::_prepareMassactionColumn(); + /** needs for correct work of mass action select functionality */ + $this->setMassactionIdField('id'); + + return $this; + } + + + /** + * Get headers visibility + * + * @return bool + * + * @SuppressWarnings(PHPMD.BooleanGetMethodName) + */ + public function getHeadersVisibility() + { + return $this->getCollection()->getSize() >= 0; + } + + /** + * {@inheritdoc} + */ + public function getRowUrl($row) + { + return $this->getUrl('andreani/pages/reverselogistics/operation/view', ['andreani_order_id' => $row->getId(),'order_id' => $row->getOrderId()]); + } +} \ No newline at end of file diff --git a/app/code/DrubuNet/Andreani/Block/Adminhtml/Order/Tab/ReverseLogistics.php b/app/code/DrubuNet/Andreani/Block/Adminhtml/Order/Tab/ReverseLogistics.php new file mode 100644 index 0000000..13a3b80 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Block/Adminhtml/Order/Tab/ReverseLogistics.php @@ -0,0 +1,103 @@ +_coreRegistry = $registry; + parent::__construct($context, $data); + } + + /** + * Retrieve order model instance + * + * @return \Magento\Sales\Model\Order + */ + public function getOrder() + { + return $this->_coreRegistry->registry('current_order'); + } + + /** + * {@inheritdoc} + */ + public function getTabLabel() + { + return 'Andreani - Logistica Inversa'; + } + + /** + * {@inheritdoc} + */ + public function getTabTitle() + { + return 'Logistica Inversa'; + } + + /** + * {@inheritdoc} + */ + public function canShowTab() + { + if ($this->getOrder()->getIsVirtual()) { + return false; + } + return true; + } + + /** + * {@inheritdoc} + */ + public function isHidden() + { + return false; + } + + public function getTabUrl() + { + return $this->getUrl('andreani/tab/reverselogistics', ['_current' => true]); + } + + /** + * Get Tab Class + * + * @return string + */ + public function getTabClass() + { + return 'ajax only'; + } + + /** + * Get Class + * + * @return string + */ + public function getClass() + { + return $this->getTabClass(); + } + +} \ No newline at end of file diff --git a/app/code/DrubuNet/Andreani/Block/Adminhtml/Order/View/Info.php b/app/code/DrubuNet/Andreani/Block/Adminhtml/Order/View/Info.php new file mode 100644 index 0000000..0b00a78 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Block/Adminhtml/Order/View/Info.php @@ -0,0 +1,358 @@ +groupRepository = $groupRepository; + $this->metadata = $metadata; + $this->_metadataElementFactory = $elementFactory; + $this->addressRenderer = $addressRenderer; + parent::__construct($context, $registry, $adminHelper, $groupRepository, $metadata, $elementFactory, $addressRenderer, $data); + } + + /** + * Retrieve required options from parent + * + * @throws \Magento\Framework\Exception\LocalizedException + * @return void + */ + protected function _beforeToHtml() + { + if (!$this->getParentBlock()) { + throw new \Magento\Framework\Exception\LocalizedException( + __('Please correct the parent block for this block.') + ); + } + $this->setOrder($this->getParentBlock()->getOrder()); + + foreach ($this->getParentBlock()->getOrderInfoData() as $key => $value) { + $this->setDataUsingMethod($key, $value); + } + + parent::_beforeToHtml(); + } + + /** + * Get order store name + * + * @return null|string + */ + public function getOrderStoreName() + { + if ($this->getOrder()) { + $storeId = $this->getOrder()->getStoreId(); + if ($storeId === null) { + $deleted = __(' [deleted]'); + return nl2br($this->getOrder()->getStoreName()) . $deleted; + } + $store = $this->_storeManager->getStore($storeId); + $name = [$store->getWebsite()->getName(), $store->getGroup()->getName(), $store->getName()]; + return implode('
', $name); + } + + return null; + } + + /** + * Return name of the customer group. + * + * @return string + */ + public function getCustomerGroupName() + { + if ($this->getOrder()) { + $customerGroupId = $this->getOrder()->getCustomerGroupId(); + try { + if ($customerGroupId !== null) { + return $this->groupRepository->getById($customerGroupId)->getCode(); + } + } catch (NoSuchEntityException $e) { + return ''; + } + } + + return ''; + } + + /** + * Get URL to edit the customer. + * + * @return string + */ + public function getCustomerViewUrl() + { + if ($this->getOrder()->getCustomerIsGuest() || !$this->getOrder()->getCustomerId()) { + return ''; + } + + return $this->getUrl('customer/index/edit', ['id' => $this->getOrder()->getCustomerId()]); + } + + /** + * Get order view URL. + * + * @param int $orderId + * @return string + */ + public function getViewUrl($orderId) + { + return $this->getUrl('sales/order/view', ['order_id' => $orderId]); + } + + /** + * Find sort order for account data + * Sort Order used as array key + * + * @param array $data + * @param int $sortOrder + * @return int + */ + protected function _prepareAccountDataSortOrder(array $data, $sortOrder) + { + if (isset($data[$sortOrder])) { + return $this->_prepareAccountDataSortOrder($data, $sortOrder + 1); + } + + return $sortOrder; + } + + /** + * Return array of additional account data + * Value is option style array + * + * @return array + */ + public function getCustomerAccountData() + { + $accountData = []; + $entityType = 'customer'; + + /* @var \Magento\Customer\Api\Data\AttributeMetadataInterface $attribute */ + foreach ($this->metadata->getAllAttributesMetadata($entityType) as $attribute) { + if (!$attribute->isVisible() || $attribute->isSystem()) { + continue; + } + $orderKey = sprintf('customer_%s', $attribute->getAttributeCode()); + $orderValue = $this->getOrder()->getData($orderKey); + if ($orderValue != '') { + $metadataElement = $this->_metadataElementFactory->create($attribute, $orderValue, $entityType); + $value = $metadataElement->outputValue(AttributeDataFactory::OUTPUT_FORMAT_HTML); + $sortOrder = $attribute->getSortOrder() + $attribute->isUserDefined() ? 200 : 0; + $sortOrder = $this->_prepareAccountDataSortOrder($accountData, $sortOrder); + $accountData[$sortOrder] = [ + 'label' => $attribute->getFrontendLabel(), + 'value' => $this->escapeHtml($value, ['br']), + ]; + } + } + ksort($accountData, SORT_NUMERIC); + + return $accountData; + } + + /** + * Get link to edit order address page + * + * @param \Magento\Sales\Model\Order\Address $address + * @param string $label + * @return string + */ + public function getAddressEditLink($address, $label = '') + { + if ($this->_authorization->isAllowed('Magento_Sales::actions_edit')) { + if (empty($label)) { + $label = __('Edit'); + } + $url = $this->getUrl('sales/order/address', ['address_id' => $address->getId()]); + return '' . $this->escapeHtml($label) . ''; + } + + return ''; + } + + /** + * Whether Customer IP address should be displayed on sales documents + * + * @return bool + */ + public function shouldDisplayCustomerIp() + { + return !$this->_scopeConfig->isSetFlag( + 'sales/general/hide_customer_ip', + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + $this->getOrder()->getStoreId() + ); + } + + /** + * Check if is single store mode + * + * @return bool + */ + public function isSingleStoreMode() + { + return $this->_storeManager->isSingleStoreMode(); + } + + /** + * Get object created at date affected with object store timezone + * + * @param mixed $store + * @param string $createdAt + * @return \DateTime + */ + public function getCreatedAtStoreDate($store, $createdAt) + { + return $this->_localeDate->scopeDate($store, $createdAt, true); + } + + /** + * Get timezone for store + * + * @param mixed $store + * @return string + */ + public function getTimezoneForStore($store) + { + return $this->_localeDate->getConfigTimezone( + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + $store->getCode() + ); + } + + /** + * Get object created at date + * + * @param string $createdAt + * @return \DateTime + */ + public function getOrderAdminDate($createdAt) + { + return $this->_localeDate->date(new \DateTime($createdAt)); + } + + /** + * Returns string with formatted address + * + * @param Address $address + * @return null|string + */ + public function getFormattedAddress(Address $address) + { + return $this->addressRenderer->format($address, 'html'); + } + + /** + * @inheritdoc + * @since 101.0.0 + */ + public function getChildHtml($alias = '', $useCache = true) + { + $layout = $this->getLayout(); + + if ($alias || !$layout) { + return parent::getChildHtml($alias, $useCache); + } + + $childNames = $layout->getChildNames($this->getNameInLayout()); + $outputChildNames = array_diff($childNames, ['extra_customer_info']); + + $out = ''; + foreach ($outputChildNames as $childName) { + $out .= $layout->renderElement($childName, $useCache); + } + + return $out; + } + + public function getAndreaniOriginAddress(){ + /** + * @var RLOrder $andreaniOrder + */ + $andreaniOrder = $this->_coreRegistry->registry('current_andreani_order'); + $originAddress = $andreaniOrder->getOriginAddress(); + + $html = "%customer_firstname %customer_lastname
%street %number, %floor %apartment
%city, %postcode, %region
Telefono: %customer_telephone"; + + foreach ($originAddress->getData() as $field => $value){ + $html = str_replace('%'.$field, $value, $html); + } + + return $html; + } + + public function getAndreaniDestinationAddress(){ + /** + * @var RLOrder $andreaniOrder + */ + $andreaniOrder = $this->_coreRegistry->registry('current_andreani_order'); + $destinationAddress = $andreaniOrder->getDestinationAddress(); + + $html = "%customer_firstname %customer_lastname (DNI: %customer_vat_id)
%street %number, %floor %apartment
%city, %postcode, %region
Telefono: %customer_telephone
Observaciones: %observations"; + + foreach ($destinationAddress->getData() as $field => $value){ + $html = str_replace('%'.$field, $value, $html); + } + + return $html; + } +} diff --git a/app/code/DrubuNet/Andreani/Block/Adminhtml/ReverseLogistics/Create.php b/app/code/DrubuNet/Andreani/Block/Adminhtml/ReverseLogistics/Create.php new file mode 100644 index 0000000..4ca61b4 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Block/Adminhtml/ReverseLogistics/Create.php @@ -0,0 +1,101 @@ +_coreRegistry = $registry; + parent::__construct($context, $data); + } + + /** + * @return void + */ + protected function _construct() + { + //$this->_objectId = 'order_id'; + $this->_mode = 'create'; + $this->_objectId = 'simple_form'; + $this->_blockGroup = 'DrubuNet_Andreani'; + $this->_controller = 'adminhtml_reverselogistics'; + + parent::_construct(); + + $this->buttonList->remove('save'); + $this->buttonList->remove('delete'); + $operation = $this->_request->getParam('operation'); + if($operation != 'view') { + if($operation == 'resend_order') { + $label = 'Generar Reenvio'; + } + elseif($operation == 'change_order'){ + $label = 'Generar Cambio'; + } + else{ + $label = 'Generar Retiro/Devolución'; + } + $action = $this->getUrl("andreani/order/operations/operation/$operation",['order_id' => $this->getOrder()->getId()]); + $this->addButton( + $operation, + [ + 'label' => __($label), + //'onclick' => 'jQuery(\'#edit_form\').submit()', //'setLocation(\'' . $action . '\')', + 'onclick' => 'submitShipment(this);', + 'class' => 'primary' + ], + -1 + ); + } + } + + /** + * @return Order + */ + public function getOrder(){ + return $this->_coreRegistry->registry('current_order'); + } + + /** + * @return string + */ + public function getHeaderText() + { + $header = __('New Shipment for Order #%1',$this->getOrder()->getId()); + return $header; + } + + /** + * @return string + */ + public function getBackUrl() + { + return $this->getUrl( + 'sales/order/view', + ['order_id' => $this->getOrder()->getId()] + ); + } +} \ No newline at end of file diff --git a/app/code/DrubuNet/Andreani/Block/Adminhtml/ReverseLogistics/Create/Form.php b/app/code/DrubuNet/Andreani/Block/Adminhtml/ReverseLogistics/Create/Form.php new file mode 100644 index 0000000..093f3a1 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Block/Adminhtml/ReverseLogistics/Create/Form.php @@ -0,0 +1,158 @@ +orderRepository = $orderRepository; + } + + /** + * Retrieve invoice order + * + * @return \Magento\Sales\Model\Order + */ + public function getOrder() + { + return $this->_coreRegistry->registry('current_order'); + //return $this->orderRepository->get($this->getOrderIdByParam()); + } + + /** + * Retrieve source + * + * @return \Magento\Sales\Model\Order\Shipment + */ + public function getSource() + { + return $this->getShipment(); + } + + /** + * Retrieve shipment model instance + * + * @return \Magento\Sales\Model\Order\Shipment + */ + public function getShipment() + { + return $this->_coreRegistry->registry('current_shipment'); + } + + /** + * @return \Magento\Framework\View\Element\AbstractBlock + */ + protected function _prepareLayout() + { + $this->addChild('items', \Magento\Shipping\Block\Adminhtml\Create\Items::class); + return parent::_prepareLayout(); + } + + /** + * @return string + */ + public function getPaymentHtml() + { + return $this->getChildHtml('order_payment'); + } + + /** + * @return string + */ + public function getItemsHtml() + { + return $this->getChildHtml('order_items'); + } + + /** + * @return string + */ + public function getSaveUrl() + { + $rlOperation = $this->_request->getParam('operation'); + return $this->getUrl('andreani/order/operations/operation/generate_reverse_logistics/rl_operation/' . $rlOperation,['order_id' => $this->getOrder()->getId()]); + } + + public function getAndreaniOriginAddress(){ + /** + * @var RLOrder $andreaniOrder + */ + $andreaniOrder = $this->_coreRegistry->registry('current_andreani_order'); + $originAddress = $andreaniOrder->getOriginAddress()->getData(); + $html = "%customer_firstname %customer_lastname
%street %number, %floor %apartment
%city, %postcode, %region
Telefono: %customer_telephone"; + $valueInput = ''; + foreach ($originAddress as $field => $value){ + $html = str_replace('%'.$field, $value, $html); + $valueInput .= $field . '-' . $value . ';'; + } + + return [ + 'template' => $html, + 'input' => substr($valueInput,0, strlen($valueInput)-1), + 'data' => $originAddress + ]; + } + + public function getAndreaniDestinationAddress(){ + /** + * @var RLOrder $andreaniOrder + */ + $andreaniOrder = $this->_coreRegistry->registry('current_andreani_order'); + $destinationAddress = $andreaniOrder->getDestinationAddress()->getData(); + + $html = $this->getAndreaniAddressTemplate(); + $valueInput = ''; + + foreach ($destinationAddress as $field => $value){ + $html = str_replace('%'.$field, $value, $html); + $valueInput .= $field . '-' . $value . ';'; + } + + return [ + 'template' => $html, + 'input' => substr($valueInput,0, strlen($valueInput)-1), + 'data' => $destinationAddress + ]; + } + + public function getAndreaniAddressTemplate(){ + return "%customer_firstname %customer_lastname (DNI: %customer_vat_id)
%street %number, %floor %apartment
%city, %postcode, %region
Telefono: %customer_telephone
Observaciones: %observations"; + } + + public function isAndreaniViewOperation(){ + return $this->_request->getParam('operation') == 'view'; + } + + public function getAndreaniOrderItems(){ + return $this->_coreRegistry->registry('current_andreani_order')->getItems(); + } +} \ No newline at end of file diff --git a/app/code/DrubuNet/Andreani/Block/Adminhtml/ReverseLogistics/Create/Items.php b/app/code/DrubuNet/Andreani/Block/Adminhtml/ReverseLogistics/Create/Items.php new file mode 100644 index 0000000..5ddf387 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Block/Adminhtml/ReverseLogistics/Create/Items.php @@ -0,0 +1,209 @@ +_salesData = $salesData; + $this->_carrierFactory = $carrierFactory; + $this->orderRepository = $orderRepository; + parent::__construct($context, $stockRegistry, $stockConfiguration, $registry, $data); + } + + /** + * Retrieve invoice order + * + * @return \Magento\Sales\Model\Order + */ + public function getOrder() + { + return $this->_coreRegistry->registry('current_order'); + //return $this->orderRepository->get($this->getOrderIdByParam()); + } + + + public function getSource() + { + return $this->getShipment(); + } + + public function getShipment() + { + return $this->getOrder();//$this->_coreRegistry->registry('current_shipment'); + } + + /** + * Prepare child blocks + * + * @return string + */ + protected function _beforeToHtml() + { + $this->addChild( + 'submit_button', + \Magento\Backend\Block\Widget\Button::class, + [ + 'label' => __('Submit'), + 'class' => 'save submit-button primary', + //'onclick' => 'submitOperation(this);' + + 'onclick' => 'setLocation(\'' . $this->getUrl("andreani/order/operations/operation/withdraw_order",['order_id' => $this->getOrder()->getId()]) . '\')' + + ] + ); + + return parent::_beforeToHtml(); + } + + /** + * Format given price + * + * @param float $price + * @return string + */ + public function formatPrice($price) + { + return $this->getShipment()->getOrder()->formatPrice($price); + } + + /** + * Retrieve HTML of update button + * + * @return string + */ + public function getUpdateButtonHtml() + { + return $this->getChildHtml('update_button'); + } + + /** + * Get url for update + * + * @return string + */ + public function getUpdateUrl() + { + return $this->getUrl('sales/*/updateQty', ['order_id' => $this->getShipment()->getOrderId()]); + } + +public function getColumnHtml(\Magento\Framework\DataObject $item, $column, $field = null) +{ + return parent::getColumnHtml($item, $column, $field); // TODO: Change the autogenerated stub +} + + /** + * Check possibility to send shipment email + * + * @return bool + */ + public function canSendShipmentEmail() + { + return $this->_salesData->canSendNewShipmentEmail($this->getOrder()->getStore()->getId()); + } + + /** + * Checks the possibility of creating shipping label by current carrier + * + * @return bool + */ + public function canCreateShippingLabel() + { + $shippingCarrier = $this->_carrierFactory->create( + $this->getOrder()->getShippingMethod(true)->getCarrierCode() + ); + return $shippingCarrier && $shippingCarrier->isShippingLabelsAvailable(); + } + + /** + * Return true if can ship partially + * + * @param Order|null $order + * @return bool + */ + public function canShipPartially($order = null) + { + if ($order === null || !$order instanceof Order) { + $order = $this->getOrder(); + } + $value = $order->getCanShipPartially(); + if ($value !== null && !$value) { + return false; + } + return true; + } + + /** + * Return true if can ship items partially + * + * @param Order|null $order + * @return bool + */ + public function canShipPartiallyItem($order = null) + { + if ($order === null || !$order instanceof Order) { + $order = $this->getOrder(); + } + $value = $order->getCanShipPartiallyItem(); + if ($value !== null && !$value) { + return false; + } + return true; + } + + public function isAndreaniViewOperation(){ + return $this->_request->getParam('operation') == 'view'; + } + + public function getAndreaniOrderItems(){ + return $this->_coreRegistry->registry('current_andreani_order')->getItems(); + } + + private function getOrderIdByParam(){ + return $this->_request->getParam('order_id'); + } + +} diff --git a/app/code/DrubuNet/Andreani/Controller/Adminhtml/Order/Operations.php b/app/code/DrubuNet/Andreani/Controller/Adminhtml/Order/Operations.php index 12c6fce..382b420 100644 --- a/app/code/DrubuNet/Andreani/Controller/Adminhtml/Order/Operations.php +++ b/app/code/DrubuNet/Andreani/Controller/Adminhtml/Order/Operations.php @@ -7,6 +7,7 @@ namespace DrubuNet\Andreani\Controller\Adminhtml\Order; +use DrubuNet\Andreani\Model\RLOrder; use DrubuNet\Andreani\Model\ShippingProcessor; use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; @@ -14,6 +15,7 @@ use Magento\Framework\App\Response\Http\FileFactory; use Magento\Framework\Exception\CouldNotSaveException; use Magento\Sales\Api\OrderRepositoryInterface as SalesOrderRepositoryInterface; +use Magento\Sales\Model\Order; use Magento\Shipping\Model\Shipping\LabelGeneratorFactory; use Magento\Sales\Model\ResourceModel\Order\Shipment\CollectionFactory as ShipmentCollectionFactory; @@ -52,6 +54,18 @@ class Operations extends Action * @var SalesOrderRepositoryInterface */ private $orderRepository; + /** + * @var \Magento\Framework\Registry + */ + private $registry; + /** + * @var \DrubuNet\Andreani\Model\ReverseLogisticsRepository + */ + private $reverseLogisticsRepository; + /** + * @var \DrubuNet\Andreani\Model\ResourceModel\RLOrder\CollectionFactory + */ + private $rlOrderCollectionFactory; /** * @param Context $context @@ -68,7 +82,9 @@ public function __construct( ShippingProcessor $shippingProcessor, LabelGeneratorFactory $labelGeneratorFactory, FileFactory $fileFactory, - \Magento\Sales\Api\OrderRepositoryInterface $orderRepository + \Magento\Sales\Api\OrderRepositoryInterface $orderRepository, + \Magento\Framework\Registry $registry, + \DrubuNet\Andreani\Model\ResourceModel\RLOrder\CollectionFactory $rlOrderCollectionFactory ) { parent::__construct($context); @@ -78,6 +94,8 @@ public function __construct( $this->_labelGeneratorFactory = $labelGeneratorFactory; $this->_fileFactory = $fileFactory; $this->orderRepository = $orderRepository; + $this->registry = $registry; + $this->rlOrderCollectionFactory = $rlOrderCollectionFactory; } /** @@ -87,8 +105,13 @@ public function execute() { $operation = $this->getRequest()->getParam('operation'); $functionName = lcfirst(str_replace('_', '', ucwords($operation,'_'))); - if($this->{$functionName}()){ - return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRefererUrl()); + if($response = $this->{$functionName}()){ + if(is_bool($response)) { + return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRefererUrl()); + } + else{ + return $response; + } } } @@ -196,4 +219,118 @@ private function printShippingLabel(){ } return true; } + + //Generar retiro + private function generateReverseLogistics(){ + $orderId = $this->getRequest()->getParam('order_id'); + $operation = $this->getRequest()->getParam('rl_operation'); + $labelSuccess = ''; + $labelError = ''; + + switch ($operation){ + case 'withdraw_order': + $labelSuccess = 'Retiro generado con exito!'; + $labelError = 'Error al generar el Retiro'; + break; + case 'resend_order': + $labelSuccess = 'Reenvio generado con exito!'; + $labelError = 'Error al generar el Reenvio'; + break; + case 'change_order': + $labelSuccess = 'Cambio generado con exito!'; + $labelError = 'Error al generar el Cambio'; + break; + default: + $this->messageManager->addErrorMessage(__('Operacion incorrecta para la orden %1', $operation)); + break; + } + + if($labelSuccess != ''){ + $originAddressData = $this->_request->getParam('origin-address-input'); + $destinationAddressData = $this->_request->getParam('destination-address-input'); + + $originAddress = []; + $destinationAddress = []; + $items = []; + + foreach (explode(';',$originAddressData) as $fieldValueData){ + $fieldValue = explode('-', $fieldValueData); + $originAddress[$fieldValue[0]] = $fieldValue[1]; + } + + foreach (explode(';',$destinationAddressData) as $fieldValueData){ + $fieldValue = explode('-', $fieldValueData); + $destinationAddress[$fieldValue[0]] = $fieldValue[1]; + } + + foreach($this->_request->getParams() as $key => $value){ + if(strpos($key,'item_qty_for_') !== false && $value > 0){ + $sku = substr($key,strlen('item_qty_for_')); + $items[$sku] = $value; + } + } + + $orderData = [ + 'order_id' => $orderId, + 'operation' => $operation, + 'tracking_number' => '', + 'origin_address' => $originAddress, + 'destination_address' => $destinationAddress, + 'items' => $items + ]; + + $shipmentResult = $this->shippingProcessor->generateAndreaniRLShipping($orderData); + if($shipmentResult->getStatus()){ + $this->messageManager->addSuccessMessage(__($labelSuccess)); + } + else{ + $this->messageManager->addErrorMessage(__($labelError)); + } + + return $this->resultRedirectFactory->create()->setUrl($this->getUrl( + 'sales/order/view', + ['order_id' => $orderId] + )); + } + return true; + } + + private function massPrintRlLabels(){ + $ids = $this->getRequest()->getParam('andreani_rl_orders_ids'); + $collection = $this->rlOrderCollectionFactory->create()->addFieldToFilter(RLOrder::ID, ['in' => $ids]); + $labelContent = []; + /** + * @var RLOrder $order + */ + foreach ($collection as $order){ + $linking = $order->getLinking(); + foreach ($linking as $label){ + if(!empty($label)) { + $labelContent[] = $this->shippingProcessor->getLabel($label, true); + } + } + } + + $pdfName = 'guia_masiva_'.date_timestamp_get(date_create()) . '.pdf'; + if(count($labelContent) > 0) { + $outputPdf = $this->_labelGeneratorFactory->create()->combineLabelsPdf($labelContent); + return $this->_fileFactory->create( + $pdfName, + $outputPdf->render(), + \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR, + 'application/pdf' + ); + } + else{ + $this->messageManager->addWarningMessage('No se encontraron etiquetas de logistica inversa para los envios seleccionados.'); + } + return true; + } + + + protected function _isAllowed() + { + return true; + } + } diff --git a/app/code/DrubuNet/Andreani/Controller/Adminhtml/Pages/ReverseLogistics.php b/app/code/DrubuNet/Andreani/Controller/Adminhtml/Pages/ReverseLogistics.php new file mode 100644 index 0000000..b3ffbfb --- /dev/null +++ b/app/code/DrubuNet/Andreani/Controller/Adminhtml/Pages/ReverseLogistics.php @@ -0,0 +1,70 @@ +registry = $registry; + $this->orderRepository = $orderRepository; + $this->reverseLogisticsRepository = $reverseLogisticsRepository; + } + + public function execute() + { + if(!$this->_request->getParam('andreani_order_id')) { + $currentOrder = $this->orderRepository->get($this->_request->getParam('order_id')); + $andreaniOrder = $this->reverseLogisticsRepository->createEmptyOrder($currentOrder, $this->_request->getParam('operation')); + } + else{ + $andreaniOrder = $this->reverseLogisticsRepository->getById($this->_request->getParam('andreani_order_id')); + $currentOrder = $this->orderRepository->get($andreaniOrder->getOrderId()); + } + $this->registry->register('current_order', $currentOrder); + $this->registry->register('current_andreani_order', $andreaniOrder); + + $this->_view->loadLayout(); + //$this->_setActiveMenu('Magento_Sales::sales_order'); + if(!$this->_request->getParam('andreani_order_id')) { + $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Generando un %1 del pedido %2', $andreaniOrder->getOperationLabel(), $currentOrder->getIncrementId())); + } + else{ + $this->_view->getPage()->getConfig()->getTitle()->prepend(__('%1 del pedido %2',$andreaniOrder->getOperationLabel(),$currentOrder->getIncrementId())); + } + $this->_view->renderLayout(); + } +} diff --git a/app/code/DrubuNet/Andreani/Controller/Adminhtml/Tab/ReverseLogistics.php b/app/code/DrubuNet/Andreani/Controller/Adminhtml/Tab/ReverseLogistics.php new file mode 100644 index 0000000..7251ad5 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Controller/Adminhtml/Tab/ReverseLogistics.php @@ -0,0 +1,89 @@ +layoutFactory = $layoutFactory; + parent::__construct( + $context, + $coreRegistry, + $fileFactory, + $translateInline, + $resultPageFactory, + $resultJsonFactory, + $resultLayoutFactory, + $resultRawFactory, + $orderManagement, + $orderRepository, + $logger + ); + } + + public function execute() + { +// $this->_view->loadLayout(); +// $this->_view->renderLayout(); + $this->_initOrder(); + $layout = $this->layoutFactory->create(); + $html = $layout->createBlock(\DrubuNet\Andreani\Block\Adminhtml\Edit\Edit::class) + ->toHtml(); + $html .= $layout->createBlock(\DrubuNet\Andreani\Block\Adminhtml\Edit\Tab\View\ReverseLogistics::class) + ->toHtml(); + $this->_translateInline->processResponseBody($html); + /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ + $resultRaw = $this->resultRawFactory->create(); + $resultRaw->setContents($html); + return $resultRaw; + } +} \ No newline at end of file diff --git a/app/code/DrubuNet/Andreani/Controller/Checkout/PickupRates.php b/app/code/DrubuNet/Andreani/Controller/Checkout/PickupRates.php index 7486983..a8783f0 100644 --- a/app/code/DrubuNet/Andreani/Controller/Checkout/PickupRates.php +++ b/app/code/DrubuNet/Andreani/Controller/Checkout/PickupRates.php @@ -71,7 +71,7 @@ public function execute() $storeId = $request->getParam('store_id') ? $request->getParam('store_id') : null; $addressZip = $request->getParam('address_zip') ? $request->getParam('address_zip') : null; $storeName = $request->getParam('store_name') ? $request->getParam('store_name') : null; - $rate = $this->shippingProcessor->getRate($this->checkoutSession->getQuote()->getAllItems(), $addressZip, \DrubuNet\Andreani\Model\Carrier\PickupDelivery::CARRIER_CODE, $storeId); + $rate = $this->shippingProcessor->getRate($this->checkoutSession->getQuote()->getAllItems(), $addressZip, \DrubuNet\Andreani\Model\Carrier\PickupDelivery::CARRIER_CODE); if ($this->checkoutSession->getFreeShipping()) { $price = 0; diff --git a/app/code/DrubuNet/Andreani/Helper/Data.php b/app/code/DrubuNet/Andreani/Helper/Data.php index 1e9aa74..0644488 100644 --- a/app/code/DrubuNet/Andreani/Helper/Data.php +++ b/app/code/DrubuNet/Andreani/Helper/Data.php @@ -178,6 +178,22 @@ public function isDebugEnable(){ return boolval($this->getConfig(self::SHIPPING_SECTION . 'debug_mode')); } + public function getAttributeHeight(){ + return $this->getConfig(self::SHIPPING_SECTION . 'attributes_mapping/selected_height'); + } + + public function getAttributeLength(){ + return $this->getConfig(self::SHIPPING_SECTION . 'attributes_mapping/selected_length'); + } + + public function getAttributeWidth(){ + return $this->getConfig(self::SHIPPING_SECTION . 'attributes_mapping/selected_width'); + } + + public function getRlContractByType($type){ + return $this->getConfig(self::SHIPPING_SECTION . $type); + } + /* * Shipping method config */ diff --git a/app/code/DrubuNet/Andreani/Model/Carrier/BiggerDelivery.php b/app/code/DrubuNet/Andreani/Model/Carrier/BiggerDelivery.php new file mode 100644 index 0000000..0e4f8a8 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Model/Carrier/BiggerDelivery.php @@ -0,0 +1,172 @@ +_rateResultFactory = $rateResultFactory; + $this->_rateMethodFactory = $rateMethodFactory; + $this->shippingProcessor = $shippingProcessor; + $this->andreaniHelper = $andreaniHelper; + parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data); + } + /** + * Collect and get rates + * + * @param RateRequest $request + * @return Result|bool + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + */ + public function collectRates(RateRequest $request) + { + if (!$this->getConfigFlag('active')) { + return false; + } + if($request->getPackageWeight() <= 50){ + return false; + } + + /** @var Result $result */ + $result = $this->_rateResultFactory->create(); + + $shippingPrice = $this->getShippingPrice($request); + + if ($shippingPrice !== false) { + $method = $this->createResultMethod($shippingPrice); + $result->append($method); + } + + return $result; + } + + /** + * Get allowed shipping methods + * + * @return array + */ + public function getAllowedMethods() + { + return [$this->_code => $this->getConfigData('name')]; + } + + /** + * Returns shipping price + * + * @param RateRequest $request + * @return bool|float + */ + private function getShippingPrice(RateRequest $request) + { + $shippingPrice = false; + if(!$request->getFreeShipping()) { + $rate = $this->shippingProcessor->getRate($request->getAllItems(), $request->getDestPostcode(),\DrubuNet\Andreani\Model\Carrier\BiggerDelivery::CARRIER_CODE); + if($rate->getStatus()){ + $shippingPrice = $rate->getPrice(); + } + if(!is_bool($shippingPrice)) { + $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice); + } + } + else{ + $shippingPrice = 0; + } + + return $shippingPrice; + } + + /** + * Creates result method + * + * @param int|float $shippingPrice + * @return \Magento\Quote\Model\Quote\Address\RateResult\Method + */ + private function createResultMethod($shippingPrice) + { + /** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */ + $method = $this->_rateMethodFactory->create(); + + $method->setCarrier(self::CARRIER_CODE); + $method->setCarrierTitle($this->getConfigData('title')); + + $method->setMethod(self::METHOD_CODE); + $method->setMethodTitle($this->getConfigData('name')); + + $method->setPrice($shippingPrice); + $method->setCost($shippingPrice); + return $method; + } + + public function isTrackingAvailable() + { + return true; + } + + public function isShippingLabelsAvailable() + { + return true; + } +} diff --git a/app/code/DrubuNet/Andreani/Model/Carrier/PickupDelivery.php b/app/code/DrubuNet/Andreani/Model/Carrier/PickupDelivery.php index d94e22e..2b2a571 100644 --- a/app/code/DrubuNet/Andreani/Model/Carrier/PickupDelivery.php +++ b/app/code/DrubuNet/Andreani/Model/Carrier/PickupDelivery.php @@ -85,6 +85,9 @@ public function collectRates(RateRequest $request) if (!$this->getConfigFlag('active')) { return false; } + if($request->getPackageWeight() > 50){ + return false; + } /** @var Result $result */ $result = $this->_rateResultFactory->create(); diff --git a/app/code/DrubuNet/Andreani/Model/Carrier/PriorityDelivery.php b/app/code/DrubuNet/Andreani/Model/Carrier/PriorityDelivery.php index 83470a1..3221efe 100644 --- a/app/code/DrubuNet/Andreani/Model/Carrier/PriorityDelivery.php +++ b/app/code/DrubuNet/Andreani/Model/Carrier/PriorityDelivery.php @@ -86,6 +86,9 @@ public function collectRates(RateRequest $request) if (!$this->getConfigFlag('active')) { return false; } + if($request->getPackageWeight() > 50){ + return false; + } /** @var Result $result */ $result = $this->_rateResultFactory->create(); diff --git a/app/code/DrubuNet/Andreani/Model/Carrier/StandardDelivery.php b/app/code/DrubuNet/Andreani/Model/Carrier/StandardDelivery.php index 066ee81..7f06204 100644 --- a/app/code/DrubuNet/Andreani/Model/Carrier/StandardDelivery.php +++ b/app/code/DrubuNet/Andreani/Model/Carrier/StandardDelivery.php @@ -86,6 +86,9 @@ public function collectRates(RateRequest $request) if (!$this->getConfigFlag('active')) { return false; } + if($request->getPackageWeight() > 50){ + return false; + } /** @var Result $result */ $result = $this->_rateResultFactory->create(); diff --git a/app/code/DrubuNet/Andreani/Model/RLAddress.php b/app/code/DrubuNet/Andreani/Model/RLAddress.php new file mode 100644 index 0000000..622a0b4 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Model/RLAddress.php @@ -0,0 +1,305 @@ +_init(RLAddressResourceModel::class); + } + + public function getId() + { + return $this->getData(self::ID); + } + + public function setId($id) + { + return $this->setData(self::ID, $id); + } + + /** + * @return string + */ + public function getAddressType() + { + return $this->getData(self::ADDRESS_TYPE); + } + + /** + * @return string + */ + public function getCustomerFirstname() + { + return $this->getData(self::CUSTOMER_FIRSTNAME); + } + + /** + * @return string + */ + public function getCustomerLastname() + { + return $this->getData(self::CUSTOMER_LASTNAME); + } + + /** + * @return string + */ + public function getCustomerVatId() + { + return $this->getData(self::CUSTOMER_VAT_ID); + } + + /** + * @return string + */ + public function getCustomerTelephone() + { + return $this->getData(self::CUSTOMER_TELEPHONE); + } + + /** + * @return string + */ + public function getStreet() + { + return $this->getData(self::ADDRESS_STREET); + } + + /** + * @return string + */ + public function getNumber() + { + return $this->getData(self::ADDRESS_NUMBER); + } + + /** + * @return string + */ + public function getFloor() + { + return $this->getData(self::ADDRESS_FLOOR); + } + + /** + * @return string + */ + public function getApartment() + { + return $this->getData(self::ADDRESS_APARTMENT); + } + + /** + * @return string + */ + public function getObservations() + { + return $this->getData(self::ADDRESS_OBSERVATIONS); + } + + /** + * @return string + */ + public function getPostcode() + { + return $this->getData(self::ADDRESS_POSTCODE); + } + + /** + * @return string + */ + public function getCity() + { + return $this->getData(self::ADDRESS_CITY); + } + + /** + * @return string + */ + public function getRegion() + { + return $this->getData(self::ADDRESS_REGION); + } + + /** + * @return string + */ + public function getCountry() + { + return $this->getData(self::ADDRESS_COUNTRY); + } + + /** + * @return string + */ + public function getBetweenStreets() + { + return $this->getData(self::ADDRESS_BETWEEN_STREETS); + } + + /** + * @return string + */ + public function getCreatedAt() + { + return $this->getData(self::CREATED_AT); + } + + /** + * @param $addressType + * @return RLAddressInterface + */ + public function setAddressType($addressType) + { + return $this->setData(self::ADDRESS_TYPE, $addressType); + } + + /** + * @param $customerFirstname + * @return RLAddressInterface + */ + public function setCustomerFirstname($customerFirstname) + { + return $this->setData(self::CUSTOMER_FIRSTNAME, $customerFirstname); + } + + /** + * @param $customerLastname + * @return RLAddressInterface + */ + public function setCustomerLastname($customerLastname) + { + return $this->setData(self::CUSTOMER_LASTNAME, $customerLastname); + } + + /** + * @param $customerVatId + * @return RLAddressInterface + */ + public function setCustomerVatId($customerVatId) + { + return $this->setData(self::CUSTOMER_VAT_ID, $customerVatId); + } + + /** + * @param $customerTelephone + * @return RLAddressInterface + */ + public function setCustomerTelephone($customerTelephone) + { + return $this->setData(self::CUSTOMER_TELEPHONE, $customerTelephone); + } + + /** + * @param $street + * @return RLAddressInterface + */ + public function setStreet($street) + { + return $this->setData(self::ADDRESS_STREET, $street); + } + + /** + * @param $number + * @return RLAddressInterface + */ + public function setNumber($number) + { + return $this->setData(self::ADDRESS_NUMBER, $number); + } + + /** + * @param $floor + * @return RLAddressInterface + */ + public function setFloor($floor) + { + return $this->setData(self::ADDRESS_FLOOR, $floor); + } + + /** + * @param $apartment + * @return RLAddressInterface + */ + public function setApartment($apartment) + { + return $this->setData(self::ADDRESS_APARTMENT, $apartment); + } + + /** + * @param $observations + * @return RLAddressInterface + */ + public function setObservations($observations) + { + return $this->setData(self::ADDRESS_OBSERVATIONS, $observations); + } + + /** + * @param $postcode + * @return RLAddressInterface + */ + public function setPostcode($postcode) + { + return $this->setData(self::ADDRESS_POSTCODE, $postcode); + } + + /** + * @param $city + * @return RLAddressInterface + */ + public function setCity($city) + { + return $this->setData(self::ADDRESS_CITY, $city); + } + + /** + * @param $region + * @return RLAddressInterface + */ + public function setRegion($region) + { + return $this->setData(self::ADDRESS_REGION, $region); + } + + /** + * @param $country + * @return RLAddressInterface + */ + public function setCountry($country) + { + return $this->setData(self::ADDRESS_COUNTRY, $country); + } + + /** + * @param $betweenStreets + * @return RLAddressInterface + */ + public function setBetweenStreets($betweenStreets) + { + return $this->setData(self::ADDRESS_BETWEEN_STREETS, $betweenStreets); + } + + /** + * @param $createdAt + * @return RLAddressInterface + */ + public function setCreatedAt($createdAt): RLAddressInterface + { + return $this->setData(self::CREATED_AT, $createdAt); + } +} diff --git a/app/code/DrubuNet/Andreani/Model/RLItem.php b/app/code/DrubuNet/Andreani/Model/RLItem.php new file mode 100644 index 0000000..ea932f6 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Model/RLItem.php @@ -0,0 +1,118 @@ +_init(RLItemResourceModel::class); + } + + public function getId() + { + return $this->getData(self::ID); + } + + public function setId($id) + { + return $this->setData(self::ID, $id); + } + + /** + * @return int + */ + public function getParentId(): int + { + return $this->getData(self::PARENT_ID); + } + + /** + * @param int $orderId + * @return RLItemInterface + */ + public function setParentId(int $orderId): RLItemInterface + { + return $this->setData(self::PARENT_ID, $orderId); + } + + /** + * @return string + */ + public function getSku(): string + { + return $this->getData(self::SKU); + } + + /** + * @param string $sku + * @return RLItemInterface + */ + public function setSku(string $sku): RLItemInterface + { + return $this->setData(self::SKU, $sku); + } + + /** + * @return string + */ + public function getName(): string + { + return $this->getData(self::NAME); + } + + /** + * @param string $name + * @return RLItemInterface + */ + public function setName(string $name): RLItemInterface + { + return $this->setData(self::NAME, $name); + } + + /** + * @return int + */ + public function getQty(): int + { + return $this->getData(self::QTY); + } + + /** + * @param int $qty + * @return RLItemInterface + */ + public function setQty(int $qty): RLItemInterface + { + return $this->setData(self::QTY, $qty); + } + + /** + * @return string + */ + public function getCreatedAt() + { + return $this->getData(self::CREATED_AT); + } + + /** + * @param $createdAt + * @return RLItemInterface + */ + public function setCreatedAt($createdAt): RLItemInterface + { + return $this->setData(self::CREATED_AT, $createdAt); + } +} diff --git a/app/code/DrubuNet/Andreani/Model/RLOrder.php b/app/code/DrubuNet/Andreani/Model/RLOrder.php new file mode 100644 index 0000000..b49f632 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Model/RLOrder.php @@ -0,0 +1,318 @@ +_init(RLOrderResourceModel::class); + } + + public function __construct( + RLAddressModelFactory $RLAddressModelFactory, + RLItemModelFactory $RLItemModelFactory, + \Magento\Framework\Model\Context $context, + \Magento\Framework\Registry $registry, + \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, + \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + array $data = [] + ) + { + parent::__construct($context, $registry, $resource, $resourceCollection, $data); + $this->RLAddressModelFactory = $RLAddressModelFactory; + $this->RLItemModelFactory = $RLItemModelFactory; + } + + public function getId() + { + return $this->getData(self::ID); + } + + public function setId($id) + { + return $this->setData(self::ID, $id); + } + + /** + * @return int + */ + public function getOrderId(): int + { + return $this->getData(self::ORDER_ID); + } + + /** + * @param int $orderId + * @return RLOrderInterface + */ + public function setOrderId(int $orderId): RLOrderInterface + { + return $this->setData(self::ORDER_ID, $orderId); + } + + /** + * @return string + */ + public function getOperation(): string + { + return $this->getData(self::OPERATION); + } + + /** + * @param string $operation + * @return RLOrderInterface + */ + public function setOperation(string $operation): RLOrderInterface + { + if($operation == 'resend_order') { + $label = 'Reenvio'; + } + elseif($operation == 'change_order'){ + $label = 'Cambio'; + } + else{ + $label = 'Retiro/Devolución'; + } + $this->setOperationLabel($label); + return $this->setData(self::OPERATION, $operation); + } + + /** + * @return string + */ + public function getOperationLabel(): string + { + return $this->getData(self::OPERATION_LABEL); + } + + /** + * @param string $operationLabel + * @return RLOrderInterface + */ + public function setOperationLabel(string $operationLabel): RLOrderInterface + { + return $this->setData(self::OPERATION_LABEL, $operationLabel); + } + + /** + * @return string + */ + public function getTrackingNumber(): string + { + return $this->getData(self::TRACKING_NUMBER); + } + + /** + * @param string $trackingNumber + * @return RLOrderInterface + */ + public function setTrackingNumber(string $trackingNumber): RLOrderInterface + { + return $this->setData(self::TRACKING_NUMBER, $trackingNumber); + } + + /** + * @return string + */ + public function getCreatedAt() + { + return $this->getData(self::CREATED_AT); + } + + /** + * @param $createdAt + * @return RLOrderInterface + */ + public function setCreatedAt($createdAt): RLOrderInterface + { + return $this->setData(self::CREATED_AT, $createdAt); + } + + /** + * @return RLItemInterface[] + */ + public function getItems() + { + return $this->getData(self::ORDER_ITEMS); + } + + /** + * @param array|DataObject[] $items + * @return RLOrderInterface + */ + public function setItems($items) + { + $orderItems = []; + $fields = [ + 'sku', + 'qty', + 'name' + ]; + + foreach ($items as $item){ + $orderItem = $this->RLItemModelFactory->create(); + foreach ($fields as $field){ + $orderItem->setData($field, $item[$field]); + } + $orderItems[] = $orderItem; + } + + return $this->setData(self::ORDER_ITEMS, $orderItems); + } + + /** + * @param $addressId + * @return RLOrderInterface + */ + public function setOriginAddressId($addressId): RLOrderInterface + { + return $this->setData(self::ORIGIN_ADDRESS_ID, $addressId); + } + + /** + * @return RLAddressInterface + */ + public function getOriginAddress(): RLAddressInterface + { + $originAddress = $this->getData(self::ORIGIN_ADDRESS); + if(!$originAddress){ + $originAddress = $this->RLAddressModelFactory->create(); + } + return $originAddress; + } + + /** + * @param array|DataObject $sellerAddress + * @return RLOrderInterface + */ + public function setOriginAddress($sellerAddress): RLOrderInterface + { + $originAddress = $this->getOriginAddress(); + $fields = [ + 'customer_firstname', + 'customer_lastname', + 'customer_telephone', + 'customer_vat_id', + 'street', + 'number', + 'floor', + 'apartment', + 'observations', + 'postcode', + 'city', + 'region', + 'country', + 'between_streets' + ]; + foreach ($fields as $field){ + $originAddress->setData($field, $sellerAddress[$field]); + } + return $this->setData(self::ORIGIN_ADDRESS, $originAddress); + } + + /** + * @param $addressId + * @return RLOrderInterface + */ + public function setDestinationAddressId($addressId): RLOrderInterface + { + return $this->setData(self::DESTINATION_ADDRESS_ID, $addressId); + } + + /** + * @return RLAddressInterface + */ + public function getDestinationAddress(): RLAddressInterface + { + $destination = $this->getData(self::DESTINATION_ADDRESS); + if(!$destination){ + $destination = $this->RLAddressModelFactory->create(); + } + return $destination; + } + + /** + * @param array|DataObject $customerAddress + * @return RLOrderInterface + */ + public function setDestinationAddress($customerAddress): RLOrderInterface + { + $destination = $this->getDestinationAddress(); + + $fields = [ + 'customer_firstname', + 'customer_lastname', + 'customer_telephone', + 'customer_vat_id', + 'street', + 'number', + 'floor', + 'apartment', + 'observations', + 'postcode', + 'city', + 'region', + 'country', + 'between_streets' + ]; + foreach ($fields as $field){ + $destination->setData($field, $customerAddress[$field]); + } + return $this->setData(self::DESTINATION_ADDRESS, $destination); + } + + public function getData($key = '', $index = null) + { + $orderData = parent::getData($key, $index); + + if($key == '' && $index == null){ + $items = []; + foreach ($this->getItems() as $item) { + $items[] = $item->getData(); + } + + $orderData[RLOrderInterface::ORDER_ITEMS] = $items; + $orderData[RLOrderInterface::ORIGIN_ADDRESS] = $this->getOriginAddress()->getData(); + $orderData[RLOrderInterface::DESTINATION_ADDRESS] = $this->getDestinationAddress()->getData(); + } + return $orderData; + } + + /** + * @return mixed + */ + public function getLinking() + { + return explode(';',$this->getData(self::LINKING)); + } + + /** + * @param mixed $linking + * @return RLOrderInterface + */ + public function setLinking($linking): RLOrderInterface + { + return $this->setData(self::LINKING, implode(';',$linking)); + } +} diff --git a/app/code/DrubuNet/Andreani/Model/ResourceModel/RLAddress.php b/app/code/DrubuNet/Andreani/Model/ResourceModel/RLAddress.php new file mode 100644 index 0000000..ae72e87 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Model/ResourceModel/RLAddress.php @@ -0,0 +1,24 @@ +_init(self::TABLE, RLAddressInterface::ID); + } +} diff --git a/app/code/DrubuNet/Andreani/Model/ResourceModel/RLAddress/Collection.php b/app/code/DrubuNet/Andreani/Model/ResourceModel/RLAddress/Collection.php new file mode 100644 index 0000000..825f97e --- /dev/null +++ b/app/code/DrubuNet/Andreani/Model/ResourceModel/RLAddress/Collection.php @@ -0,0 +1,29 @@ +_init(RlAddress::class, RLAddressResource::class); + } +} diff --git a/app/code/DrubuNet/Andreani/Model/ResourceModel/RLItem.php b/app/code/DrubuNet/Andreani/Model/ResourceModel/RLItem.php new file mode 100644 index 0000000..b53e351 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Model/ResourceModel/RLItem.php @@ -0,0 +1,24 @@ +_init(self::TABLE, RLItemInterface::ID); + } +} diff --git a/app/code/DrubuNet/Andreani/Model/ResourceModel/RLItem/Collection.php b/app/code/DrubuNet/Andreani/Model/ResourceModel/RLItem/Collection.php new file mode 100644 index 0000000..3a6059a --- /dev/null +++ b/app/code/DrubuNet/Andreani/Model/ResourceModel/RLItem/Collection.php @@ -0,0 +1,31 @@ +_init(RLItem::class, RLItemResource::class); + } + + +} diff --git a/app/code/DrubuNet/Andreani/Model/ResourceModel/RLOrder.php b/app/code/DrubuNet/Andreani/Model/ResourceModel/RLOrder.php new file mode 100644 index 0000000..d23dc9f --- /dev/null +++ b/app/code/DrubuNet/Andreani/Model/ResourceModel/RLOrder.php @@ -0,0 +1,130 @@ +_init(self::TABLE, RLOrderInterface::ID); + } + + /** + * @param \Magento\Framework\Model\ResourceModel\Db\Context $context + * @param string $connectionName + */ + public function __construct( + \Magento\Framework\Model\ResourceModel\Db\Context $context, + \DrubuNet\Andreani\Model\RLAddressFactory $RLAddressModelFactory, + \DrubuNet\Andreani\Model\ResourceModel\RLAddress $RLAddressResource, + \DrubuNet\Andreani\Model\ResourceModel\RLItem $RLItemResource, + \DrubuNet\Andreani\Model\ResourceModel\RLItem\CollectionFactory $RLItemCollectionFactory, + $connectionName = null + ) + { + parent::__construct($context, $connectionName); + $this->RLAddressResource = $RLAddressResource; + $this->RLAddressModelFactory = $RLAddressModelFactory; + $this->RLItemResource = $RLItemResource; + $this->RLItemCollectionFactory = $RLItemCollectionFactory; + } + + public function save(\Magento\Framework\Model\AbstractModel $object) + { + /** + * @var \DrubuNet\Andreani\Model\RLOrder $order + */ + $order = $object; + //1. Save addresses + /** + * @var RLAddressInterface $originAddress + */ + $originAddress = $object->getOriginAddress(); + /** + * @var RLAddressInterface $destinationAddress + */ + $destinationAddress = $object->getDestinationAddress(); + + $originAddress->setAddressType(0); + $destinationAddress->setAddressType(1); + $this->RLAddressResource->save($originAddress); + $this->RLAddressResource->save($destinationAddress); + + $order->setOriginAddressId($originAddress->getId()); + $order->setDestinationAddressId($destinationAddress->getId()); + + $saveReference = parent::save($object); + + /** + * @var RLItemInterface $item + */ + foreach ($object->getItems() as $item){ + $item->setParentId($object->getId()); + $this->RLItemResource->save($item); + } + + + return $saveReference; + } + + public function load(\Magento\Framework\Model\AbstractModel $object, $value, $field = null) + { + parent::load($object, $value, $field); + /** + * @var \DrubuNet\Andreani\Model\RLOrder $order + */ + $order = $object; + $originAddressId = $order->getData(RLOrderInterface::ORIGIN_ADDRESS_ID); + $destinationAddressId = $order->getData(RLOrderInterface::DESTINATION_ADDRESS_ID); + + $originAddress = $this->RLAddressModelFactory->create(); + $this->RLAddressResource->load($originAddress,$originAddressId); + $order->setData(RLOrderInterface::ORIGIN_ADDRESS,$originAddress); + + $destinationAddress = $this->RLAddressModelFactory->create(); + $this->RLAddressResource->load($destinationAddress,$destinationAddressId); + $order->setData(RLOrderInterface::DESTINATION_ADDRESS,$destinationAddress); + + $itemCollection = $this->RLItemCollectionFactory->create()->addFieldToFilter(RLItemInterface::PARENT_ID,$order->getId()); + $orderItems = []; + foreach ($itemCollection as $item){ + $orderItems[] = $item; + } + $order->setData(RLOrderInterface::ORDER_ITEMS,$orderItems); + } +} diff --git a/app/code/DrubuNet/Andreani/Model/ResourceModel/RLOrder/Collection.php b/app/code/DrubuNet/Andreani/Model/ResourceModel/RLOrder/Collection.php new file mode 100644 index 0000000..82876f2 --- /dev/null +++ b/app/code/DrubuNet/Andreani/Model/ResourceModel/RLOrder/Collection.php @@ -0,0 +1,29 @@ +_init(RLOrder::class, RLOrderResource::class); + } +} diff --git a/app/code/DrubuNet/Andreani/Model/ReverseLogisticsRepository.php b/app/code/DrubuNet/Andreani/Model/ReverseLogisticsRepository.php new file mode 100644 index 0000000..388ceba --- /dev/null +++ b/app/code/DrubuNet/Andreani/Model/ReverseLogisticsRepository.php @@ -0,0 +1,183 @@ +rlOrderFactory = $rlOrderFactory; + $this->rlOrderResource = $rlOrderResource; + $this->rlOrderCollectionFactory = $rlOrderCollectionFactory; + $this->andreaniHelper = $andreaniHelper; + } + + public function createEmptyOrder(OrderInterface $order, $operation){ + /** + * @var RLOrderInterface $andreaniOrder + */ + $andreaniOrder = $this->rlOrderFactory->create(); + $originAddress = [ + 'customer_firstname' => $this->andreaniHelper->getSenderFullname(), + 'customer_lastname' => '', + 'customer_telephone' => $this->andreaniHelper->getSenderPhoneNumber(), + 'customer_vat_id' => $this->andreaniHelper->getSenderId(), + 'street' => $this->andreaniHelper->getOrigStreet(), + 'number' => $this->andreaniHelper->getOrigNumber(), + 'floor' => $this->andreaniHelper->getOrigFloor(), + 'apartment' => $this->andreaniHelper->getOrigApartment(), + 'observations' => '', + 'postcode' => $this->andreaniHelper->getOrigPostcode(), + 'city' => $this->andreaniHelper->getOrigCity(), + 'region' => $this->andreaniHelper->getOrigRegion(), + 'country' => $this->andreaniHelper->getOrigCountry(), + 'between_streets' => $this->andreaniHelper->getOrigBetweenStreets() + ]; + $shippingAddress = $order->getShippingAddress(); + $destinationAddress = [ + 'customer_firstname' => $shippingAddress->getFirstname(), + 'customer_lastname' => $shippingAddress->getLastname(), + 'customer_telephone' => $shippingAddress->getTelephone(), + 'customer_vat_id' => $shippingAddress->getDni(), + 'street' => $shippingAddress->getStreetLine(1), + 'number' => $shippingAddress->getAltura(), + 'floor' => $shippingAddress->getPiso(), + 'apartment' => $shippingAddress->getDepartamento(), + 'observations' => $shippingAddress->getObservaciones(), + 'postcode' => $shippingAddress->getPostcode(), + 'city' => $shippingAddress->getCity(), + 'region' => $shippingAddress->getRegion(), + 'country' => 'Argentina', + 'between_streets' => '' + ]; + + $andreaniOrder->setDestinationAddress($destinationAddress); + $andreaniOrder->setOriginAddress($originAddress); + $andreaniOrder->setOperation($operation); + $andreaniOrder->setOrderId($order->getEntityId()); + + return $andreaniOrder; + } + + public function save(RLOrderInterface $rlOrder){ + try { + if($rlOrder->getId()){ + $rlOrder = $this->getById($rlOrder->getId())->addData($rlOrder->getData()); + } + $this->rlOrderResource->save($rlOrder); + }catch (\Exception $e){ + if($rlOrder->getId()){ + throw new CouldNotSaveException( + __( + 'Unable to save ordersPrepared with ID %1. Error: %2', + [$rlOrder->getId(), $e->getMessage()] + ) + ); + } + throw new CouldNotSaveException(__('Unable to save new ordersPrepared. Error: %1', $e->getMessage())); + } + } + + /** + * @param array $data + */ + public function setAndSaveOrderData($data){ + /** + * @var RLOrder $orderModel + */ + $orderModel = $this->rlOrderFactory->create(); + foreach ($data as $key => $value){ + $orderModel->{$this->getFunctionFormat($key)}($value); + } + $this->save($orderModel); + } + + public function getList($orderId): array + { + $rlOrders = []; + $rlOrderCollection = $this->rlOrderCollectionFactory->create(); + $rlOrderCollection->addFieldToFilter(RLOrderInterface::ORDER_ID, $orderId); + foreach ($rlOrderCollection as $order){ + $this->rlOrderResource->load($order,$order->getId()); + $rlOrders[] = $order; + } + return $rlOrders; + } + + /** + * @param $id + * @return RLOrder + * @throws NoSuchEntityException + */ + public function getById($id) + { + /** @var \DrubuNet\Andreani\Model\RLOrder $rlOrder */ + $rlOrder = $this->rlOrderFactory->create(); + $this->rlOrderResource->load($rlOrder, $id); + if (!$rlOrder->getId()) { + throw new NoSuchEntityException(__('RLOrder with specified ID "%1" not found.', $id)); + } + return $rlOrder; + } + + public function getByOrderId($orderId){ + $rlOrder = null; + $rlOrderCollection = $this->rlOrderCollectionFactory->create(); + $rlOrderCollection->addFieldToFilter(RLOrderInterface::ORDER_ID, $orderId); + if($rlOrderCollection->count() > 0){ + $rlOrder = $rlOrderCollection->getFirstItem(); + } + return $rlOrder; + } + + private function getFunctionFormat($name){ + $pos = strpos($name, '_'); + while (($pos = strpos($name, '_')) !== false) { + $start = substr($name, 0, $pos); + $end = substr($name, $pos + 1); + $name = $start . ucfirst($end); + } + return 'set' . ucfirst($name); + } +} diff --git a/app/code/DrubuNet/Andreani/Model/ShippingProcessor.php b/app/code/DrubuNet/Andreani/Model/ShippingProcessor.php index e639898..2926eaa 100644 --- a/app/code/DrubuNet/Andreani/Model/ShippingProcessor.php +++ b/app/code/DrubuNet/Andreani/Model/ShippingProcessor.php @@ -10,6 +10,7 @@ use DrubuNet\Andreani\Service\AndreaniApiService; use Magento\Framework\DataObject; +use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Sales\Api\ShipOrderInterfaceFactory; use Magento\Shipping\Model\Shipping\LabelGenerator; use Magento\Shipping\Model\Shipping\LabelGeneratorFactory; @@ -51,6 +52,19 @@ class ShippingProcessor */ private $shipmentRepositoryFactory; + /** + * @var ReverseLogisticsRepository + */ + private $reverseLogisticsRepository; + /** + * @var OrderRepositoryInterface + */ + private $orderRepository; + /** + * @var \Magento\Catalog\Api\ProductRepositoryInterface + */ + private $productRepository; + public function __construct( \DrubuNet\Andreani\Helper\Data $andreaniHelper, AndreaniApiService $andreaniApiService, @@ -58,7 +72,10 @@ public function __construct( ShipOrderInterfaceFactory $shipOrderFactory, \Magento\Sales\Api\Data\ShipmentTrackCreationInterfaceFactory $shipmentTrackCreationFactory, \Magento\Sales\Api\ShipmentRepositoryInterfaceFactory $shipmentRepositoryFactory, - LabelGeneratorFactory $labelGeneratorFactory + LabelGeneratorFactory $labelGeneratorFactory, + \DrubuNet\Andreani\Model\ReverseLogisticsRepository $reverseLogisticsRepository, + OrderRepositoryInterface $orderRepository, + \Magento\Catalog\Api\ProductRepositoryInterface $productRepository ) { $this->andreaniHelper = $andreaniHelper; @@ -68,6 +85,9 @@ public function __construct( $this->shipmentTrackCreationFactory = $shipmentTrackCreationFactory; $this->labelGeneratorFactory = $labelGeneratorFactory; $this->shipmentRepositoryFactory = $shipmentRepositoryFactory; + $this->reverseLogisticsRepository = $reverseLogisticsRepository; + $this->orderRepository = $orderRepository; + $this->productRepository = $productRepository; } /** @@ -77,7 +97,7 @@ public function __construct( * @param string $store_id * @return DataObject */ - public function getRate($items, $zip, $method, $store_id = ''){ + public function getRate($items, $zip, $method){ $rate = new DataObject(); $price = -1; $status = false; @@ -87,7 +107,7 @@ public function getRate($items, $zip, $method, $store_id = ''){ "cpDestino" => $zip,//CP de la sucursal, viene en la info "contrato" => $this->andreaniHelper->getContractByType($method),//nro contrato, config, "cliente" => $this->andreaniHelper->getClientNumber(),//Codigo cliente, config, - "sucursalOrigen" => $store_id,//Codigo sucursal + "sucursalOrigen" => '',//Codigo sucursal "bultos" => [ [ "valorDeclarado" => $packageWeight['amount'],//total de la compra @@ -134,14 +154,14 @@ public function getRate($items, $zip, $method, $store_id = ''){ return $rate; } - public function getLabel($tracking){ + public function getLabel($labelData, $isUrl = false){ $label = null; try{ - $label = $this->andreaniApiService->getLabel($tracking); + $label = $this->andreaniApiService->getLabel($labelData, $isUrl); }catch (\Exception $e){ $logMessage = "Method: getLabel\n"; $logMessage .= "Status: with errors\n"; - $logMessage .= "Request: $tracking\n"; + $logMessage .= "Request: $labelData\n"; $logMessage .= "Message: " . $e->getMessage() . "\n"; \DrubuNet\Andreani\Helper\Data::log($logMessage, 'andreani_rest_' . date('Y_m') . '.log'); } @@ -406,6 +426,155 @@ public function generateAndreaniShipping($order){ return $shipmentResult; } + public function generateAndreaniRLShipping($data){ + $shipmentResult = new \Magento\Framework\DataObject; + $shipmentResult->setStatus(false); + $order = $this->orderRepository->get($data['order_id']); + $itemsSelected = $data['items']; + $contract = $this->andreaniHelper->getRlContractByType(explode('_',$data['operation'])[0] . '_contract'); + $rlOrderItems = []; + $orderItemsFiltered = []; + foreach ($order->getAllItems() as $item){ + if(array_key_exists($item->getSku(),$itemsSelected)){ + if($item->getProductType() != 'simple') { + continue; + } + $qtySelected = $itemsSelected[$item->getSku()]; + $item = $item->setQtyOrdered($qtySelected); + $orderItemsFiltered[] = $item; + $rlOrderItems[] = ['sku' => $item->getSku(), 'qty' => $qtySelected, 'name' => $item->getName()]; + } + } + $data['items'] = $rlOrderItems; + $packageWeight = $this->getPackageWeightByItems($orderItemsFiltered); + $params = array( + "contrato" => $contract, + "origen" => array( + "postal" => array( + "codigoPostal" =>$data['origin_address']['postcode'], + "calle" => $data['origin_address']['street'], + "numero" => $data['origin_address']['number'], + "localidad" => $data['origin_address']['city'], + "region" => $data['origin_address']['region'], + "pais" => $data['origin_address']['country'], + ) + ), + "destino" => [ + "postal" => array( + "codigoPostal" => $data['destination_address']['postcode'], + "calle" => $data['destination_address']['street'], + "numero" => $data['destination_address']['number'], + "localidad" => $data['destination_address']['city'], + "region" => $data['destination_address']['region'], + "pais" => "Argentina", + "componentesDeDireccion" => [ + + ] + ) + ], + "remitente" => array( + "nombreCompleto" => $data['origin_address']['customer_firstname'] . ' ' . $data['origin_address']['customer_lastname'], + "email" => $this->andreaniHelper->getSenderEmail(), + "documentoTipo" => $this->andreaniHelper->getSenderIdType(), + "documentoNumero" => $data['origin_address']['customer_vat_id'], + "telefonos" => [ + array( + "tipo" => intval($this->andreaniHelper->getSenderPhoneType()), + "numero" => $data['origin_address']['customer_telephone'] + ) + ] + ), + "destinatario" => [ + array( + "nombreCompleto" => $data['destination_address']['customer_firstname'] . ' ' . $data['destination_address']['customer_lastname'], + "email" => $order->getCustomerEmail(), + "documentoTipo" => "DNI", + "documentoNumero" => $data['destination_address']['customer_vat_id'], + "telefonos" => [ + array( + "tipo" => 1, + "numero" => $data['destination_address']['customer_telephone'] + ) + ] + ), + ], + "bultos" => [ + array( + "kilos" => $packageWeight['weight'], + + "volumenCm" => $packageWeight['volume'], + "valorDeclaradoSinImpuestos" => floatval($packageWeight['amount']), + //"valorDeclaradoConImpuestos" => 1452, + "referencias" => [ + array( + "meta" => "idCliente", + "contenido" => $order->getIncrementId() + ), + array( + "meta" => "observaciones", + "contenido" => substr($packageWeight['names'],0,255) + ), + ] + ) + ] + ); + + if($data['destination_address']['floor'] != ''){ + $params['destino']['postal']['componentesDeDireccion'][] = array( + "meta" => "piso", + "contenido" => $data['destination_address']['floor'] + ); + } + if($data['destination_address']['apartment'] != ''){ + $params['destino']['postal']['componentesDeDireccion'][] = array( + "meta" => "departamento", + "contenido" => $data['destination_address']['apartment'] + ); + } + + $response = $this->andreaniApiService->createOrder(new DataObject($params)); + + if (!is_array($response)) { + if ($this->andreaniHelper->isDebugEnable()) { + $logMessage = "\nOrder #{$order->getIncrementId()}\n"; + $logMessage .= "Method: createRLOrder\n"; + $logMessage .= "Status: with errors\n"; + $logMessage .= "Request: " . json_encode($params) . "\n"; + $logMessage .= "Response: " . json_encode($response) . "\n"; + \DrubuNet\Andreani\Helper\Data::log($logMessage, 'andreani_errores_rest_' . date('Y_m') . '.log'); + } + $shipmentResult->setMessage($response); + return $shipmentResult; + } else { + if ($this->andreaniHelper->isDebugEnable()) { + $logMessage = "\nOrder #{$order->getIncrementId()}\n"; + $logMessage .= "Method: createRLOrder\n"; + $logMessage .= "Status: successful\n"; + $logMessage .= "Request: " . json_encode($params) . "\n"; + $logMessage .= "Response: " . json_encode($response) . "\n"; + \DrubuNet\Andreani\Helper\Data::log($logMessage, 'andreani_rest_' . date('Y_m') . '.log'); + } + $shipmentResult->setStatus(true); + } + + $linkingData = []; + $tracks = []; + if (count($response['bultos']) > 0) { + foreach ($response['bultos'] as $bulto) { + $tracks[] = $bulto['numeroDeEnvio']; + if(array_key_exists('linking', $bulto) && is_array($bulto['linking'])) { + foreach ($bulto['linking'] as $linking) { + $linkingData[] = $linking['contenido']; + } + } + } + } + $data['tracking_number'] = implode(',', $tracks); + $data['linking'] = $linkingData; + $this->reverseLogisticsRepository->setAndSaveOrderData($data); + return $shipmentResult; + } + private function generatePackageWithLabel($shipmentId, $shippingLabelContent, $packageWeight){ //creo el shipping label /** diff --git a/app/code/DrubuNet/Andreani/Model/Source/AttributesOptions.php b/app/code/DrubuNet/Andreani/Model/Source/AttributesOptions.php new file mode 100644 index 0000000..aff0c1d --- /dev/null +++ b/app/code/DrubuNet/Andreani/Model/Source/AttributesOptions.php @@ -0,0 +1,36 @@ +attributeCollection = $attributeCollection; + } + + public function toOptionArray() + { + $attributes = $this->attributeCollection->getCollection()->addFieldToFilter("entity_type_id", 4); + + $options = []; + foreach ($attributes as $attribute){ + $options[$attribute->getAttributeCode()] = $attribute->getAttributeCode(); + } + return $options; + } +} \ No newline at end of file diff --git a/app/code/DrubuNet/Andreani/Service/AndreaniApiService.php b/app/code/DrubuNet/Andreani/Service/AndreaniApiService.php index 5bae534..307a38b 100644 --- a/app/code/DrubuNet/Andreani/Service/AndreaniApiService.php +++ b/app/code/DrubuNet/Andreani/Service/AndreaniApiService.php @@ -93,8 +93,14 @@ public function createOrder(DataObject $data){ * @param string $tracking * @return DataObject */ - public function getLabel($tracking){ - $labelUrl = str_replace('{numeroAndreani}',$tracking,$this->helper->getLabelUrl()); + public function getLabel($labelData, $isUrl = false){ + if(!$isUrl) { + $tracking = $labelData; + $labelUrl = str_replace('{numeroAndreani}', $tracking, $this->helper->getLabelUrl()); + } + else{ + $labelUrl = $labelData; + } if(empty($this->token)){ $this->login(); } diff --git a/app/code/DrubuNet/Andreani/Setup/UpgradeSchema.php b/app/code/DrubuNet/Andreani/Setup/UpgradeSchema.php index 609ff64..cf52e93 100644 --- a/app/code/DrubuNet/Andreani/Setup/UpgradeSchema.php +++ b/app/code/DrubuNet/Andreani/Setup/UpgradeSchema.php @@ -7,6 +7,9 @@ namespace DrubuNet\Andreani\Setup; +use DrubuNet\Andreani\Api\Data\RLAddressInterface; +use DrubuNet\Andreani\Api\Data\RLItemInterface; +use DrubuNet\Andreani\Api\Data\RLOrderInterface; use Magento\Framework\Setup\UpgradeSchemaInterface; use Magento\Framework\Setup\SchemaSetupInterface; use Magento\Framework\Setup\ModuleContextInterface; @@ -23,6 +26,9 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con if(version_compare($context->getVersion(), '2.0.0', '<')) { $this->upgradeTo200($setup); } + if(version_compare($context->getVersion(), '2.0.2', '<')) { + $this->upgradeTo202($setup); + } $setup->endSetup(); } @@ -119,4 +125,86 @@ private function upgradeTo200(SchemaSetupInterface $setup){ ]); } } + + private function upgradeTo202(SchemaSetupInterface $setup) + { + if(!$setup->tableExists("drubunet_andreani_logisticainversa")) { + $drubunetAndreaniLogisticaInversa = $setup->getConnection() + ->newTable($setup->getTable('drubunet_andreani_logisticainversa')) + ->addColumn( + RLOrderInterface::ID, + Table::TYPE_INTEGER, + 6, + ['identity' => true, 'nullable' => false, 'primary' => true] + ) + ->addColumn(RLOrderInterface::ORDER_ID, Table::TYPE_INTEGER, 6, ['nullable' => false]) + ->addColumn(RLOrderInterface::OPERATION, Table::TYPE_TEXT, 20, ['nullable' => false]) + ->addColumn(RLOrderInterface::OPERATION_LABEL, Table::TYPE_TEXT, 30, ['nullable' => false]) + ->addColumn(RLOrderInterface::TRACKING_NUMBER, Table::TYPE_TEXT, 30, ['nullable' => false]) + ->addColumn(RLOrderInterface::LINKING, Table::TYPE_TEXT, 400, ['nullable' => false]) + ->addColumn(RLOrderInterface::ORIGIN_ADDRESS_ID, Table::TYPE_INTEGER, 10, ['nullable' => false]) + ->addColumn(RLOrderInterface::DESTINATION_ADDRESS_ID, Table::TYPE_INTEGER, 10, ['nullable' => false]) + ->addColumn(RLOrderInterface::CREATED_AT, Table::TYPE_TIMESTAMP, null, ['nullable' => false, 'default' => Table::TIMESTAMP_INIT]) + ->addIndex( + $setup->getIdxName('drubunet_andreani_logisticainversa', [RLOrderInterface::ID]), + [RLOrderInterface::ID] + ); + + $setup->getConnection()->createTable($drubunetAndreaniLogisticaInversa); + } + if(!$setup->tableExists("drubunet_andreani_logisticainversa_direcciones")) { + $drubunetAndreaniLogisticaInversaDirecciones = $setup->getConnection() + ->newTable($setup->getTable('drubunet_andreani_logisticainversa_direcciones')) + ->addColumn( + RLAddressInterface::ID, + Table::TYPE_INTEGER, + 10, + ['identity' => true, 'nullable' => false, 'primary' => true]) + ->addColumn(RLAddressInterface::ADDRESS_TYPE, Table::TYPE_SMALLINT, 1, ['nullable' => false]) + ->addColumn(RLAddressInterface::CUSTOMER_FIRSTNAME, Table::TYPE_TEXT, 20, ['nullable' => false]) + ->addColumn(RLAddressInterface::CUSTOMER_LASTNAME, Table::TYPE_TEXT, 20, ['nullable' => false]) + ->addColumn(RLAddressInterface::CUSTOMER_VAT_ID, Table::TYPE_TEXT, 10, ['nullable' => false]) + ->addColumn(RLAddressInterface::CUSTOMER_TELEPHONE, Table::TYPE_TEXT, 10, ['nullable' => false]) + + ->addColumn(RLAddressInterface::ADDRESS_STREET, Table::TYPE_TEXT, 100, ['nullable' => false]) + ->addColumn(RLAddressInterface::ADDRESS_NUMBER, Table::TYPE_TEXT, 10, ['nullable' => false]) + ->addColumn(RLAddressInterface::ADDRESS_FLOOR, Table::TYPE_TEXT, 40, ['nullable' => true]) + ->addColumn(RLAddressInterface::ADDRESS_APARTMENT, Table::TYPE_TEXT, 40, ['nullable' => true]) + ->addColumn(RLAddressInterface::ADDRESS_BETWEEN_STREETS, Table::TYPE_TEXT, 100, ['nullable' => true]) + ->addColumn(RLAddressInterface::ADDRESS_OBSERVATIONS, Table::TYPE_TEXT, 100, ['nullable' => true]) + ->addColumn(RLAddressInterface::ADDRESS_POSTCODE, Table::TYPE_TEXT, 20, ['nullable' => false]) + ->addColumn(RLAddressInterface::ADDRESS_CITY, Table::TYPE_TEXT, 100, ['nullable' => false]) + ->addColumn(RLAddressInterface::ADDRESS_REGION, Table::TYPE_TEXT, 100, ['nullable' => false]) + ->addColumn(RLAddressInterface::ADDRESS_COUNTRY, Table::TYPE_TEXT, 100, ['nullable' => false]) + ->addColumn(RLAddressInterface::CREATED_AT, Table::TYPE_TIMESTAMP, null, ['nullable' => false, 'default' => Table::TIMESTAMP_INIT]) + ->addIndex( + $setup->getIdxName('drubunet_andreani_logisticainversa_direcciones', [RLAddressInterface::ID]), + [RLAddressInterface::ID] + ); + + $setup->getConnection()->createTable($drubunetAndreaniLogisticaInversaDirecciones); + } + if(!$setup->tableExists("drubunet_andreani_logisticainversa_productos")) { + $drubunetAndreaniLogisticaInversaProductos = $setup->getConnection() + ->newTable($setup->getTable('drubunet_andreani_logisticainversa_productos')) + ->addColumn( + RLItemInterface::ID, + Table::TYPE_INTEGER, + 10, + ['identity' => true, 'nullable' => false, 'primary' => true]) + ->addColumn(RLItemInterface::PARENT_ID, Table::TYPE_INTEGER, 6, ['nullable' => false]) + ->addColumn(RLItemInterface::SKU, Table::TYPE_TEXT, 100, ['nullable' => false]) + ->addColumn(RLItemInterface::NAME, Table::TYPE_TEXT, 100, ['nullable' => false]) + ->addColumn(RLItemInterface::QTY, Table::TYPE_SMALLINT, 3, ['nullable' => false]) + ->addColumn(RLItemInterface::CREATED_AT, Table::TYPE_TIMESTAMP, null, ['nullable' => false, 'default' => Table::TIMESTAMP_INIT]) + ->addIndex( + $setup->getIdxName('drubunet_andreani_logisticainversa_productos', [RLItemInterface::ID]), + [RLItemInterface::ID] + ); + + $setup->getConnection()->createTable($drubunetAndreaniLogisticaInversaProductos); + } + + + } } diff --git a/app/code/DrubuNet/Andreani/Ui/DataProvider/Listing/OrderDataProvider.php b/app/code/DrubuNet/Andreani/Ui/DataProvider/Listing/OrderDataProvider.php index 8ed5003..fe8a052 100644 --- a/app/code/DrubuNet/Andreani/Ui/DataProvider/Listing/OrderDataProvider.php +++ b/app/code/DrubuNet/Andreani/Ui/DataProvider/Listing/OrderDataProvider.php @@ -49,6 +49,7 @@ public function getCollection() $methodsCondition = '\'' . \DrubuNet\Andreani\Model\Carrier\PickupDelivery::CARRIER_CODE . '_' . \DrubuNet\Andreani\Model\Carrier\PickupDelivery::METHOD_CODE . '\', ' . '\'' . \DrubuNet\Andreani\Model\Carrier\StandardDelivery::CARRIER_CODE . '_' . \DrubuNet\Andreani\Model\Carrier\StandardDelivery::METHOD_CODE . '\', ' . + '\'' . \DrubuNet\Andreani\Model\Carrier\BiggerDelivery::CARRIER_CODE . '_' . \DrubuNet\Andreani\Model\Carrier\BiggerDelivery::METHOD_CODE . '\', ' . '\'' . \DrubuNet\Andreani\Model\Carrier\PriorityDelivery::CARRIER_CODE . '_' . \DrubuNet\Andreani\Model\Carrier\PriorityDelivery::METHOD_CODE . '\''; $select->where("ss.order_id IS NULL and so.shipping_method in ($methodsCondition)"); diff --git a/app/code/DrubuNet/Andreani/etc/adminhtml/menu.xml b/app/code/DrubuNet/Andreani/etc/adminhtml/menu.xml index de471a9..7e22b10 100644 --- a/app/code/DrubuNet/Andreani/etc/adminhtml/menu.xml +++ b/app/code/DrubuNet/Andreani/etc/adminhtml/menu.xml @@ -13,15 +13,6 @@ sortOrder="70" resource="Magento_Config::brand" /> - - - - - - - - - + + + + + Magento\Config\Model\Config\Source\Yesno + + + + + + + validate-number validate-zero-or-greater + + + + + + + + + + shipping-applicable-country + Magento\Shipping\Model\Config\Source\Allspecificcountries + + + + Magento\Directory\Model\Config\Source\Country + 1 + + 1 + + + + + Magento\Config\Model\Config\Source\Yesno + shipping-skip-hide + + + + + 1 + + + + @@ -175,6 +220,29 @@ La url ingresada no debe terminar con "/" + + + Contrato provisto por andreani para realizar cambios de un pedido. + + + + Contrato provisto por andreani para realizar retiro/devolución de un pedido. + + + + + + + + + + + + + + + + diff --git a/app/code/DrubuNet/Andreani/etc/config.xml b/app/code/DrubuNet/Andreani/etc/config.xml index fa31678..11a50fa 100644 --- a/app/code/DrubuNet/Andreani/etc/config.xml +++ b/app/code/DrubuNet/Andreani/etc/config.xml @@ -40,6 +40,20 @@ F 0.00 + + 1 + DrubuNet\Andreani\Model\Carrier\BiggerDelivery + Envio a domicilio para pedidos > 50kg + 3 + Andreani + 400006710 + 0 + 1 + This shipping method is not available. To use this shipping method, please contact us. + I + F + 0.00 + 1 DrubuNet\Andreani\Model\Carrier\PriorityDelivery diff --git a/app/code/DrubuNet/Andreani/etc/module.xml b/app/code/DrubuNet/Andreani/etc/module.xml index 2133e41..02ed95c 100644 --- a/app/code/DrubuNet/Andreani/etc/module.xml +++ b/app/code/DrubuNet/Andreani/etc/module.xml @@ -1,6 +1,6 @@ - + + + + + + \ No newline at end of file diff --git a/app/code/DrubuNet/Andreani/view/adminhtml/layout/andreani_tab_reverselogistics.xml b/app/code/DrubuNet/Andreani/view/adminhtml/layout/andreani_tab_reverselogistics.xml new file mode 100644 index 0000000..8159a49 --- /dev/null +++ b/app/code/DrubuNet/Andreani/view/adminhtml/layout/andreani_tab_reverselogistics.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/app/code/DrubuNet/Andreani/view/adminhtml/layout/sales_order_view.xml b/app/code/DrubuNet/Andreani/view/adminhtml/layout/sales_order_view.xml new file mode 100644 index 0000000..3ed8b4c --- /dev/null +++ b/app/code/DrubuNet/Andreani/view/adminhtml/layout/sales_order_view.xml @@ -0,0 +1,21 @@ + + + + + + + + + + andreani_tabs + andreani_reverse_logistics.grid.container + tabid + + + + + diff --git a/app/code/DrubuNet/Andreani/view/adminhtml/templates/create/form.phtml b/app/code/DrubuNet/Andreani/view/adminhtml/templates/create/form.phtml new file mode 100644 index 0000000..2afb606 --- /dev/null +++ b/app/code/DrubuNet/Andreani/view/adminhtml/templates/create/form.phtml @@ -0,0 +1,337 @@ +getAndreaniOriginAddress(); +$destinationAddress = $block->getAndreaniDestinationAddress(); +$addressTemplate = $block->getAndreaniAddressTemplate(); +?> +
+
+ getChildHtml('order_info') ?> +
+
+ escapeHtml(__('Address Information')) ?> +
+
+
+ +
+ escapeHtml(__('Origin Address')) ?> + isAndreaniViewOperation()) : ?> + + +
+
+ +
+ getOrder()->getIsVirtual()) : ?> +
+ +
+ escapeHtml(__('Destination Address')) ?> + isAndreaniViewOperation()) : ?> + + +
+
+ +
+ +
+
+ +
+ isAndreaniViewOperation()) : ?> +
+ escapeHtml(__('Items Shipped')) ?> +
+
+ + + + + + + + getAndreaniOrderItems(); + $_i = count($_items); ?> + + + + + + + + + +
+ escapeHtml(__('Items to Ship')) ?> +
+
+
escapeHtml(__('Product')) ?> + escapeHtml(__('Qty Shipped')) ?> +
+
+ escapeHtml($_item->getName()) ?> +
+
+ escapeHtml(__('SKU')) ?>: ', $this->helper(\Magento\Catalog\Helper\Data::class)->splitSku($block->escapeHtml($_item->getSku()))) ?> +
+
+ getQty() ?> +
+ + + + + + + + getOrder()->getAllItems() ?> + getParentItem()) : + continue; + endif; + $_i++ ?> + + + + + + + + + +
escapeHtml(__('Product')) ?>escapeHtml(__('Qty')) ?> + escapeHtml(__('Qty to Ship')) ?> +
+
+ escapeHtml($_item->getName()) ?> +
+
+ escapeHtml(__('SKU')) ?>: ', $this->helper(\Magento\Catalog\Helper\Data::class)->splitSku($block->escapeHtml($_item->getSku()))) ?> +
+
+ + + + + +
escapeHtml(__('Ordered')); ?>getQtyOrdered() ?>
+
+ +
+
+
+
+
+
+ getChildHtml('submit_before') ?> +
+ getChildHtml('submit_button') ?> + getChildHtml('submit_after') ?> +
+ +
+
+
+
+ + + + + + diff --git a/app/code/DrubuNet/Andreani/view/adminhtml/templates/create/items.phtml b/app/code/DrubuNet/Andreani/view/adminhtml/templates/create/items.phtml new file mode 100644 index 0000000..3711f97 --- /dev/null +++ b/app/code/DrubuNet/Andreani/view/adminhtml/templates/create/items.phtml @@ -0,0 +1,161 @@ +
+ isAndreaniViewOperation()) : ?> +
+ escapeHtml(__('Items Shipped')) ?> +
+
+ + + + + + + + getAndreaniOrderItems(); + $_i = count($_items); ?> + + + + + + + + + +
+ escapeHtml(__('Items to Ship')) ?> +
+
+
escapeHtml(__('Product')) ?> + escapeHtml(__('Qty Shipped')) ?> +
+
+ escapeHtml($_item->getName()) ?> +
+
+ escapeHtml(__('SKU')) ?>: ', $this->helper(\Magento\Catalog\Helper\Data::class)->splitSku($block->escapeHtml($_item->getSku()))) ?> +
+
+ getQty() ?> +
+ + + + + + + + getOrder()->getAllItems() ?> + getParentItem()) : + continue; + endif; + $_i++ ?> + + + + + + + + + +
escapeHtml(__('Product')) ?>escapeHtml(__('Qty')) ?> + escapeHtml(__('Qty to Ship')) ?> +
+
+ escapeHtml($_item->getName()) ?> +
+
+ escapeHtml(__('SKU')) ?>: ', $this->helper(\Magento\Catalog\Helper\Data::class)->splitSku($block->escapeHtml($_item->getSku()))) ?> +
+
+ + + + + + + getQtyInvoiced()) : ?> + + + + + + + getQtyShipped()) : ?> + + + + + + + getQtyRefunded()) : ?> + + + + + + + getQtyCanceled()) : ?> + + + + + +
escapeHtml(__('Ordered')); ?>getQtyOrdered() ?>
escapeHtml(__('Invoiced')); ?>getQtyInvoiced() ?>
escapeHtml(__('Shipped')); ?>getQtyShipped() ?>
escapeHtml(__('Refunded')); ?>getQtyRefunded() ?>
escapeHtml(__('Canceled')); ?>getQtyCanceled() ?>
+
+ +
+
+
+ + + \ No newline at end of file diff --git a/app/code/DrubuNet/Andreani/view/adminhtml/templates/order/tab/view/order_info.phtml b/app/code/DrubuNet/Andreani/view/adminhtml/templates/order/tab/view/order_info.phtml new file mode 100644 index 0000000..c39d249 --- /dev/null +++ b/app/code/DrubuNet/Andreani/view/adminhtml/templates/order/tab/view/order_info.phtml @@ -0,0 +1 @@ +
asdasd
\ No newline at end of file diff --git a/app/code/DrubuNet/Andreani/view/adminhtml/templates/order/tab/view/reverse_logistics_grid.phtml b/app/code/DrubuNet/Andreani/view/adminhtml/templates/order/tab/view/reverse_logistics_grid.phtml new file mode 100644 index 0000000..e69de29 diff --git a/app/code/DrubuNet/Andreani/view/adminhtml/templates/order/view/info.phtml b/app/code/DrubuNet/Andreani/view/adminhtml/templates/order/view/info.phtml new file mode 100644 index 0000000..7ad2193 --- /dev/null +++ b/app/code/DrubuNet/Andreani/view/adminhtml/templates/order/view/info.phtml @@ -0,0 +1,188 @@ +getOrder(); + +$baseCurrencyCode = (string)$order->getBaseCurrencyCode(); +$globalCurrencyCode = (string)$order->getGlobalCurrencyCode(); +$orderCurrencyCode = (string)$order->getOrderCurrencyCode(); + +$orderAdminDate = $block->formatDate( + $block->getOrderAdminDate($order->getCreatedAt()), + \IntlDateFormatter::MEDIUM, + true +); + +$orderStoreDate = $block->formatDate( + $order->getCreatedAt(), + \IntlDateFormatter::MEDIUM, + true, + $block->getTimezoneForStore($order->getStore()) +); + +$customerUrl = $block->getCustomerViewUrl(); + +$allowedAddressHtmlTags = ['b', 'br', 'em', 'i', 'li', 'ol', 'p', 'strong', 'sub', 'sup', 'ul']; +?> + + + + diff --git a/app/code/DrubuNet/Andreani/view/adminhtml/ui_component/andreani_reverse_logistics_grid.xml b/app/code/DrubuNet/Andreani/view/adminhtml/ui_component/andreani_reverse_logistics_grid.xml new file mode 100644 index 0000000..9e02c31 --- /dev/null +++ b/app/code/DrubuNet/Andreani/view/adminhtml/ui_component/andreani_reverse_logistics_grid.xml @@ -0,0 +1,209 @@ + + ++ + + sales_order_shipment_grid.sales_order_shipment_grid_data_source + + + + sales_order_shipment_columns + + sales_order_shipment_grid.sales_order_shipment_grid_data_source + + + + + + + Magento_Sales::shipment + + + id + entity_id + + + + + + + + + + + + + All Store Views + + store_id + + ns = ${ $.ns }, componentType = column, index = ${ $.index }:visible + + + + + + + + + pdfshipments_order + + + + + + + print_shipping_label + + + + + + + + + + + sales_order_shipment_grid.sales_order_shipment_grid.sales_order_shipment_columns.actions + applyAction + + view + ${ $.$data.rowIndex } + + + + + + + entity_id + + + + + text + + asc + + + + + dateRange + date + + + + + + text + + + + + + dateRange + date + + + + + + text + + + + + + textRange + + + + + + select + + select + + false + + + + + + ui/grid/cells/html + false + false + + + + + text + + false + + + + + text + + false + + + + + select + + select + + false + + + + + text + + ui/grid/cells/html + false + + + + + text + + ui/grid/cells/html + false + + + + + select + + select + + false + + + + + text + + false + + + + + + sales/shipment/view + shipment_id + + + + entity_id + + + + diff --git a/app/code/DrubuNet/Andreani/view/frontend/web/js/view/checkout/pickup/pickup-andreani.js b/app/code/DrubuNet/Andreani/view/frontend/web/js/view/checkout/pickup/pickup-andreani.js index 8131f72..de6ad46 100644 --- a/app/code/DrubuNet/Andreani/view/frontend/web/js/view/checkout/pickup/pickup-andreani.js +++ b/app/code/DrubuNet/Andreani/view/frontend/web/js/view/checkout/pickup/pickup-andreani.js @@ -89,7 +89,7 @@ define([ store_id: checkoutConfig.andreani.stores[this.selectedProvince()][this.selectedCity()][this.selectedStore()].codigo, store_name: this.selectedStore(), quote_id: quote.getQuoteId(), - address_zip: quote.shippingAddress().postcode + address_zip: checkoutConfig.andreani.stores[this.selectedProvince()][this.selectedCity()][this.selectedStore()].direccion.codigoPostal }, complete: function (response) { if(response.status == 200 && response.responseJSON.status){