How to set redirect URL programmatically in magento 2?

In Magento 2, You can set redirect to any link URL by the Magento\Framework\Controller\Result\RedirectFactory Class.

How to get Product URL from product object Magento 2?

Magento 2, You can get Product URL from Product object. You can be assigned Product URL to any page in store for a redirect to Product page.

I hope you have Product Object, Get Product Object by SKU

If you want to get Only Url Key value, You can access by $product->getUrlKey() method.

You can product full URL by getProductUrl() method.

<?php 
$sku = '24-MB01';
$_product = $this->productRepository->get($sku);?>
<?php echo $_product->getProductUrl(); ?>

 

Assign customer to company Magento 2 B2B.

You can add Customer to Company Programmatically by assignCustomer( ) function from CompanyManagementInterface.

Magento\Company\Api\CompanyManagementInterface Interface will be used for assign customer to Company in Magento 2.

You need Company id and Customer id to achieve this. Continue reading “Assign customer to company Magento 2 B2B.”