Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Fix set and get view model method code #8494

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/guides/v2.3/extension-dev-guide/view-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ You can access the public methods for the view model class in the template:

/** @var $viewModel \OrangeCompany\Catalog\ViewModel\MyNewViewModel */

$viewModel = $block->getViewModel();
$viewModel = $block->getData('viewModel');

?>
<h1><?= $block->escapeHtml($viewModel->getTitle()); ?></h1>
Expand All @@ -78,7 +78,7 @@ The view model class is passed as an argument to the `product.info.upsell` block
<block class="Magento\Catalog\Block\Product\ProductList\Upsell" name="product.info.upsell" template="Magento_Catalog::product/list/items.phtml">
<arguments>
<argument name="type" xsi:type="string">upsell</argument>
<argument name="viewModel" xsi:type="object">Magento\Catalog\ViewModel\Product\Listing\PreparePostData</argument>
<argument name="view_model" xsi:type="object">Magento\Catalog\ViewModel\Product\Listing\PreparePostData</argument>
</arguments>
</block>
```
Expand Down Expand Up @@ -139,3 +139,5 @@ $postArray = $viewModel->getPostData(
['product' => $_item->getEntityId()]
);
```
{:.bs-callout-info}
If you use `argument name="view_model"` you can access it using `$viewModel = $block->getViewModel();` Or You can use `argument name="viewModel"` and can access `$viewModel = $block->getData('viewModel');`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IF this is true then the to changes above are mutually exclusive - only one of them should have been changed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, It depends on implementation! either we can use Getter/Setter OR we can get Data of argument!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.