コード例 #1
0
 /**
  * @param \Magento\Sales\Model\Spi\InvoiceResourceInterface $subject
  * @param \Closure $proceed
  *
  *        Include both the extended AbstractModel and implemented Interface here for the IDE's benefit
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Sales\Api\Data\InvoiceInterface $entity
  * @param mixed $value
  * @param string $field field to load by (defaults to model id)
  * @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  */
 public function aroundLoad(InvoiceResourceInterface $subject, \Closure $proceed, AbstractModel $entity, $value, $field = null)
 {
     /** @var \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resultEntity */
     $resultEntity = $proceed($entity, $value, $field);
     // Load AvaTax extension attributes
     if ($this->avaTaxConfig->isModuleEnabled($entity->getStoreId())) {
         // Get the AvaTax Attributes from the AbstractModel
         $avataxIsUnbalanced = $entity->getData('avatax_is_unbalanced');
         $baseAvataxTaxAmount = $entity->getData('base_avatax_tax_amount');
         // Check the AvaTax Entity to see if we need to add extension attributes
         if ($avataxIsUnbalanced !== null || $baseAvataxTaxAmount !== null) {
             // Get any existing extension attributes or create a new one
             $entityExtension = $entity->getExtensionAttributes();
             if (!$entityExtension) {
                 $entityExtension = $this->invoiceExtensionFactory->create();
             }
             // Set the attributes
             if ($avataxIsUnbalanced !== null) {
                 $entityExtension->setAvataxIsUnbalanced($avataxIsUnbalanced);
             }
             if ($baseAvataxTaxAmount !== null) {
                 $entityExtension->setBaseAvataxTaxAmount($baseAvataxTaxAmount);
             }
             // save the ExtensionAttributes on the entity object
             $entity->setExtensionAttributes($entityExtension);
         }
     }
     return $resultEntity;
 }
コード例 #2
0
 /**
  * @param \Magento\Sales\Api\Data\InvoiceInterface|\Magento\Sales\Api\Data\CreditmemoInterface $entity
  * @return \Magento\Sales\Api\Data\InvoiceExtension|\Magento\Sales\Api\Data\CreditmemoExtension
  * @throws \Exception
  */
 protected function getEntityExtensionInterface($entity)
 {
     if ($entity instanceof InvoiceInterface) {
         return $this->invoiceExtensionFactory->create();
     } elseif ($entity instanceof CreditmemoInterface) {
         return $this->creditmemoExtensionFactory->create();
     } else {
         $message = __('Did not receive a valid entity instance to determine the extension to return');
         throw new \Exception($message);
     }
 }