本文整理匯總了PHP中Mtf\Fixture\FixtureInterface::getConfigurableAttributes方法的典型用法代碼示例。如果您正苦於以下問題:PHP FixtureInterface::getConfigurableAttributes方法的具體用法?PHP FixtureInterface::getConfigurableAttributes怎麽用?PHP FixtureInterface::getConfigurableAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Mtf\Fixture\FixtureInterface
的用法示例。
在下文中一共展示了FixtureInterface::getConfigurableAttributes方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getOptions
/**
* Get configurable product options
*
* @param FixtureInterface|null $product [optional]
* @return array
* @throws \Exception
*/
public function getOptions(FixtureInterface $product)
{
if ($product instanceof InjectableFixture) {
/** @var ConfigurableProductInjectable $product */
$attributesData = $product->hasData('configurable_attributes_data') ? $product->getConfigurableAttributesData()['attributes_data'] : [];
} else {
/** @var ConfigurableProduct $product */
$attributesData = $product->getConfigurableAttributes();
foreach ($attributesData as $key => $attributeData) {
$attributeData['label'] = $attributeData['label']['value'];
$attributeData['frontend_input'] = 'dropdown';
$attributesData[$key] = $attributeData;
}
}
$listOptions = $this->getListOptions();
$result = [];
foreach ($attributesData as $option) {
$title = $option['label'];
if (!isset($listOptions[$title])) {
throw new \Exception("Can't find option: \"{$title}\"");
}
/** @var Element $optionElement */
$optionElement = $listOptions[$title];
$typeMethod = preg_replace('/[^a-zA-Z]/', '', $option['frontend_input']);
$getTypeData = 'get' . ucfirst(strtolower($typeMethod)) . 'Data';
$optionData = $this->{$getTypeData}($optionElement);
$optionData['title'] = $title;
$optionData['type'] = $option['frontend_input'];
$optionData['is_require'] = $optionElement->find($this->required, Locator::SELECTOR_XPATH)->isVisible() ? 'Yes' : 'No';
$result[$title] = $optionData;
}
return $result;
}
示例2: fillOptions
/**
* Fill in the option specified for the product
*
* @param FixtureInterface $product
* @return void
*/
public function fillOptions(FixtureInterface $product)
{
if ($product instanceof InjectableFixture) {
/** @var ConfigurableProductInjectable $product */
$attributesData = $product->getConfigurableAttributesData()['attributes_data'];
$checkoutData = $product->getCheckoutData();
// Prepare attribute data
foreach ($attributesData as $attributeKey => $attribute) {
$attributesData[$attributeKey] = ['type' => $attribute['frontend_input'], 'title' => $attribute['label'], 'options' => []];
foreach ($attribute['options'] as $optionKey => $option) {
$attributesData[$attributeKey]['options'][$optionKey] = ['title' => $option['label']];
}
}
} else {
// TODO: Removed after refactoring(removed) old product fixture.
/** @var ConfigurableProduct $product */
$attributesData = $product->getConfigurableAttributes();
$checkoutData = $product->getCheckoutData();
// Prepare attributes data
foreach ($attributesData as $attributeKey => $attribute) {
$attributesData[$attributeKey] = ['type' => 'dropdown', 'title' => $attribute['label']['value']];
unset($attribute['label']);
foreach ($attribute as $optionKey => $option) {
$attributesData[$attributeKey]['options'][$optionKey] = ['title' => $option['option_label']['value']];
}
}
}
$configurableCheckoutData = isset($checkoutData['configurable_options']) ? $checkoutData['configurable_options'] : [];
$checkoutOptionsData = $this->prepareCheckoutData($attributesData, $configurableCheckoutData);
$this->getCustomOptionsBlock()->fillCustomOptions($checkoutOptionsData);
parent::fillOptions($product);
}