/**
  * Prepare filter for attribute.
  *
  * @param ConfigurableProduct $product
  * @param string $filterLink
  * @return array
  */
 protected function prepareFilter(ConfigurableProduct $product, $filterLink)
 {
     list($attributeKey, $optionKey) = explode('::', $filterLink);
     $attributesData = $product->getConfigurableOptions()['attributes_data'];
     return ['attribute' => $attributesData[$attributeKey]['frontend_label'], 'option' => $attributesData[$attributeKey]['options'][$optionKey]['label']];
 }
 /**
  * Prepare data for configurable product.
  *
  * @param ConfigurableProduct $product
  * @return array
  */
 protected function prepareConfigurableData(ConfigurableProduct $product)
 {
     $result = [];
     $checkoutData = $product->getCheckoutData();
     $result['qty'] = $checkoutData['qty'];
     $attributesData = $product->hasData('configurable_options') ? $product->getDataFieldConfig('configurable_options')['source']->getAttributesData() : null;
     if ($attributesData == null) {
         return $result;
     }
     foreach ($checkoutData['options']['configurable_options'] as $key => $option) {
         $attributeId = $attributesData[$key]->getAttributeId();
         $optionId = $attributesData[$key]->getOptions()[substr($option['value'], -1)]['id'];
         $result['super_attribute'][$attributeId] = $optionId;
     }
     return $result;
 }
 /**
  * Get configurable options source for original product.
  *
  * @return ConfigurableOptions
  */
 protected function getOriginalProductOptionsSource()
 {
     return $this->product->getDataFieldConfig('configurable_options')['source'];
 }
Exemple #4
0
 /**
  * Prepare configurable product data.
  *
  * @param ConfigurableProduct $product
  * @param array $valuesIndexes
  * @return string
  */
 protected function prepareConfigurableProductData(ConfigurableProduct $product, array $valuesIndexes)
 {
     $result = [];
     $configurableOptions = $product->getConfigurableOptions();
     $configurableOptionsSource = $product->getDataFieldConfig('configurable_options')['source'];
     $associatedProducts = $this->splitProducts($configurableOptionsSource->getProducts());
     foreach ($configurableOptions['attributes_data'] as $attributeKey => $attribute) {
         foreach ($attribute['options'] as $optionKey => $option) {
             $productId = $associatedProducts[$attributeKey . ':' . $optionKey]->getId();
             $result[$productId][] = ['label' => $option['label'], 'attribute_id' => $attribute['attribute_id'], 'value_index' => $valuesIndexes[$attributeKey . ':' . $optionKey], 'is_percent' => $option['price_type'] == 'Percentage' ? 1 : 0, 'pricing_value' => $option['price']];
         }
     }
     return json_encode($result, true);
 }