本文整理汇总了PHP中Magento\Mtf\Fixture\FixtureInterface::getConfigurableAttributesData方法的典型用法代码示例。如果您正苦于以下问题:PHP FixtureInterface::getConfigurableAttributesData方法的具体用法?PHP FixtureInterface::getConfigurableAttributesData怎么用?PHP FixtureInterface::getConfigurableAttributesData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Mtf\Fixture\FixtureInterface
的用法示例。
在下文中一共展示了FixtureInterface::getConfigurableAttributesData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOptions
/**
* Get configurable product options
*
* @param FixtureInterface|null $product [optional]
* @return array
* @throws \Exception
*/
public function getOptions(FixtureInterface $product)
{
/** @var ConfigurableProduct $product */
$attributesData = $product->hasData('configurable_attributes_data') ? $product->getConfigurableAttributesData()['attributes_data'] : [];
$listOptions = $this->getListOptions();
$result = [];
foreach ($attributesData as $option) {
$title = $option['label'];
if (!isset($listOptions[$title])) {
throw new \Exception("Can't find option: \"{$title}\"");
}
/** @var SimpleElement $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';
foreach ($optionData['options'] as $key => $value) {
$optionData['options'][$key]['price'] = $this->getOptionPrice($title, $value['title']);
}
$result[$title] = $optionData;
}
return $result;
}
示例2: prepareVariationsMatrix
/**
* Preparing matrix data
*
* @param FixtureInterface $product
* @return array
*/
protected function prepareVariationsMatrix(FixtureInterface $product)
{
/** @var ConfigurableAttributesData $configurableAttributesData */
$configurableAttributesData = $product->getDataFieldConfig('configurable_attributes_data')['source'];
$attributesData = $configurableAttributesData->getAttributesData();
$assignedProducts = $configurableAttributesData->getProducts();
$matrixData = $product->getConfigurableAttributesData()['matrix'];
$result = [];
foreach ($matrixData as $variationKey => $variation) {
// For assigned products doesn't send data about them
if (isset($assignedProducts[$variationKey])) {
continue;
}
$compositeKeys = explode(' ', $variationKey);
$keyIds = [];
$configurableAttribute = [];
foreach ($compositeKeys as $compositeKey) {
list($attributeKey, $optionKey) = explode(':', $compositeKey);
$attribute = $attributesData[$attributeKey];
$keyIds[] = $attribute['options'][$optionKey]['id'];
$configurableAttribute[] = sprintf('"%s":"%s"', $attribute['attribute_code'], $attribute['options'][$optionKey]['id']);
}
$keyIds = implode('-', $keyIds);
$variation['configurable_attribute'] = '{' . implode(',', $configurableAttribute) . '}';
$result[$keyIds] = $variation;
}
return $result;
}
示例3: getOptionsPrices
/**
* Get configurable attributes options prices
*
* @param FixtureInterface $product
* @return array
*/
public function getOptionsPrices(FixtureInterface $product)
{
/** @var ConfigurableProduct $product */
$attributesData = [];
$productVariations = [];
if ($product->hasData('configurable_attributes_data')) {
$attributesData = $product->getConfigurableAttributesData()['attributes_data'];
$productVariations = $product->getConfigurableAttributesData()['matrix'];
}
$productVariations = array_keys($productVariations);
$result = [];
foreach ($productVariations as $variation) {
$variationOptions = explode(' ', $variation);
$result[$variation]['price'] = $this->getOptionPrice($variationOptions, $attributesData);
}
return $result;
}
示例4: fillOptions
/**
* Fill in the option specified for the product
*
* @param FixtureInterface $product
* @return void
*/
public function fillOptions(FixtureInterface $product)
{
/** @var ConfigurableProduct $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']];
}
$attributesData[$attributeKey]['options'] = array_values($attributesData[$attributeKey]['options']);
}
$attributesData = array_values($attributesData);
$configurableCheckoutData = isset($checkoutData['options']['configurable_options']) ? $checkoutData['options']['configurable_options'] : [];
$checkoutOptionsData = $this->prepareCheckoutData($attributesData, $configurableCheckoutData);
$this->getCustomOptionsBlock()->fillCustomOptions($checkoutOptionsData);
parent::fillOptions($product);
}
示例5: getProductPrice
/**
* Get configurable product price
*
* @param FixtureInterface $product
* @throws \Exception
* @return int
*/
protected function getProductPrice(FixtureInterface $product)
{
$price = $product->getPrice();
if (!$this->productsIsConfigured) {
return $price;
}
if (!$product instanceof ConfigurableProduct) {
throw new \Exception("Product '{$product->getName}()' is not configurable product.");
}
$checkoutData = $product->getCheckoutData();
if ($checkoutData === null) {
return 0;
}
$attributesData = $product->getConfigurableAttributesData()['attributes_data'];
foreach ($checkoutData['options']['configurable_options'] as $option) {
$itemOption = $attributesData[$option['title']]['options'][$option['value']];
$itemPrice = $itemOption['is_percent'] == 'No' ? $itemOption['pricing_value'] : $product->getPrice() / 100 * $itemOption['pricing_value'];
$price += $itemPrice;
}
return $price;
}