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
Stock.php
42 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Synchronization\Component; |
| 4 | |
| 5 | class Stock extends SynchronizerForMeta { |
| 6 | |
| 7 | const STOCK_META_KEY = '_stock'; |
| 8 | const STOCK_STATUS_META_KEY = '_stock_status'; |
| 9 | |
| 10 | public function run( $product, $translationsIds, $translationsLanguages ) { |
| 11 | $productObject = wc_get_product( $product->ID ); |
| 12 | $productIdManagingStock = $productObject->get_stock_managed_by_id(); |
| 13 | |
| 14 | $translationsManagingStock = $translationsIds; |
| 15 | if ( $productIdManagingStock !== $product->ID ) { |
| 16 | $translationsManagingStock = $this->elementTranslations->get_element_translations( $productIdManagingStock, false, false ); |
| 17 | } |
| 18 | |
| 19 | $this->synchronizeMeta( $productIdManagingStock, $translationsManagingStock, self::STOCK_META_KEY ); |
| 20 | $this->synchronizeMeta( $product->ID, $translationsIds, self::STOCK_STATUS_META_KEY ); |
| 21 | |
| 22 | if ( $productIdManagingStock !== $product->ID ) { |
| 23 | $this->deleteCache( $productIdManagingStock ); |
| 24 | foreach ( $translationsManagingStock as $translationManagingStock ) { |
| 25 | $this->deleteCache( $translationManagingStock ); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | delete_transient( 'wc_low_stock_count' ); |
| 30 | delete_transient( 'wc_outofstock_count' ); |
| 31 | } |
| 32 | |
| 33 | private function deleteCache( $productId ) { |
| 34 | wp_cache_delete( $productId, 'post_meta' ); |
| 35 | wp_cache_delete( 'product-' . $productId, 'products' ); |
| 36 | delete_transient( 'wc_product_children_' . $productId ); |
| 37 | $wcml_data_store = wcml_product_data_store_cpt(); |
| 38 | $wcml_data_store->update_lookup_table_data( $productId ); |
| 39 | } |
| 40 | |
| 41 | } |
| 42 |