/** * @constructor * @param FixtureInterface $product */ public function __construct(FixtureInterface $product) { parent::__construct($product); /** @var BundleProduct $product */ $bundleSelection = $product->getBundleSelections(); $checkoutData = $product->getCheckoutData(); $checkoutBundleOptions = isset($checkoutData['options']['bundle_options']) ? $checkoutData['options']['bundle_options'] : []; foreach ($checkoutBundleOptions as $checkoutOptionKey => $checkoutOption) { // Find option and value keys $attributeKey = null; $optionKey = null; foreach ($bundleSelection['bundle_options'] as $key => $option) { if ($option['title'] == $checkoutOption['title']) { $attributeKey = $key; foreach ($option['assigned_products'] as $valueKey => $value) { if (false !== strpos($value['search_data']['name'], $checkoutOption['value']['name'])) { $optionKey = $valueKey; } } } } // Prepare option data $bundleSelectionAttribute = $bundleSelection['products'][$attributeKey]; $bundleOptions = $bundleSelection['bundle_options'][$attributeKey]; $value = $bundleSelectionAttribute[$optionKey]->getName(); $qty = $bundleOptions['assigned_products'][$optionKey]['data']['selection_qty']; $price = $product->getPriceType() == 'Dynamic' ? number_format($bundleSelectionAttribute[$optionKey]->getPrice(), 2) : number_format($bundleOptions['assigned_products'][$optionKey]['data']['selection_price_value'], 2); $optionData = ['title' => $checkoutOption['title'], 'value' => "{$qty} x {$value} {$price}"]; $checkoutBundleOptions[$checkoutOptionKey] = $optionData; } $this->data['options'] += $checkoutBundleOptions; }
/** * @constructor * @param FixtureInterface $product */ public function __construct(FixtureInterface $product) { parent::__construct($product); /** @var DownloadableProduct $product */ $checkoutDownloadableOptions = []; $checkoutData = $product->getCheckoutData(); $downloadableOptions = $product->getDownloadableLinks(); foreach ($checkoutData['options']['links'] as $link) { $keyLink = str_replace('link_', '', $link['label']); $checkoutDownloadableOptions[] = ['title' => 'Links', 'value' => $downloadableOptions['downloadable']['link'][$keyLink]['title']]; } $this->data['options'] += $checkoutDownloadableOptions; }
/** * @constructor * @param FixtureInterface $product */ public function __construct(FixtureInterface $product) { parent::__construct($product); /** @var ConfigurableProduct $product */ $checkoutData = $product->getCheckoutData(); $cartItem = isset($checkoutData['cartItem']) ? $checkoutData['cartItem'] : []; $attributesData = $product->getConfigurableAttributesData()['attributes_data']; $checkoutConfigurableOptions = isset($checkoutData['options']['configurable_options']) ? $checkoutData['options']['configurable_options'] : []; foreach ($checkoutConfigurableOptions as $key => $checkoutConfigurableOption) { $attribute = $checkoutConfigurableOption['title']; $option = $checkoutConfigurableOption['value']; $checkoutConfigurableOptions[$key] = ['title' => isset($attributesData[$attribute]['label']) ? $attributesData[$attribute]['label'] : $attribute, 'value' => isset($attributesData[$attribute]['options'][$option]['label']) ? $attributesData[$attribute]['options'][$option]['label'] : $option]; } $cartItem['options'] = isset($cartItem['options']) ? $cartItem['options'] + $checkoutConfigurableOptions : $checkoutConfigurableOptions; $this->data = $cartItem; }
/** * @constructor * @param FixtureInterface $product */ public function __construct(FixtureInterface $product) { parent::__construct($product); /** @var GroupedProductInjectable $product */ $associatedProducts = []; $cartItem = []; foreach ($product->getAssociated()['products'] as $key => $product) { $key = 'product_key_' . $key; $associatedProducts[$key] = $product; } // Replace key in checkout data foreach ($this->data as $fieldName => $fieldValues) { foreach ($fieldValues as $key => $value) { $product = $associatedProducts[$key]; $cartItem[$fieldName][$product->getSku()] = $value; } } // Add empty "options" field foreach ($associatedProducts as $product) { $cartItem['options'][$product->getSku()] = []; } $this->data = array_replace($this->data, $cartItem); }