6 declare(strict_types=1);
23 private $configurableOptions = [];
29 public function testQueryConfigurableProductLinks()
31 $productSku =
'configurable';
36 products(filter: {sku: {eq:
"{$productSku}"}}) {
45 ...
on PhysicalProductInterface {
93 configurable_options {
115 ...
on PhysicalProductInterface {
167 media_gallery_entries {
211 $this->assertArrayHasKey(
'products',
$response);
212 $this->assertArrayHasKey(
'items',
$response[
'products']);
213 $this->assertEquals(1, count(
$response[
'products'][
'items']));
214 $this->assertArrayHasKey(0,
$response[
'products'][
'items']);
216 $this->assertConfigurableProductOptions(
$response[
'products'][
'items'][0]);
217 $this->assertConfigurableVariants(
$response[
'products'][
'items'][0]);
224 private function assertBaseFields(
$product, $actualResponse)
228 $priceInfo = $priceInfoFactory->create(
$product);
231 $minimalPriceAmount = $finalPrice->getMinimalPrice();
232 $maximalPriceAmount = $finalPrice->getMaximalPrice();
238 [
'response_field' =>
'attribute_set_id',
'expected_value' =>
$product->getAttributeSetId()],
239 [
'response_field' =>
'created_at',
'expected_value' =>
$product->getCreatedAt()],
241 'response_field' =>
'id',
242 'expected_value' =>
$product->getData(
243 $metadataPool->getMetadata(
244 ProductInterface::class
248 [
'response_field' =>
'name',
'expected_value' =>
$product->getName()],
249 [
'response_field' =>
'sku',
'expected_value' =>
$product->getSku()],
250 [
'response_field' =>
'type_id',
'expected_value' =>
$product->getTypeId()],
251 [
'response_field' =>
'updated_at',
'expected_value' =>
$product->getUpdatedAt()],
252 [
'response_field' =>
'weight',
'expected_value' =>
$product->getWeight()],
254 'response_field' =>
'price',
255 'expected_value' => [
258 'value' => $minimalPriceAmount->getValue(),
265 'value' => $maximalPriceAmount->getValue(),
272 'value' => $regularPriceAmount->getValue(),
291 private function assertConfigurableVariants($actualResponse)
293 $this->assertNotEmpty(
294 $actualResponse[
'variants'],
295 "Precondition failed: 'variants' must not be empty" 297 foreach ($actualResponse[
'variants'] as $variantKey => $variantArray) {
298 $this->assertNotEmpty($variantArray);
299 $this->assertNotEmpty($variantArray[
'product']);
301 isset($variantArray[
'product'][
'id']),
302 'variant product elements don\'t contain id key' 304 $indexValue = $variantArray[
'product'][
'sku'];
305 unset($variantArray[
'product'][
'id']);
307 isset($variantArray[
'product'][
'categories']),
308 'variant product doesn\'t contain categories key' 316 $this->assertCount(1,
$links,
"Precondition failed, incorrect number of categories.");
320 = $actualResponse[
'variants'][$variantKey][
'product'][
'categories'][0];
321 $this->assertEquals($actualValue, [
'id' =>
$id]);
322 unset($variantArray[
'product'][
'categories']);
324 $mediaGalleryEntries =
$childProduct->getMediaGalleryEntries();
327 $mediaGalleryEntries,
328 "Precondition failed since there are incorrect number of media gallery entries" 332 $actualResponse[
'variants']
335 [
'media_gallery_entries']
340 $actualResponse[
'variants'][$variantKey][
'product'][
'media_gallery_entries'],
341 "there must be 1 record in the media gallery" 343 $mediaGalleryEntry = $mediaGalleryEntries[0];
345 $actualResponse[
'variants']
348 [
'media_gallery_entries'][0],
350 'disabled' => (
bool)$mediaGalleryEntry->isDisabled(),
351 'file' => $mediaGalleryEntry->getFile(),
352 'id' => $mediaGalleryEntry->getId(),
353 'label' => $mediaGalleryEntry->getLabel(),
354 'media_type' => $mediaGalleryEntry->getMediaType(),
355 'position' => $mediaGalleryEntry->getPosition()
358 $videoContent = $mediaGalleryEntry->getExtensionAttributes()->getVideoContent();
360 $actualResponse[
'variants']
363 [
'media_gallery_entries']
375 unset($variantArray[
'product'][
'media_gallery_entries']);
377 foreach ($variantArray[
'product'] as $key =>
$value) {
378 if ($key !==
'price') {
407 $variantArray[
'product'][
'price']
409 $configurableOptions = $this->getConfigurableOptions();
410 foreach ($variantArray[
'attributes'] as
$attribute) {
411 $hasAssertion =
false;
415 $this->assertEquals((
int)
$attribute[
'value_index'], (
int)
$value[
'value_index']);
417 $hasAssertion =
true;
422 if (!$hasAssertion) {
423 $this->fail(
'variant did not contain correct attributes');
429 private function assertConfigurableProductOptions($actualResponse)
431 $this->assertNotEmpty(
432 $actualResponse[
'configurable_options'],
433 "Precondition failed: 'configurable_options' must not be empty" 435 $configurableAttributeOptions = $this->getConfigurableOptions();
436 $configurableAttributeOption = array_shift($configurableAttributeOptions);
439 $actualResponse[
'configurable_options'][0][
'id'],
440 $configurableAttributeOption[
'id']
443 $actualResponse[
'configurable_options'][0][
'use_default'],
444 (
bool)$configurableAttributeOption[
'use_default']
447 $actualResponse[
'configurable_options'][0][
'attribute_id'],
448 $configurableAttributeOption[
'attribute_id']
451 $actualResponse[
'configurable_options'][0][
'label'],
452 $configurableAttributeOption[
'label']
455 $actualResponse[
'configurable_options'][0][
'position'],
456 $configurableAttributeOption[
'position']
459 $actualResponse[
'configurable_options'][0][
'product_id'],
460 $configurableAttributeOption[
'product_id']
463 $actualResponse[
'configurable_options'][0][
'attribute_code'],
464 $configurableAttributeOption[
'attribute_code']
466 foreach ($actualResponse[
'configurable_options'][0][
'values'] as $key =>
$value) {
469 $configurableAttributeOption[
'options'][$key][
'label']
473 $configurableAttributeOption[
'options'][$key][
'store_label']
477 $configurableAttributeOption[
'options'][$key][
'default_label']
480 $value[
'use_default_value'],
481 $configurableAttributeOption[
'options'][$key][
'use_default_value']
484 (
int)
$value[
'value_index'],
485 (
int)$configurableAttributeOption[
'options'][$key][
'value_index']
490 private function getConfigurableOptions()
492 if (!empty($this->configurableOptions)) {
493 return $this->configurableOptions;
495 $productSku =
'configurable';
498 $product = $productRepo->get($productSku);
499 $configurableAttributeOptions =
$product->getExtensionAttributes()->getConfigurableProductOptions();
500 $configurableAttributeOptionsData = [];
501 foreach ($configurableAttributeOptions as
$option) {
502 $configurableAttributeOptionsData[
$option->getId()] =
$option->getData();
503 $configurableAttributeOptionsData[
$option->getId()][
'id'] =
$option->getId();
504 $configurableAttributeOptionsData[
$option->getId()][
'attribute_code']
505 =
$option->getProductAttribute()->getAttributeCode();
506 unset($configurableAttributeOptionsData[
$option->getId()][
'values']);
508 $configurableAttributeOptionsData[
$option->getId()][
'values'][
$value->getId()] =
$value->getData();
509 $configurableAttributeOptionsData[
$option->getId()][
'values'][
$value->getId()][
'label']
514 return $this->configurableOptions = $configurableAttributeOptionsData;
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
if( $block->displayPriceExclTax()||$block->displayBothPrices())(__('Excl. Tax')) ?>"> <?php if ($block -> displayPriceWithWeeeDetails()): ?> <span class="cart-tax-total" data-mage-init=' Magento Weee Helper Data Magento Weee Helper Data title amount
assertResponseFields($actualResponse, $assertionMap)
taxRateField this edit on("click.mselect-delete", ".mselect-delete", function() { if(!confirm('<?=/*@escapeNotVerified */__( 'Do you really want to delete this tax rate?') ?>')) { return;} var that=$(this), select=that.closest('.mselect-list').prev(), rateValue=that.parent().find( 'input[type="checkbox"]').val();$( 'body').trigger( 'processStart');var ajaxOptions={ type:'POST', data:{ tax_calculation_rate_id:rateValue, form_key:$( 'input[name="form_key"]').val() }, dataType:'json', url:'<?=/*@escapeNotVerified */$block->getTaxRateDeleteUrl() ?>', success:function(result, status) { $( 'body').trigger( 'processStop');if(result.success) { that.parent().remove();select.find( 'option').each(function() { if(this.value===rateValue) { $(this).remove();} });select.trigger( 'change.hiddenSelect');} else { if(result.error_message) alert({ content:result.error_message });else alert({ content:'<?=/*@escapeNotVerified */__( 'An error occurred') ?>' });} }, error:function() { $( 'body').trigger( 'processStop');alert({ content:'<?=/*@escapeNotVerified */__( 'An error occurred') ?>' });} };$.ajax(ajaxOptions);}) .on( 'click.mselectAdd'
graphQlQuery(string $query, array $variables=[], string $operationName='', array $headers=[])