diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4438f37 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/* +.idea diff --git a/Model/Config/Source/Customer/Attributes.php b/Model/Config/Source/Customer/Attributes.php new file mode 100644 index 0000000..92e1b6a --- /dev/null +++ b/Model/Config/Source/Customer/Attributes.php @@ -0,0 +1,60 @@ +setAttributeCollectionFactory($attributeCollectionFactory); + } + + /** + * @return array + */ + public function toOptionArray() + { + $attributeCollection = $this->getAttributeCollectionFactory()->create(); + $attributeCollection->setAttributeSetFilter(self::CUSTOMER_ATTRIBUTE_SET); + $attributeCollection->getSelect()->order('frontend_label'); + + $options = []; + foreach ($attributeCollection as $attribute) { + $options[] = ['value' => $attribute->getAttributeCode(), 'label' => $attribute->getFrontendLabel()]; + } + + return $options; + } + + /** + * @return AttributeCollectionFactory + */ + protected function getAttributeCollectionFactory() + { + return $this->attributeCollectionFactory; + } + + /** + * @param AttributeCollectionFactory $attributeCollectionFactory + * @return Attributes + */ + protected function setAttributeCollectionFactory($attributeCollectionFactory) + { + $this->attributeCollectionFactory = $attributeCollectionFactory; + return $this; + } +} \ No newline at end of file diff --git a/Model/Request/ShipmentOrder.php b/Model/Request/ShipmentOrder.php index c42c57a..b9c7b52 100644 --- a/Model/Request/ShipmentOrder.php +++ b/Model/Request/ShipmentOrder.php @@ -82,7 +82,7 @@ public function shipmentOrder($collectionData) $this->scheduling_window_end = $collectionData['scheduling_window_end']; $this->shipment_order_type = $collectionData['shipment_order_type']; $this->shipment_order_sub_type = $collectionData['shipment_order_sub_type']; - $this->shipment_order_volume_invoice = $invoiceObj->getInformation($collectionData['order_number']); + $this->shipment_order_volume_invoice = $invoiceObj->getInformation($collectionData['entity_id']); $this->shipment_order_volume_array = $volObj->getInformation($collectionData['volumes'], $this->shipment_order_volume_invoice); $this->end_customer = $ecObj->getInformation($collectionData['entity_id'], $collectionData['customer_taxvat']); if($this->_scopeConfig->getValue('intelipost_push/order_status/create_and_ship')){ @@ -209,4 +209,4 @@ public function getNowDateTime() $now = str_replace(' ', 'T', $localizedDateTimeISO); return $now; } -} \ No newline at end of file +} diff --git a/Model/Request/ShipmentOrder/Invoice.php b/Model/Request/ShipmentOrder/Invoice.php index 5213fd6..807c64b 100644 --- a/Model/Request/ShipmentOrder/Invoice.php +++ b/Model/Request/ShipmentOrder/Invoice.php @@ -3,62 +3,64 @@ namespace Intelipost\Push\Model\Request\ShipmentOrder; use Magento\Framework\Model\AbstractModel; +use Magento\Sales\Api\OrderRepositoryInterface; class Invoice extends AbstractModel { - private $invoice_number; - private $invoice_series; - private $invoice_key; - private $invoice_date; - private $invoice_total_value; - private $invoice_products_value; - private $invoice_cfop; + private $invoice_number; + private $invoice_series; + private $invoice_key; + private $invoice_date; + private $invoice_total_value; + private $invoice_products_value; + private $invoice_cfop; - protected $_collectionFactory; - protected $_helper; + protected $_collectionFactory; + protected $_helper; - public function __construct( - \Intelipost\Push\Model\Resource\Invoice\CollectionFactory $collectionFactory - ) - { - $this->_collectionFactory = $collectionFactory; - } + /** @var OrderRepositoryInterface $orderRepository */ + protected $orderRepository; - public function getInformation($order_number) - { - $invoiceCollection = $this->getInvoiceCollection($order_number); - foreach($invoiceCollection as $invoice) - { - $this->invoice_number = $invoice['invoice_number']; - $this->invoice_series = $invoice['invoice_series']; - $this->invoice_key = $invoice['invoice_key']; - $this->invoice_date = str_replace(' ', 'T', $invoice['invoice_date']); - $this->invoice_total_value = $invoice['invoice_total_value']; - $this->invoice_products_value = $invoice['invoice_products_value']; - $this->invoice_cfop = $invoice['invoice_cfop']; - } - $shipment_order_volume_invoice_obj = $this->preapreInvoiceObj(); - return $shipment_order_volume_invoice_obj; - } + /** + * Invoice constructor. + * @param \Intelipost\Push\Model\Resource\Invoice\CollectionFactory $collectionFactory + * @param OrderRepositoryInterface $orderRepository + */ + public function __construct( + \Intelipost\Push\Model\Resource\Invoice\CollectionFactory $collectionFactory, + OrderRepositoryInterface $orderRepository + ) + { + $this->_collectionFactory = $collectionFactory; + $this->orderRepository = $orderRepository; + } - public function getInvoiceCollection($order_number) - { - $iCollection = $this->_collectionFactory->create(); - $iCollection->addFieldToFilter('order_number', array('eq' => $order_number)); - return $iCollection->getData(); - } + public function getInformation($orderId) + { + $order = $this->orderRepository->get((int) $orderId); - public function preapreInvoiceObj() - { - $shipment_order_volume_invoice = new \Stdclass(); - $shipment_order_volume_invoice->invoice_number = $this->invoice_number; - $shipment_order_volume_invoice->invoice_series = $this->invoice_series; - $shipment_order_volume_invoice->invoice_key = $this->invoice_key; - $shipment_order_volume_invoice->invoice_date = $this->invoice_date; - $shipment_order_volume_invoice->invoice_total_value = $this->invoice_total_value; - $shipment_order_volume_invoice->invoice_products_value = $this->invoice_products_value; - $shipment_order_volume_invoice->invoice_cfop = $this->invoice_cfop; + $this->invoice_number = $order->getEntityId(); + $this->invoice_series = $order->getIncrementId(); + $this->invoice_key = '01234567890123456789012345678901234567891234'; + $this->invoice_date = str_replace(' ', 'T', $order->getCreatedAt()); + $this->invoice_total_value = number_format($order->getGrandTotal(), '2', '.', ''); + $this->invoice_products_value = number_format($order->getSubtotalInclTax(), '2', '.', ''); + $this->invoice_cfop = "1612"; - return $shipment_order_volume_invoice; - } + $shipment_order_volume_invoice_obj = $this->preapreInvoiceObj(); + return $shipment_order_volume_invoice_obj; + } + + public function preapreInvoiceObj() + { + $shipment_order_volume_invoice = new \Stdclass(); + $shipment_order_volume_invoice->invoice_number = $this->invoice_number; + $shipment_order_volume_invoice->invoice_series = $this->invoice_series; + $shipment_order_volume_invoice->invoice_date = $this->invoice_date; + $shipment_order_volume_invoice->invoice_total_value = $this->invoice_total_value; + $shipment_order_volume_invoice->invoice_products_value = $this->invoice_products_value; + $shipment_order_volume_invoice->invoice_cfop = $this->invoice_cfop; + + return $shipment_order_volume_invoice; + } } \ No newline at end of file diff --git a/Observer/OrderSaveAfter.php b/Observer/OrderSaveAfter.php index 791daad..311e0f1 100644 --- a/Observer/OrderSaveAfter.php +++ b/Observer/OrderSaveAfter.php @@ -45,7 +45,7 @@ public function execute(Observer $observer) $order = $observer->getOrder(); $magentoStatus = $order->getStatus(); $entity_id = $order->getEntityId(); - + $statusToCreate = $this->_scopeConfig->getValue('intelipost_push/order_status/status_to_create'); $magentoStatusAfterCreate = $this->_scopeConfig->getValue('intelipost_push/order_status/magento_status_after_create'); $createAndShip = $this->_scopeConfig->getValue('intelipost_push/order_status/create_and_ship'); @@ -57,18 +57,18 @@ public function execute(Observer $observer) //Apenas uma entrega if(sizeof($shipmentObj) == 1) - { + { foreach($colData as $shipment) { //criação do pedido if($magentoStatus == $statusToCreate && $shipment['intelipost_status'] == 'pending') { $col = $this->_shipmentOrder->create(); - $col->shipmentOrder($shipment); + $col->shipmentOrder($shipment); } //despacho do pedido - if(!$createAndShip && $magentoStatus == $statusToShip && $shipment['intelipost_status'] == 'created') + if(!$createAndShip && $magentoStatus == $statusToShip) { $col = $this->_shipped->create(); $col->shippedRequestBody($shipment); @@ -84,7 +84,7 @@ public function execute(Observer $observer) $this->_helper->logIntelipost(json_encode('duas entregas')); //criação do pedidos foreach($colData as $shipment) - { + { //fazer o match dos skus e criar as entregas relativas na Intelipost } diff --git a/composer.json b/composer.json index abe537e..00ecfa1 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,13 @@ { - "name": "intelipost/magento2-push", - "description": "Intelipost Push", + "name": "luanet/magento2-push", + "description": "Fork Intelipost Push", "type": "magento2-module", - "version": "1.0.0", + "version": "1.0.6", "authors": [ { - "name": "Alex Restani", - "email": "integracoes@intelipost.com.br", - "homepage": "http://www.intelipost.com.br/" + "name": "Lucas Santos", + "email": "lsantos@lua.net", + "homepage": "http://lua.net/" } ], "license": [ @@ -26,4 +26,4 @@ "Intelipost\\Push\\": "" } } -} \ No newline at end of file +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 6bf9f5f..3d08e14 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -20,7 +20,7 @@ - Intelipost\Quote\Model\Config\Source\Attribute + Intelipost\Push\Model\Config\Source\Customer\Attributes Select CPF attribute diff --git a/etc/di.xml b/etc/di.xml index 76168e1..08d8452 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -1,20 +1,20 @@ - - - + - + + + + Intelipost\Quote\Model\Resource\Shipment\Grid\Collection + + + + intelipost_shipment intelipost_quote_grid_collection - intelipost_grid_collection + intelipost_grid_collection Intelipost\Quote\Model\Resource\Shipment - + @@ -22,4 +22,4 @@ - \ No newline at end of file +