コード例 #1
0
ファイル: ItemBuilder.php プロジェクト: zhangjiachao/magento2
 /**
  * {@inheritdoc}
  */
 protected function _setDataValues(array $data)
 {
     if (array_key_exists(Item::KEY_TAX_CLASS_KEY, $data)) {
         $data[Item::KEY_TAX_CLASS_KEY] = $this->taxClassKeyBuilder->populateWithArray($data[Item::KEY_TAX_CLASS_KEY])->create();
     }
     return parent::_setDataValues($data);
 }
コード例 #2
0
 /**
  * Creates a QuoteDetails item data object by calling setters.
  *
  * @param array $dataArray
  * @return Item
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 private function generateItemWithSetters($dataArray)
 {
     $this->quoteDetailsItemBuilder->populateWithArray([]);
     if (array_key_exists(Item::KEY_CODE, $dataArray)) {
         $this->quoteDetailsItemBuilder->setCode($dataArray[Item::KEY_CODE]);
     }
     if (array_key_exists(Item::KEY_TYPE, $dataArray)) {
         $this->quoteDetailsItemBuilder->setType($dataArray[Item::KEY_TYPE]);
     }
     if (array_key_exists(Item::KEY_TAX_CLASS_KEY, $dataArray)) {
         $this->quoteDetailsItemBuilder->setTaxClassKey($this->taxClassKeyBuilder->setType($dataArray[Item::KEY_TAX_CLASS_KEY][TaxClassKey::KEY_TYPE])->setValue($dataArray[Item::KEY_TAX_CLASS_KEY][TaxClassKey::KEY_VALUE])->create());
     }
     if (array_key_exists(Item::KEY_DISCOUNT_AMOUNT, $dataArray)) {
         $this->quoteDetailsItemBuilder->setDiscountAmount($dataArray[Item::KEY_DISCOUNT_AMOUNT]);
     }
     if (array_key_exists(Item::KEY_QUANTITY, $dataArray)) {
         $this->quoteDetailsItemBuilder->setQuantity($dataArray[Item::KEY_QUANTITY]);
     }
     if (array_key_exists(Item::KEY_PARENT_CODE, $dataArray)) {
         $this->quoteDetailsItemBuilder->setParentCode($dataArray[Item::KEY_PARENT_CODE]);
     }
     if (array_key_exists(Item::KEY_SHORT_DESCRIPTION, $dataArray)) {
         $this->quoteDetailsItemBuilder->setShortDescription($dataArray[Item::KEY_SHORT_DESCRIPTION]);
     }
     if (array_key_exists(Item::KEY_UNIT_PRICE, $dataArray)) {
         $this->quoteDetailsItemBuilder->setUnitPrice($dataArray[Item::KEY_UNIT_PRICE]);
     }
     if (array_key_exists(Item::KEY_TAX_INCLUDED, $dataArray)) {
         $this->quoteDetailsItemBuilder->setTaxIncluded($dataArray[Item::KEY_TAX_INCLUDED]);
     }
     return $this->quoteDetailsItemBuilder->create();
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 protected function _setDataValues(array $data)
 {
     if (array_key_exists(QuoteDetails::KEY_BILLING_ADDRESS, $data)) {
         $data[QuoteDetails::KEY_BILLING_ADDRESS] = $this->addressBuilder->populateWithArray($data[QuoteDetails::KEY_BILLING_ADDRESS])->create();
     }
     if (array_key_exists(QuoteDetails::KEY_SHIPPING_ADDRESS, $data)) {
         $data[QuoteDetails::KEY_SHIPPING_ADDRESS] = $this->addressBuilder->populateWithArray($data[QuoteDetails::KEY_SHIPPING_ADDRESS])->create();
     }
     if (array_key_exists(QuoteDetails::KEY_ITEMS, $data)) {
         $items = [];
         foreach ($data[QuoteDetails::KEY_ITEMS] as $itemArray) {
             $items[] = $this->itemBuilder->populateWithArray($itemArray)->create();
         }
         $data[QuoteDetails::KEY_ITEMS] = $items;
     }
     if (array_key_exists(QuoteDetails::KEY_CUSTOMER_TAX_CLASS_KEY, $data)) {
         $data[QuoteDetails::KEY_CUSTOMER_TAX_CLASS_KEY] = $this->taxClassKeyBuilder->populateWithArray($data[QuoteDetails::KEY_CUSTOMER_TAX_CLASS_KEY])->create();
     }
     return parent::_setDataValues($data);
 }
コード例 #4
0
ファイル: Data.php プロジェクト: pavelnovitsky/magento2
 /**
  * Get product price with all tax settings processing
  *
  * @param   \Magento\Catalog\Model\Product $product
  * @param   float $price inputted product price
  * @param   bool $includingTax return price include tax flag
  * @param   null|Address $shippingAddress
  * @param   null|Address $billingAddress
  * @param   null|int $ctc customer tax class
  * @param   null|string|bool|int|Store $store
  * @param   bool $priceIncludesTax flag what price parameter contain tax
  * @param   bool $roundPrice
  * @return  float
  */
 public function getTaxPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null, $ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true)
 {
     if (!$price) {
         return $price;
     }
     $store = $this->_storeManager->getStore($store);
     if ($this->_taxConfig->needPriceConversion($store)) {
         if (is_null($priceIncludesTax)) {
             $priceIncludesTax = $this->_taxConfig->priceIncludesTax($store);
         }
         $shippingAddressDataObject = null;
         if ($shippingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
             $shippingAddressDataObject = $this->_addressConverter->createAddressFromModel($shippingAddress, null, null);
         }
         $billingAddressDataObject = null;
         if ($billingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
             $billingAddressDataObject = $this->_addressConverter->createAddressFromModel($billingAddress, null, null);
         }
         $item = $this->_quoteDetailsItemBuilder->setQuantity(1)->setCode($product->getSku())->setShortDescription($product->getShortDescription())->setTaxClassKey($this->_taxClassKeyBuilder->setType(TaxClassKey::TYPE_ID)->setValue($product->getTaxClassId())->create())->setTaxIncluded($priceIncludesTax)->setType('product')->setUnitPrice($price)->create();
         $quoteDetails = $this->_quoteDetailsBuilder->setShippingAddress($shippingAddressDataObject)->setBillingAddress($billingAddressDataObject)->setCustomerTaxClassKey($this->_taxClassKeyBuilder->setType(TaxClassKey::TYPE_ID)->setValue($ctc)->create())->setItems([$item])->setCustomerId($this->_customerSession->getCustomerId())->create();
         $storeId = null;
         if ($store) {
             $storeId = $store->getId();
         }
         $taxDetails = $this->_taxCalculationService->calculateTax($quoteDetails, $storeId);
         $items = $taxDetails->getItems();
         $taxDetailsItem = array_shift($items);
         if (!is_null($includingTax)) {
             if ($includingTax) {
                 $price = $taxDetailsItem->getPriceInclTax();
             } else {
                 $price = $taxDetailsItem->getPrice();
             }
         } else {
             switch ($this->_taxConfig->getPriceDisplayType($store)) {
                 case Config::DISPLAY_TYPE_EXCLUDING_TAX:
                 case Config::DISPLAY_TYPE_BOTH:
                     $price = $taxDetailsItem->getPrice();
                     break;
                 case Config::DISPLAY_TYPE_INCLUDING_TAX:
                     $price = $taxDetailsItem->getPriceInclTax();
                     break;
                 default:
                     break;
             }
         }
     }
     if ($roundPrice) {
         return $store->roundPrice($price);
     } else {
         return $price;
     }
 }