Attachments.php
1 week ago
Attributes.php
1 week ago
DownloadableFiles.php
1 week ago
Linked.php
1 week ago
Meta.php
1 week ago
Post.php
1 week ago
Stock.php
1 week ago
Synchronizer.php
1 week ago
SynchronizerForMeta.php
1 week ago
Taxonomies.php
1 week ago
VariationAttachments.php
1 week ago
VariationMeta.php
1 week ago
VariationTaxonomies.php
1 week ago
Variations.php
1 week ago
DownloadableFiles.php
45 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Synchronization\Component; |
| 4 | |
| 5 | use WCML_Downloadable_Products; |
| 6 | |
| 7 | class DownloadableFiles extends SynchronizerForMeta { |
| 8 | |
| 9 | public function run( $product, $translationsIds, $translationsLanguages ) { |
| 10 | $settingsFactory = wpml_load_core_tm()->settings_factory(); |
| 11 | $postmetaFieldSetting = $settingsFactory->post_meta_setting( '_downloadable_files' ); |
| 12 | $postmetaFieldStatus = $postmetaFieldSetting->status(); |
| 13 | if ( WPML_IGNORE_CUSTOM_FIELD === $postmetaFieldStatus ) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | $this->syncFiles( $product->ID, $translationsIds ); |
| 18 | } |
| 19 | |
| 20 | public function syncFiles( $productId, $translationsIds ) { |
| 21 | $generalProductSync = $this->woocommerceWpml->settings[ WCML_Downloadable_Products::SYNC_MODE_SETTING_KEY ]; |
| 22 | $customProductSync = get_post_meta( $productId, WCML_Downloadable_Products::SYNC_MODE_META, true ); |
| 23 | |
| 24 | if ( $this->isSyncOn( $generalProductSync, $customProductSync ) ) { |
| 25 | $this->synchronizeMeta( $productId, $translationsIds, WCML_Downloadable_Products::DOWNLOADABLE_FILES_META ); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | private function isSyncOn( $generalProductSync, $customProductSync ): bool { |
| 30 | if ( WCML_Downloadable_Products::SYNC_MODE_META_AUTO === $customProductSync ) { |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | if ( WCML_Downloadable_Products::SYNC_MODE_META_SELF === $customProductSync ) { |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | if ( WCML_Downloadable_Products::SYNC_MODE_SETTING_AUTO === $generalProductSync ) { |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | return false; |
| 43 | } |
| 44 | } |
| 45 |