magento updating products within website scope

magento updating products within website scope

magento updating products within website scope – In this post we will show you how to magento updating products within website scope programmatically. At times in Magento you have to keep in touch with some code to refresh items automatically. This may run as an inseparable unit with needing to clump refresh items inside a specific store or site scope. As of late we should have been ready to determine which sites ought to be refreshed with the “value” quality. A few issues remained in our direction.

The first being that the extent of all value characteristics (value, exceptional value, unique from date, uncommon to date, and so on.) were not overseen in the ‘Deal with Attributes’ segment in the Magento backend as one would accept. Rather, they can be found in System > Configuration > Catalog > Catalog > Price > Price Scope. You can either pick “Worldwide” (which means over all sites) or “Site” (for site particular valuing, as we are needing.) We can’t pick “Store” scope.

We can now utilize the accompanying code in a capacity to conform the cost programatically for particular site codes. You’ll additionally see beneath that we set the store to the administrator store, something I battled with. We should set the administrator store in the first place, and after that set the extent of the particular item later ($product->setStoreId($store->getStoreId());) You may likewise see lines this way: $product->setSpecialToDateIsFormated(true);. We require these to go in a date as a string and reveal to Magento that it is undoubtedly a date and ought to be put away that way.

public function setUpdateSpecialPriceByWebsite($get_price, $get_specialFromDate, $get_specialToDate, $get_sku, $get_website)
{
	try {
		$get_specialFromDate = date('Y-m-d', strtotime($get_specialFromDate));
		$get_specialToDate = date('Y-m-d', strtotime($get_specialToDate));
		$get_website = Mage::app()->getWebsite($get_website);
		Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
		$get_store = $get_website->getDefaultStore();
		$products = Mage::getModel('catalog/product');
		$productId = $products->getIdBySku($get_sku);
		$products->load($productId);
		if ($products && $products->getId()) 
		{
			// set value for product
			$products->setStoreId($get_store->getStoreId());
			$products->setSpecialFromDate($get_specialFromDate);
			$products->setSpecialFromDateIsFormated(true);
			$products->setSpecialToDate($get_specialToDate);
			$products->setSpecialToDateIsFormated(true);
			$products->setSpecialPrice(strval($get_price));
			$products->save();
			return true;
		}
	} 
	catch (Exception $exception) 
	{
		// exception error 
		Mage::logException($exception);
		return false;
	}

	return true;
}

You also like Get Order Details using Order and customer registration programmatically and Magento2 admin login user detail

Leave a Comment

Your email address will not be published. Required fields are marked *

4  +  4  =  

We accept paid advance and paid guest Posting on our Site : Contact US