/**
  * @return bool|int
  */
 public function getId()
 {
     if (null === $this->defaultWebsiteId && $this->storeSwitcher->isInitialized()) {
         try {
             $storeId = $this->storeSwitcher->getStoreId();
             if ($storeId) {
                 $store = $this->storeRepository->getById($storeId);
                 $this->defaultWebsiteId = $store->getWebsiteId();
             } else {
                 $this->defaultWebsiteId = false;
             }
         } catch (\Exception $e) {
             $this->defaultWebsiteId = false;
         }
     }
     return $this->defaultWebsiteId ?: false;
 }
 /**
  * @param int|bool $storeId
  * @return \Magento\Store\Model\Website
  */
 protected function getWebsite($storeId)
 {
     if ($storeId) {
         $websiteId = $this->storeRepository->getById($storeId)->getWebsiteId();
         $website = $this->websiteRepository->getById($websiteId);
     } else {
         $website = $this->websiteRepository->getDefault();
     }
     return $website;
 }
 /**
  * Get data
  *
  * @return array
  */
 public function getData()
 {
     if (!$this->getCollection()->isLoaded()) {
         $this->getCollection()->addAttributeToFilter('type_id', $this->config->getComposableTypes());
         if ($storeId = $this->request->getParam('current_store_id')) {
             /** @var StoreInterface $store */
             $store = $this->storeRepository->getById($storeId);
             $this->getCollection()->setStore($store);
         }
         $this->getCollection()->load();
     }
     $items = $this->getCollection()->toArray();
     return ['totalRecords' => $this->getCollection()->getSize(), 'items' => array_values($items)];
 }
 /**
  * Retrieve store
  *
  * @return StoreInterface|null
  */
 protected function getStore()
 {
     if (null !== $this->store) {
         return $this->store;
     }
     if (!($storeId = $this->request->getParam('current_store_id'))) {
         return null;
     }
     return $this->store = $this->storeRepository->getById($storeId);
 }
 /**
  * {@inheritdoc}
  */
 public function getStore($storeId = null)
 {
     if (!isset($storeId) || '' === $storeId || $storeId === true) {
         if (!$this->currentStoreId) {
             \Magento\Framework\Profiler::start('store.resolve');
             $this->currentStoreId = $this->storeResolver->getCurrentStoreId();
             \Magento\Framework\Profiler::stop('store.resolve');
         }
         $storeId = $this->currentStoreId;
     }
     if ($storeId instanceof \Magento\Store\Api\Data\StoreInterface) {
         return $storeId;
     }
     $store = is_numeric($storeId) ? $this->storeRepository->getById($storeId) : $this->storeRepository->get($storeId);
     return $store;
 }
 /**
  * @return \Magento\Store\Model\Store
  */
 protected function loadSource()
 {
     return $this->storeRespository->getById($this->getStoreId());
 }
Esempio n. 7
0
 /**
  * Creates and returns a populated getTaxRequest for a invoice
  *
  * @param \Magento\Sales\Api\Data\InvoiceInterface|\Magento\Sales\Api\Data\CreditmemoInterface $object
  * @return GetTaxRequest
  */
 public function getGetTaxRequestForSalesObject($object)
 {
     $order = $this->orderRepository->get($object->getOrderId());
     $lines = [];
     $items = $object->getItems();
     $this->taxClassHelper->populateCorrectTaxClasses($items, $object->getStoreId());
     /** @var \Magento\Tax\Api\Data\QuoteDetailsItemInterface $item */
     foreach ($items as $item) {
         $line = $this->interactionLine->getLine($item);
         if ($line) {
             $lines[] = $line;
         }
     }
     $objectIsCreditMemo = $object instanceof \Magento\Sales\Api\Data\CreditmemoInterface;
     $credit = $objectIsCreditMemo;
     $line = $this->interactionLine->getShippingLine($object, $credit);
     if ($line) {
         $lines[] = $line;
     }
     $line = $this->interactionLine->getGiftWrapItemsLine($object, $credit);
     if ($line) {
         $lines[] = $line;
     }
     $line = $this->interactionLine->getGiftWrapOrderLine($object, $credit);
     if ($line) {
         $lines[] = $line;
     }
     $line = $this->interactionLine->getGiftWrapCardLine($object, $credit);
     if ($line) {
         $lines[] = $line;
     }
     if ($objectIsCreditMemo) {
         $line = $this->interactionLine->getPositiveAdjustmentLine($object);
         if ($line) {
             $lines[] = $line;
         }
         $line = $this->interactionLine->getNegativeAdjustmentLine($object);
         if ($line) {
             $lines[] = $line;
         }
     }
     /** @var \Magento\Sales\Api\Data\OrderAddressInterface $address */
     if (!$order->getIsVirtual()) {
         $address = $order->getShippingAddress();
     } else {
         $address = $order->getBillingAddress();
     }
     $avaTaxAddress = $this->address->getAddress($address);
     $store = $this->storeRepository->getById($object->getStoreId());
     $currentDate = $this->getFormattedDate($store, $object->getCreatedAt());
     $taxOverride = null;
     if ($object instanceof \Magento\Sales\Api\Data\InvoiceInterface) {
         $docType = DocumentType::$SalesInvoice;
         if ($this->areTimesDifferentDays($order->getCreatedAt(), $object->getCreatedAt(), $object->getStoreId())) {
             $taxCalculationDate = $this->getFormattedDate($store, $order->getCreatedAt());
             // Set the tax date for calculation
             $taxOverride = $this->taxOverrideFactory->create();
             $taxOverride->setTaxDate($taxCalculationDate);
             $taxOverride->setTaxOverrideType(\AvaTax\TaxOverrideType::$TaxDate);
             $taxOverride->setTaxAmount(0.0);
             $taxOverride->setReason(self::AVATAX_INVOICE_OVERRIDE_REASON);
         }
     } else {
         $docType = DocumentType::$ReturnInvoice;
         $invoice = $this->getInvoice($object->getInvoiceId());
         // If a Creditmemo was generated for an invoice, use the created_at value from the invoice
         if ($invoice) {
             $taxCalculationDate = $this->getFormattedDate($store, $invoice->getCreatedAt());
         } else {
             $taxCalculationDate = $this->getFormattedDate($store, $order->getCreatedAt());
         }
         // Set the tax date for calculation
         $taxOverride = $this->taxOverrideFactory->create();
         $taxOverride->setTaxDate($taxCalculationDate);
         $taxOverride->setTaxOverrideType(\AvaTax\TaxOverrideType::$TaxDate);
         $taxOverride->setTaxAmount(0.0);
         $taxOverride->setReason(self::AVATAX_CREDITMEMO_OVERRIDE_REASON);
     }
     $customer = $this->getCustomerById($order->getCustomerId());
     $customerUsageType = $customer ? $this->taxClassHelper->getAvataxTaxCodeForCustomer($customer) : null;
     $data = ['StoreId' => $store->getId(), 'Commit' => $this->config->getCommitSubmittedTransactions($store), 'TaxOverride' => $taxOverride, 'CurrencyCode' => $order->getOrderCurrencyCode(), 'CustomerCode' => $this->getCustomerCode($order), 'CustomerUsageType' => $customerUsageType, 'DestinationAddress' => $avaTaxAddress, 'DocCode' => $object->getIncrementId() . '123-' . rand(10000000, 90000000000), 'DocDate' => $currentDate, 'DocType' => $docType, 'ExchangeRate' => $this->getExchangeRate($store, $order->getBaseCurrencyCode(), $order->getOrderCurrencyCode()), 'ExchangeRateEffDate' => $currentDate, 'Lines' => $lines, 'DetailLevel' => DetailLevel::$Document, 'PaymentDate' => $currentDate, 'PurchaseOrderNo' => $object->getIncrementId()];
     $data = array_merge($this->retrieveGetTaxRequestFields($store, $address, $object), $data);
     try {
         $data = $this->metaDataObject->validateData($data);
     } catch (ValidationException $e) {
         $this->avaTaxLogger->error('Error validating data: ' . $e->getMessage(), ['data' => var_export($data, true)]);
     }
     /** @var $getTaxRequest GetTaxRequest */
     $getTaxRequest = $this->getTaxRequestFactory->create();
     $this->populateGetTaxRequest($data, $getTaxRequest);
     return $getTaxRequest;
 }
Esempio n. 8
0
 /**
  * @return \Magento\Store\Model\Store
  */
 protected function loadSource()
 {
     return $this->storeRespository->getById($this->request->getData('store_id'));
 }
 /**
  * @param \Magento\Store\Model\Group $subject
  * @param \Magento\Store\Model\Store $store
  * @return \Magento\Store\Model\Store
  */
 public function afterGetDefaultStore(Group $subject, Store $store)
 {
     if ($this->generalConfig->isAvailable() && $this->storeSwitcher->isInitialized()) {
         $storeId = $this->storeSwitcher->getStoreId();
         if ($store->getId() != $storeId && in_array($storeId, $subject->getStoreIds())) {
             $store = $this->storeRepository->getById($storeId);
         }
     }
     return $store;
 }