public function testGetTaxClass()
 {
     $taxClassId = 1;
     $this->classModelMock->expects($this->exactly(2))->method('getId')->will($this->returnValue($taxClassId));
     $this->classModelMock->expects($this->once())->method('load')->with($taxClassId)->will($this->returnValue($this->classModelMock));
     $this->assertEquals($this->classModelMock, $this->taxRuleRegistry->retrieve($taxClassId));
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function delete(\Magento\Tax\Api\Data\TaxClassInterface $taxClass)
 {
     $taxClassId = $taxClass->getClassId();
     try {
         $this->taxClassResource->delete($taxClass);
     } catch (CouldNotDeleteException $e) {
         throw $e;
     } catch (\Exception $e) {
         return false;
     }
     $this->classModelRegistry->remove($taxClassId);
     return true;
 }
 /**
  * {@inheritdoc}
  */
 public function deleteTaxClass($taxClassId)
 {
     $taxClassModel = $this->classModelRegistry->retrieve($taxClassId);
     try {
         $taxClassModel->delete();
     } catch (CouldNotDeleteException $e) {
         throw $e;
     } catch (\Exception $e) {
         return false;
     }
     $this->classModelRegistry->remove($taxClassId);
     return true;
 }
 /**
  * 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());
     }
 }
Example #5
0
 /**
  * Validate rule model
  *
  * @param \Magento\Tax\Model\Calculation\Rule $value
  * @return boolean
  * @throws Zend_Validate_Exception If validation of $value is impossible
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function isValid($value)
 {
     $messages = [];
     // Position is required and must be 0 or greater
     if (!\Zend_Validate::is(trim($value->getPosition()), 'NotEmpty')) {
         $this->addErrorMessage($messages, InputException::REQUIRED_FIELD, ['fieldName' => 'position']);
     }
     if (!\Zend_Validate::is(trim($value->getPosition()), 'GreaterThan', [-1])) {
         $this->addErrorMessage($messages, InputException::INVALID_FIELD_MIN_VALUE, ['fieldName' => 'position', 'value' => $value->getPosition(), 'minValue' => 0]);
     }
     // Priority is required and must be 0 or greater
     if (!\Zend_Validate::is(trim($value->getPriority()), 'NotEmpty')) {
         $this->addErrorMessage($messages, InputException::REQUIRED_FIELD, ['fieldName' => 'priority']);
     }
     if (!\Zend_Validate::is(trim($value->getPriority()), 'GreaterThan', [-1])) {
         $this->addErrorMessage($messages, InputException::INVALID_FIELD_MIN_VALUE, ['fieldName' => 'priority', 'value' => $value->getPriority(), 'minValue' => 0]);
     }
     // Code is required
     if (!\Zend_Validate::is(trim($value->getCode()), 'NotEmpty')) {
         $this->addErrorMessage($messages, InputException::REQUIRED_FIELD, ['fieldName' => 'code']);
     }
     // customer tax class ids is required
     if ($value->getCustomerTaxClassIds() === null || !$value->getCustomerTaxClassIds()) {
         $this->addErrorMessage($messages, InputException::REQUIRED_FIELD, ['fieldName' => 'customer_tax_class_ids']);
     } else {
         // see if the customer tax class ids exist
         $customerTaxClassIds = $value->getCustomerTaxClassIds();
         foreach ($customerTaxClassIds as $customerTaxClassId) {
             try {
                 $taxClass = $this->classModelRegistry->retrieve($customerTaxClassId);
                 if ($taxClass === null || !($taxClass->getClassType() == TaxClassModel::TAX_CLASS_TYPE_CUSTOMER)) {
                     $this->addErrorMessage($messages, NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'customer_tax_class_ids', 'value' => $customerTaxClassId]);
                 }
             } catch (NoSuchEntityException $e) {
                 $this->addErrorMessage($messages, $e->getRawMessage(), $e->getParameters());
             }
         }
     }
     // product tax class ids is required
     if ($value->getProductTaxClassIds() === null || !$value->getProductTaxClassIds()) {
         $this->addErrorMessage($messages, InputException::REQUIRED_FIELD, ['fieldName' => 'product_tax_class_ids']);
     } else {
         // see if the product tax class ids exist
         $productTaxClassIds = $value->getProductTaxClassIds();
         foreach ($productTaxClassIds as $productTaxClassId) {
             try {
                 $taxClass = $this->classModelRegistry->retrieve($productTaxClassId);
                 if ($taxClass === null || !($taxClass->getClassType() == TaxClassModel::TAX_CLASS_TYPE_PRODUCT)) {
                     $this->addErrorMessage($messages, NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'product_tax_class_ids', 'value' => $productTaxClassId]);
                 }
             } catch (NoSuchEntityException $e) {
                 $this->addErrorMessage($messages, $e->getRawMessage(), $e->getParameters());
             }
         }
     }
     // tax rate ids is required
     if ($value->getTaxRateIds() === null || !$value->getTaxRateIds()) {
         $this->addErrorMessage($messages, InputException::REQUIRED_FIELD, ['fieldName' => 'tax_rate_ids']);
     }
     $this->_addMessages($messages);
     return empty($messages);
 }