コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function getList($sku, $customerGroupId)
 {
     $product = $this->productRepository->get($sku, ['edit_mode' => true]);
     $priceKey = 'website_price';
     $value = $this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE);
     if ($value == 0) {
         $priceKey = 'price';
     }
     $prices = [];
     foreach ($product->getData('tier_price') as $price) {
         if (is_numeric($customerGroupId) && intval($price['cust_group']) === intval($customerGroupId) || $customerGroupId === 'all' && $price['all_groups']) {
             /** @var \Magento\Catalog\Api\Data\ProductTierPriceInterface $tierPrice */
             $tierPrice = $this->priceFactory->create();
             $tierPrice->setValue($price[$priceKey])->setQty($price['price_qty']);
             $prices[] = $tierPrice;
         }
     }
     return $prices;
 }
コード例 #2
0
ファイル: Price.php プロジェクト: pradeep-wagento/magento2
 /**
  * Gets list of product tier prices
  *
  * @param Product $product
  * @return \Magento\Catalog\Api\Data\ProductTierPriceInterface[]
  */
 public function getTierPrices($product)
 {
     $prices = [];
     $tierPrices = $this->getExistingPrices($product, 'tier_price');
     foreach ($tierPrices as $price) {
         /** @var \Magento\Catalog\Api\Data\ProductTierPriceInterface $tierPrice */
         $tierPrice = $this->tierPriceFactory->create();
         $tierPrice->setCustomerGroupId($price['cust_group']);
         if (array_key_exists('website_price', $price)) {
             $value = $price['website_price'];
         } else {
             $value = $price['price'];
         }
         $tierPrice->setValue($value);
         $tierPrice->setQty($price['price_qty']);
         $prices[] = $tierPrice;
     }
     return $prices;
 }