Esempio n. 1
0
 /**
  * Run test getAllOptions method
  *
  * @param bool $isEmpty
  * @param array $expected
  * @dataProvider dataProviderGetAllOptions
  */
 public function testGetAllOptions($isEmpty, array $expected)
 {
     $filterMock = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false);
     $searchCriteriaMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
     $searchResultsMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassSearchResultsInterface', [], '', false, true, true, ['getItems']);
     $taxClassMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassInterface', ['getClassId', 'getClassName'], '', false, true, true);
     $this->filterBuilderMock->expects($this->once())->method('setField')->with(\Magento\Tax\Model\ClassModel::KEY_TYPE)->willReturnSelf();
     $this->filterBuilderMock->expects($this->once())->method('setValue')->with(\Magento\Tax\Api\TaxClassManagementInterface::TYPE_CUSTOMER)->willReturnSelf();
     $this->filterBuilderMock->expects($this->once())->method('create')->willReturn($filterMock);
     $this->searchCriteriaBuilderMock->expects($this->once())->method('addFilter')->with([$filterMock])->willReturnSelf();
     $this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock);
     $this->taxClassRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultsMock);
     if (!$isEmpty) {
         $taxClassMock->expects($this->once())->method('getClassId')->willReturn(10);
         $taxClassMock->expects($this->once())->method('getClassName')->willReturn('class-name');
         $items = [$taxClassMock];
         $searchResultsMock->expects($this->once())->method('getItems')->willReturn($items);
         // checking of a lack of re-initialization
         for ($i = 10; --$i;) {
             $result = $this->customer->getAllOptions();
             $this->assertEquals($expected, $result);
         }
     } else {
         $items = [];
         $searchResultsMock->expects($this->once())->method('getItems')->willReturn($items);
         // checking exception
         $this->assertEmpty($this->customer->getAllOptions());
     }
 }
Esempio n. 2
0
 /**
  * Retrieve all customer tax classes as an options array.
  *
  * @return array
  * @throws StateException
  */
 public function getAllOptions()
 {
     if (empty($this->_options)) {
         $options = [];
         $filter = $this->filterBuilder->setField(TaxClass::KEY_TYPE)->setValue(TaxClassManagementInterface::TYPE_CUSTOMER)->create();
         $searchCriteria = $this->searchCriteriaBuilder->addFilter([$filter])->create();
         $searchResults = $this->taxClassRepository->getList($searchCriteria);
         foreach ($searchResults->getItems() as $taxClass) {
             $options[] = ['value' => $taxClass->getClassId(), 'label' => $taxClass->getClassName()];
         }
         $this->_options = $options;
     }
     return $this->_options;
 }
Esempio n. 3
0
 /**
  * Log page
  *
  * @return \Magento\Backend\Model\View\Result\Page
  */
 public function execute()
 {
     try {
         $taxClass = $this->taxClassRepository->get($this->getRequest()->getParam('id'));
         $this->coreRegistry->register('current_tax_class', $taxClass);
         /** @var Page $pageResult */
         $pageResult = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
         $pageResult->setActiveMenu('ClassyLlama_AvaTax::avatax_tax_classes_' . \strtolower($this->classType));
         $pageResult->getConfig()->getTitle()->prepend(__('Edit ' . \ucfirst(\strtolower($this->classType)) . ' Tax Class'));
         return $pageResult;
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         $this->messageManager->addError(__('We can\'t find this tax class.'));
         /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
         $resultRedirect = $this->resultRedirectFactory->create();
         return $resultRedirect->setPath('*/*/');
     }
 }
 /**
  * Get the AvaTax Tax Code for a product
  *
  * @param int $taxClassId
  * @return string|null
  */
 protected function getAvaTaxTaxCode($taxClassId)
 {
     try {
         $taxClass = $this->taxClassRepository->get($taxClassId);
         return $taxClass->getAvataxCode();
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         return null;
     }
 }
Esempio n. 5
0
 /**
  * Retrieve all product tax class options.
  *
  * @param bool $withEmpty
  * @return array
  */
 public function getAllOptions($withEmpty = true)
 {
     if (!$this->_options) {
         $filter = $this->_filterBuilder->setField(TaxClass::KEY_TYPE)->setValue(TaxClassManagementInterface::TYPE_PRODUCT)->create();
         $searchCriteria = $this->_searchCriteriaBuilder->addFilter([$filter])->create();
         $searchResults = $this->_taxClassRepository->getList($searchCriteria);
         foreach ($searchResults->getItems() as $taxClass) {
             $this->_options[] = ['value' => $taxClass->getClassId(), 'label' => $taxClass->getClassName()];
         }
     }
     if ($withEmpty) {
         if (!$this->_options) {
             return [['value' => '0', 'label' => __('None')]];
         } else {
             return array_merge([['value' => '0', 'label' => __('None')]], $this->_options);
         }
     }
     return $this->_options;
 }
Esempio n. 6
0
 /**
  * Run test getAllOptions method for names integrity
  *
  * @param array $value
  * @dataProvider dataProviderGetAllOptionsNameIntegrity
  */
 public function testGetAllOptionsNameIntegrity(array $value)
 {
     $filterMock = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false);
     $searchCriteriaMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
     $searchResultsMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassSearchResultsInterface', [], '', false, true, true, ['getItems']);
     $taxClassMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassInterface', ['getClassId', 'getClassName'], '', false, true, true);
     $this->filterBuilderMock->expects($this->once())->method('setField')->with(\Magento\Tax\Model\ClassModel::KEY_TYPE)->willReturnSelf();
     $this->filterBuilderMock->expects($this->once())->method('setValue')->with(\Magento\Tax\Api\TaxClassManagementInterface::TYPE_PRODUCT)->willReturnSelf();
     $this->filterBuilderMock->expects($this->once())->method('create')->willReturn($filterMock);
     $this->searchCriteriaBuilderMock->expects($this->once())->method('addFilters')->with([$filterMock])->willReturnSelf();
     $this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock);
     $this->taxClassRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultsMock);
     $taxClassMock->expects($this->once())->method('getClassId')->willReturn($value['value']);
     $taxClassMock->expects($this->once())->method('getClassName')->willReturn($value['label']);
     $items = [$taxClassMock];
     $searchResultsMock->expects($this->once())->method('getItems')->willReturn($items);
     $result = $this->product->getAllOptions(false);
     $expected = $value;
     $this->assertEquals([$expected], $result);
 }
Esempio n. 7
0
 /**
  * Verifies that the tax class model exists and is a customer tax class type.
  *
  * @param int $taxClassId The id of the tax class model to check
  * @param \Magento\Customer\Api\Data\GroupInterface $group The original group parameters
  * @return void
  * @throws InputException Thrown if the tax class model is invalid
  */
 protected function _verifyTaxClassModel($taxClassId, $group)
 {
     try {
         /* @var TaxClassInterface $taxClassData */
         $taxClassData = $this->taxClassRepository->get($taxClassId);
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         throw InputException::invalidFieldValue('taxClassId', $group->getTaxClassId());
     }
     if ($taxClassData->getClassType() !== TaxClassManagementInterface::TYPE_CUSTOMER) {
         throw InputException::invalidFieldValue('taxClassId', $group->getTaxClassId());
     }
 }
 /**
  * @expectedException \Magento\Framework\Exception\State\InvalidTransitionException
  */
 public function testSaveWithException()
 {
     $taxClass = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassInterface', [], '', false);
     $this->groupFactory->expects($this->once())->method('create')->willReturn($this->groupModel);
     $this->group->expects($this->atLeastOnce())->method('getCode')->willReturn('Code');
     $this->group->expects($this->atLeastOnce())->method('getId')->willReturn(false);
     $this->group->expects($this->atLeastOnce())->method('getTaxClassId')->willReturn(234);
     $this->group->expects($this->atLeastOnce())->method('getTaxClassId')->willReturn(17);
     $this->groupModel->expects($this->once())->method('setCode')->with('Code');
     $this->groupModel->expects($this->once())->method('setTaxClassId')->with(234);
     $this->taxClassRepository->expects($this->once())->method('get')->with(234)->willReturn($taxClass);
     $taxClass->expects($this->once())->method('getClassType')->willReturn('CUSTOMER');
     $this->groupResourceModel->expects($this->once())->method('save')->with($this->groupModel)->willThrowException(new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Customer Group already exists.')));
     $this->model->save($this->group);
 }
 /**
  * Test delete Tax class
  */
 public function testDeleteTaxClass()
 {
     $taxClassDataObject = $this->taxClassFactory->create();
     $taxClassDataObject->setClassName(self::SAMPLE_TAX_CLASS_NAME . uniqid())->setClassType(TaxClassManagementInterface::TYPE_CUSTOMER);
     $taxClassId = $this->taxClassRepository->save($taxClassDataObject);
     $this->assertNotNull($taxClassId);
     //Verify by getting the Data\TaxClassInterface
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/' . $taxClassId, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'DeleteById']];
     $requestData = ['taxClassId' => $taxClassId];
     $result = $this->_webApiCall($serviceInfo, $requestData);
     $this->assertTrue($result);
     try {
         $this->taxClassRegistry->remove($taxClassId);
         $this->taxClassRepository->get($taxClassId);
         $this->fail("Tax class was not expected to be returned after being deleted.");
     } catch (NoSuchEntityException $e) {
         $this->assertEquals('No such entity with class_id = ' . $taxClassId, $e->getMessage());
     }
 }
Esempio n. 10
0
 /**
  * @param array $billingAddress
  * @param array $shippingAddress
  * @param int $customerTaxClassId
  * @return array
  */
 public function getTaxRates($billingAddress, $shippingAddress, $customerTaxClassId)
 {
     $billingAddressObj = null;
     $shippingAddressObj = null;
     if (!empty($billingAddress)) {
         $billingAddressObj = new \Magento\Framework\Object($billingAddress);
     }
     if (!empty($shippingAddress)) {
         $shippingAddressObj = new \Magento\Framework\Object($shippingAddress);
     }
     $rateRequest = $this->getRateRequest($shippingAddressObj, $billingAddressObj, $customerTaxClassId);
     $searchCriteria = $this->searchCriteriaBuilder->addFilters([$this->filterBuilder->setField(ClassModel::KEY_TYPE)->setValue(\Magento\Tax\Api\TaxClassManagementInterface::TYPE_PRODUCT)->create()])->create();
     $ids = $this->taxClassRepository->getList($searchCriteria)->getItems();
     $productRates = [];
     $idKeys = array_keys($ids);
     foreach ($idKeys as $idKey) {
         $rateRequest->setProductClassId($idKey);
         $rate = $this->getRate($rateRequest);
         $productRates[$idKey] = $rate;
     }
     return $productRates;
 }