Fixing Magento Issue with Downloadable Product Import

Magento, as an e-commerce platform, provides extensive capabilities for managing products, including features for importing and exporting products. However, there are instances where the process of importing Downloadable products may lead to errors in attribute management. In this article, we will discuss a patch for the Downloadable.php file that addresses the issue of saving the redundant 'links_purchased_separately' attribute. Additionally, we will talk about a temporary solution for the problem where the "Links can be purchased separately" option always remains enabled after importing Downloadable products due to a Magento bug.

Step 1: Describing the Problem

After importing Downloadable products into Magento, an issue may arise with the "Links can be purchased separately" option. Due to a Magento bug, this option will always be enabled, even if the corresponding attributes ('links_purchased_separately' or 'purchased_separately') are absent in the input data. This can lead to undesirable consequences, such as incorrect display of product availability status.

Step 2: Applying the Patch

The patch provided below for the Downloadable.php file addresses the problem of saving the 'links_purchased_separately' attribute. The patch makes changes to the prepareAttributesWithDefaultValueForSave method to avoid saving the attribute if the corresponding data is missing in the input.

--- /Model/Import/Product/Type/Downloadable.php	2022-03-08 00:52:02.000000000 +0200
+++ /Model/Import/Product/Type/Downloadable.php	2023-11-29 16:38:53.060641590 +0200
@@ -448,6 +448,9 @@
 {
     $resultAttrs = parent::prepareAttributesWithDefaultValueForSave($rowData, $withDefaultValue);
     $resultAttrs = array_merge($resultAttrs, $this->addAdditionalAttributes($rowData));
+    if (!in_array('links_purchased_separately', $rowData) && !in_array('purchased_separately', $rowData)) {
+        unset($resultAttrs['links_purchased_separately']);
+    }
     return $resultAttrs;
}

Conclusion

Using Magento to manage your store can be reliable and efficient, but occasional situations require intervention. The provided patch and temporary solution will help you address the problem of saving the 'links_purchased_separately' attribute and the "Links can be purchased separately" option after importing Downloadable products. Remember the importance of regularly updating your platform and testing changes before applying them to the live site.