Best practices in Magento for modifying private function code in vendor

1. Create shell file: m2-patch/apply-patch.sh

#!/bin/bash

PATCH_FILES=( $(find ./m2-patch -name "*.patch") )
for file in "${PATCH_FILES[@]}"; do
echo "$file"
done

for PATCH_FILE in "${PATCH_FILES[@]}"
do
APPLIED=$(patch -p1 --dry-run < $PATCH_FILE | grep -c "ignored")

if [ $APPLIED -eq 0 ]; then
patch -p1 < $PATCH_FILE
echo "Apply success: $PATCH_FILE"
else
echo "Patch has been applied: $PATCH_FILE"
fi
done

2. Add a patch file, for example m2-patch/fix_vendor_varnish_purge.patch

#Here is the patch content

3. Then, you can use the command to update code change.

bash  m2-patch/apply-patch.sh

 



Copyright © 2013-present Magento, Inc. All rights reserved.