示例#1
0
 /**
  * Returns the item price for the specified product.
  *
  * @param InjectableFixture $product
  * @return array|string
  */
 public function getPrice(InjectableFixture $product)
 {
     $productName = $product->getName();
     if ($product instanceof ConfigurableProduct) {
         // Find the price for the specific configurable product that was purchased
         $attributesData = $product->getConfigurableAttributesData()['attributes_data'];
         $matrix = $product->getConfigurableAttributesData()['matrix'];
         $checkoutOptions = $product->getCheckoutData()['options']['configurable_options'];
         $optionsDetails = [];
         $matrixKey = [];
         $optionsPrice = 0;
         foreach ($checkoutOptions as $checkoutOption) {
             $titleKey = $checkoutOption['title'];
             $valueKey = $checkoutOption['value'];
             $attributeName = $attributesData[$titleKey]['frontend_label'];
             $optionLabel = $attributesData[$titleKey]['options'][$valueKey]['label'];
             $optionsDetails[] = "{$attributeName}{$optionLabel}";
             $matrixKey[] = "{$titleKey}:{$valueKey}";
             $optionsPrice += $attributesData[$titleKey]['options'][$valueKey]['pricing_value'];
         }
         $optionsDetails = implode(' ', $optionsDetails);
         $matrixKey = implode(' ', $matrixKey);
         $productDisplay = $productName . 'SKU: ' . $matrix[$matrixKey]['sku'] . $optionsDetails;
     } else {
         $productDisplay = $productName . 'SKU: ' . $product->getSku();
     }
     $selector = '//tr[normalize-space(td)="' . $productDisplay . '"]' . $this->priceSelector;
     return $this->escapeCurrency($this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->getText());
 }