I am creating simple products through API call. Product is created finely and showing all attributes finely in admin part but when ever i am seeing product in frontend it is not showing any special price. It is directly displaying price.
I am using magento 2.2.4 version. Here is the API code.
$name = $prod_data['name'];
$price = $prod_data['price'];
$category_id = 229;
$qty = $prod_data['qty'];
$desc=$prod_data['description'];
$product->setName($name);
$product->setTypeId('simple');
$product->setAttributeSetId(10);
$product->setSku($sku);
$product->setWebsiteIds(array(1));
$product->setVisibility(1);
$product->setPrice($price);
//$product->setCategoryIds(array($category_id));
$product->setDescription($desc);
$product->setItemCode($prod_data['name']);
$product->setUrlKey($url_key);
$product->setStockData(array(
'use_config_manage_stock' => 0,
'manage_stock' => 1,
'is_in_stock' => 1,
'qty' => $qty
)
);
if ($product->save()) {
/** add saved file to the $product gallery */
$categoryLinkRepository = $objectManager->get('\Magento\Catalog\Api\CategoryLinkManagementInterface');
$categoryIds = array('229');
$categoryLinkRepository->assignProductToCategories($sku, $categoryIds);
$succ = 1;
$msg = "Product created successfully";
$logger->info("SKU Not Existed, So Creating new SKU for ". $prod_data['sku']);
}else{
$succ = 0;
$msg = "Unable to create product";
$logger->info("SKU Not Existed, But there is problem in creating sku ". $prod_data['sku']);
}
For updating special price i used the following code. In admin it is updating finely but final_price in index table is not changing.
if($prod_data['special_price'] > 0){
$product2 = $objectManager->get('Magento\Catalog\Model\Product')->load($pid);
$product2->setSpecialPrice($prod_data['special_price']);
$productResource = $objectManager->create('\Magento\Catalog\Model\ResourceModel\Product');
$productResource->saveAttribute($product2 , 'special_price');
$product2->save();
I tried indexer:reindex
but no use of it. Cleared cache, verified store id and everything is correct.
But still special price not showing in product detail page as well as cart page. How can i debug it.