saveProductType($postId); $this->saveWholesale($postId); $this->savePriceChange($postId); } } private function saveProductType(int $postId): void { $action = isset($_REQUEST['sync_basalam_bulk_product_type_action']) ? sanitize_text_field(wp_unslash($_REQUEST['sync_basalam_bulk_product_type_action'])) : 'keep'; if ($action === 'keep') { return; } if ($action === 'yes') { update_post_meta($postId, self::TYPE_META_KEY, 'yes'); $unit = isset($_REQUEST['sync_basalam_bulk_product_unit']) ? sanitize_text_field(wp_unslash($_REQUEST['sync_basalam_bulk_product_unit'])) : '6304'; $quantity = isset($_REQUEST['sync_basalam_bulk_product_value']) ? sanitize_text_field(wp_unslash($_REQUEST['sync_basalam_bulk_product_value'])) : '1'; $unitValue = is_numeric($unit) ? (string) intval($unit) : '6304'; $quantityValue = (is_numeric($quantity) && intval($quantity) > 0) ? (string) intval($quantity) : '1'; update_post_meta($postId, self::UNIT_META_KEY, $unitValue); update_post_meta($postId, self::QUANTITY_META_KEY, $quantityValue); return; } update_post_meta($postId, self::TYPE_META_KEY, 'no'); delete_post_meta($postId, self::UNIT_META_KEY); delete_post_meta($postId, self::QUANTITY_META_KEY); } private function saveWholesale(int $postId): void { $action = isset($_REQUEST['sync_basalam_bulk_wholesale_action']) ? sanitize_text_field(wp_unslash($_REQUEST['sync_basalam_bulk_wholesale_action'])) : 'keep'; if ($action === 'keep') { return; } $wholesaleValue = $action === 'yes' ? 'yes' : 'no'; update_post_meta($postId, self::WHOLESALE_META_KEY, $wholesaleValue); } private function savePriceChange(int $postId): void { $action = isset($_REQUEST['sync_basalam_bulk_price_change_action']) ? sanitize_text_field(wp_unslash($_REQUEST['sync_basalam_bulk_price_change_action'])) : 'keep'; if ($action === 'keep') { return; } if ($action === 'clear') { delete_post_meta($postId, PriceChangeField::META_KEY); return; } $value = isset($_REQUEST['sync_basalam_bulk_price_change_value']) ? sanitize_text_field(wp_unslash($_REQUEST['sync_basalam_bulk_price_change_value'])) : ''; $priceChangeValue = PriceAdjustment::normalize($value); if ($priceChangeValue === null) { return; } update_post_meta($postId, PriceChangeField::META_KEY, $priceChangeValue); } }