/** * Verify displayed product special price on product page(front-end) equals passed from fixture * * @return string|null */ protected function verifySpecialPrice() { if (!$this->product->hasData('special_price')) { return null; } $fixtureProductSpecialPrice = $this->product->getSpecialPrice(); $fixtureProductSpecialPrice = number_format($fixtureProductSpecialPrice, 2); $formProductSpecialPrice = $this->productView->getPriceBlock()->getSpecialPrice(); if ($fixtureProductSpecialPrice == $formProductSpecialPrice) { return null; } return "Displayed product special price on product page(front-end) not equals passed from fixture. " . "Actual: {$formProductSpecialPrice}, expected: {$fixtureProductSpecialPrice}."; }
/** * Prepare new product for update. * * @param ConfigurableProduct $initialProduct * @param ConfigurableProduct $product * @param string $attributeTypeAction * @return ConfigurableProduct */ protected function prepareProduct(ConfigurableProduct $initialProduct, ConfigurableProduct $product, $attributeTypeAction) { if ($attributeTypeAction == 'deleteAll') { $this->deletedAttributes = $initialProduct->getDataFieldConfig('configurable_attributes_data')['source']->getAttributes(); return $product; } $dataProduct = $product->getData(); $dataInitialProduct = $initialProduct->getData(); $oldMatrix = []; if ($attributeTypeAction == 'deleteLast') { array_pop($dataInitialProduct['configurable_attributes_data']['attributes_data']); $attributes = $initialProduct->getDataFieldConfig('configurable_attributes_data')['source']->getAttributes(); $this->deletedAttributes[] = array_pop($attributes); } $attributesData = $dataInitialProduct['configurable_attributes_data']['attributes_data']; if ($attributeTypeAction == 'addOptions') { $oldMatrix = $dataInitialProduct['configurable_attributes_data']['matrix']; $this->addOptions($attributesData, $dataProduct['configurable_attributes_data']['attributes_data']); } else { $this->addAttributes($attributesData, $dataProduct['configurable_attributes_data']['attributes_data']); } $dataProduct['configurable_attributes_data'] = ['attributes_data' => $attributesData, 'matrix' => $oldMatrix]; if ($product->hasData('category_ids')) { $dataProduct['category_ids']['category'] = $product->getDataFieldConfig('category_ids')['source']->getCategories()[0]; } return $this->fixtureFactory->createByCode('configurableProduct', ['data' => $dataProduct]); }
/** * 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_attributes_data') ? $product->getDataFieldConfig('configurable_attributes_data')['source']->getAttributesData() : null; if ($attributesData == null) { return $result; } foreach ($checkoutData['options']['configurable_options'] as $option) { $attributeId = $attributesData[$option['title']]['attribute_id']; $optionId = $attributesData[$option['title']]['options'][$option['value']]['id']; $result['super_attribute'][$attributeId] = $optionId; } return $result; }