Vue.Js Scroll to bottom of Page


Vue.Js Scroll to bottom of Page : We can use .scrollTop to scroll to bottom of page. Let us understand how we can do it.


Vue.Js Scroll to bottom of Page Example

You can scroll to bottom of page in vue.js simply as below-

Vue.Js Scroll to bottom of Page Example:

document.body.scrollTop = document.body.scrollHeight;

This will scroll to the bottom of the page.

Vue.js scroll to bottom of div


Vue.js scroll to bottom of div : We can use .scrollTop to scroll to bottom of div. Let us understand how we can do it.


Vue.js scroll to bottom of div Example

You can scroll to bottom of any div in vue.js simply as below-

Vue.js scroll to bottom of div Example:

var divContainer = this.$el.querySelector("#divId");
divContainer.scrollTop = divContainer.scrollHeight;

Vue.js enable disable input field


Vue.js enable disable input field It is very simple to enable disable form input field. Here in this article we are going to create one input field and submit button to implement this functionality.


Vue.js enable disable input field Example

Here is simply example of enable/disable input form field-

Enable/Disable Vue.Js Example:

                            





 

Try it »

If you run the above example it will produce output something like this-

Vue.js enable disable input field

Vue.js Get String Length


Vue.js Get String Length– We can use native .length property to get the string length in Vue.Js.


Vue.js Get String Length Example

Here is an example to get string length in Vue.js –

Vue.js Get String Length Example:

myvariable.length;

Magento 2 Collection get last Item


Magento 2 Collection get last Item: There are many ways to get last item from Magento collection. Here in this article we are going to explain one of the method to get last item from collection using order by and setPageSize.


Magento 2 Collection get last Item Example

You can add order by desc and setPageSize to get the last item from the collection. Here is an example to get last item-

Magento 2 Collection get last Item Example:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();   
$firstItem = $objectManager->create('Mypackage\MyModule\Model\MyData')
                    ->getCollection()
                    ->setOrder('id DESC')
                    ->setPageSize('1');

The above example will give last item so on the same way you can get the first item by just adding ->setOrder(‘id ASC’)

Magento 2 get Store Details


Magento 2 get Store Details– It is very simple to get the store details in Magento 2. There are two ways to get the store information in Magento 2 – 1. Using dependency Injection, 2. Using Object Manager. Here in this post we are going to get the – store id, store code, store name, store website, store url etc.


Magento 2 get Store Details | Id, Name ,Code

Let us get the following details from current store in Magento2-

Get Information From Current Store

We need following details about current store while working with magento.

  1. Store Name
  2. Store Id
  3. Store Code
  4. Store Website Id
  5. Store Url

We can get the above information using object manager. Here is simple Example.

Get Store Information Example:

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();        
 
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');

$storeName = storeManager->getStore()->getName();

$storeId = $storeManager->getStore()->getStoreId();

$websiteId = $storeManager->getStore()->getWebsiteId();

$storeCode = $storeManager->getStore()->getCode();

$storeUrl = $storeManager->getStore()->getStoreUrl();

So on the same way you can get other details of the current store.

Magento 2 get current Category Name


Magento 2 get current Category Name We can get current Category name by category object. Using object manager we can get current category details such as Category Name, Id etc.


How to get current Category Name,Id In Magento 2?

We can get currenct category details from registry simply as below-

Get Current category Name, Id Example:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');
    echo $category->getName();
    echo "
"; echo $category->getId();

Magento 2 Get Current Currency Symbol


Magento 2 Get Current Currency Symbol & Currency Code– We can get currency symbol using currency code so we first need to get current currency code from currency object then get currency symbol. Here in this tutorial, we are going to explain how you can get .


Magento 2 Get Current Currency Symbol & Currency Code Example

You can get Currenct Currency Code and Symbol simply as below-

How to get currency Symbol in Magento 2?

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterfa‌​ce'); 
$currencyCode = $storeManager->getStore()->getCurrentCurrencyCode(); 
$currency = $objectManager->create('Magento\Directory\Model\CurrencyFact‌​ory')->create()->loa‌​d($currencyCode); 
echo $currencySymbol = $currency->getCurrencySymbol(); 

So using above example we can get currency code and currency symbol.

Magento 2 get child categories


Magento 2 get child categories of specific category – We can get all sub categories of the specific category in Magento2. Sub categories can be get from parent category. Here in this article how we can get child categories by parent category id,we will also cover how to get current category’s child/sub categories in Magento 2.


Magento 2 get child categories Example

You can get child categories simply as below. Let us go one by one-

Get Sub Categories By Id

You can get sub categories simply as below-

Get Sub Categories Example:

$categoryId = 5;
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $_objectManager->create('Magento\Catalog\Model\Category')->load($categoryId);
foreach ($category->getChildCategories() as $child) {
    echo $child->getId();
}

Get Child Categories From Current Category

You can get child categories from current category simply as below-

Get Sub Categories Example:

 /* $block \Magento\Catalog\Block\Category\View */
foreach ($block->getCurrentCategory()->getChildCategories() as $child) {
    echo $child->getId();
}

So the above example will give you the child categories of current category.