示例#1
0
 /**
  * Get options
  *
  * @return array
  */
 public function toOptionArray()
 {
     if ($this->options === null) {
         $this->options = [];
         /** @var \Magento\Framework\Phrase $state */
         foreach ($this->creditmemoFactory->create()->getStates() as $id => $state) {
             $this->options[] = ['value' => $id, 'label' => $state->render()];
         }
     }
     return $this->options;
 }
示例#2
0
文件: Order.php 项目: aiesh/magento2
 /**
  * Convert order object to creditmemo
  *
  * @param   \Magento\Sales\Model\Order $order
  * @return  \Magento\Sales\Model\Order\Creditmemo
  */
 public function toCreditmemo(\Magento\Sales\Model\Order $order)
 {
     $creditmemo = $this->_creditmemoFactory->create();
     $creditmemo->setOrder($order)->setStoreId($order->getStoreId())->setCustomerId($order->getCustomerId())->setBillingAddressId($order->getBillingAddressId())->setShippingAddressId($order->getShippingAddressId());
     $this->_objectCopyService->copyFieldsetToTarget('sales_convert_order', 'to_cm', $order, $creditmemo);
     return $creditmemo;
 }
示例#3
0
 /**
  * Initialize creditmemo model instance
  *
  * @return \Magento\Sales\Model\Order\Creditmemo|false
  */
 public function load()
 {
     $creditmemo = false;
     $creditmemoId = $this->getCreditmemoId();
     $orderId = $this->getOrderId();
     if ($creditmemoId) {
         $creditmemo = $this->creditmemoFactory->create()->load($creditmemoId);
     } elseif ($orderId) {
         $data = $this->getCreditmemo();
         $order = $this->orderFactory->create()->load($orderId);
         $invoice = $this->_initInvoice($order);
         if (!$this->_canCreditmemo($order)) {
             return false;
         }
         $savedData = $this->_getItemData();
         $qtys = array();
         $backToStock = array();
         foreach ($savedData as $orderItemId => $itemData) {
             if (isset($itemData['qty'])) {
                 $qtys[$orderItemId] = $itemData['qty'];
             }
             if (isset($itemData['back_to_stock'])) {
                 $backToStock[$orderItemId] = true;
             }
         }
         $data['qtys'] = $qtys;
         $service = $this->orderServiceFactory->create(array('order' => $order));
         if ($invoice) {
             $creditmemo = $service->prepareInvoiceCreditmemo($invoice, $data);
         } else {
             $creditmemo = $service->prepareCreditmemo($data);
         }
         /**
          * Process back to stock flags
          */
         foreach ($creditmemo->getAllItems() as $creditmemoItem) {
             $orderItem = $creditmemoItem->getOrderItem();
             $parentId = $orderItem->getParentItemId();
             if (isset($backToStock[$orderItem->getId()])) {
                 $creditmemoItem->setBackToStock(true);
             } elseif ($orderItem->getParentItem() && isset($backToStock[$parentId]) && $backToStock[$parentId]) {
                 $creditmemoItem->setBackToStock(true);
             } elseif (empty($savedData)) {
                 $creditmemoItem->setBackToStock($this->inventoryHelper->isAutoReturnEnabled());
             } else {
                 $creditmemoItem->setBackToStock(false);
             }
         }
     }
     $this->eventManager->dispatch('adminhtml_sales_order_creditmemo_register_before', array('creditmemo' => $creditmemo, 'input' => $this->getCreditmemo()));
     $this->registry->register('current_creditmemo', $creditmemo);
     return $creditmemo;
 }
示例#4
0
 /**
  * Return option array
  *
  * @return array
  */
 public function toOptionArray()
 {
     return $this->creditmemoFactory->create()->getStates();
 }
示例#5
0
文件: State.php 项目: nja78/magento2
 /**
  * Constructor
  *
  * @param ContextInterface $context
  * @param UiComponentFactory $uiComponentFactory
  * @param CreditmemoFactory $creditmemoFactory
  * @param array $components
  * @param array $data
  */
 public function __construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, CreditmemoFactory $creditmemoFactory, array $components = [], array $data = [])
 {
     $this->states = $creditmemoFactory->create()->getStates();
     parent::__construct($context, $uiComponentFactory, $components, $data);
 }