Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductInMultipleStoresTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 
14 {
15 
22  public function testProductFromSpecificAndDefaultStore()
23  {
24  $productSku = 'simple';
25 
26  $query = <<<QUERY
27 {
28  products(filter: {sku: {eq: "{$productSku}"}})
29  {
30  items {
31  attribute_set_id
32  created_at
33  id
34  name
35  price {
36  minimalPrice {
37  amount {
38  value
39  currency
40  }
41  }
42  }
43  sku
44  type_id
45  updated_at
46  ... on PhysicalProductInterface {
47  weight
48  }
49  }
50  }
51 }
52 QUERY;
53 
55  $store = ObjectManager::getInstance()->get(\Magento\Store\Model\Store::class);
56  $storeCodeFromFixture = 'fixture_second_store';
57  $storeId = $store->load($storeCodeFromFixture)->getStoreId();
58 
60  $product = ObjectManager::getInstance()->get(\Magento\Catalog\Model\Product::class);
61  $product->load($product->getIdBySku($productSku));
62 
63  //use case for custom store
64  $productNameInFixtureStore = 'Product\'s Name in Fixture Store';
65  $product->setName($productNameInFixtureStore)->setStoreId($storeId)->save();
66  $headerMap = ['Store' => $storeCodeFromFixture];
67  $response = $this->graphQlQuery($query, [], '', $headerMap);
68  $this->assertEquals(
69  $productNameInFixtureStore,
70  $response['products']['items'][0]['name'],
71  'Product name in fixture store is invalid.'
72  );
73 
74  //use case for default storeCode
75  $nameInDefaultStore = 'Simple Product';
76  $headerMapDefault = ['Store' => 'default'];
77  $response = $this->graphQlQuery($query, [], '', $headerMapDefault);
78  $this->assertEquals(
79  $nameInDefaultStore,
80  $response['products']['items'][0]['name'],
81  'Product name in default store is invalid.'
82  );
83 
84  //use case for empty storeCode
85  $headerMapEmpty = ['Store' => ''];
86  $response = $this->graphQlQuery($query, [], '', $headerMapEmpty);
87  $this->assertEquals(
88  $nameInDefaultStore,
89  $response['products']['items'][0]['name'],
90  'Product in the default store should be returned'
91  );
92 
93  // use case for invalid storeCode
94  $nonExistingStoreCode = "non_existent_store";
95  $headerMapInvalidStoreCode = ['Store' => $nonExistingStoreCode];
96  $this->expectException(\Exception::class);
97  $this->expectExceptionMessage('Store code non_existent_store does not exist');
98  $this->graphQlQuery($query, [], '', $headerMapInvalidStoreCode);
99  }
100 }
$response
Definition: 404.php:11
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9
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
Definition: unit.phtml:68
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'
Definition: edit.phtml:164
graphQlQuery(string $query, array $variables=[], string $operationName='', array $headers=[])