categoryPreparationService = $categoryPreparationService ?: syncBasalamContainer()->get(CategoryPreparationService::class); $this->categoryService = $categoryService ?: new CategoryService(); } /** * @return int The (possibly capped) preparation days. * @throws NonRetryableException When the product must be skipped. */ public function enforce(int $preparationDays, $product): int { $categoryId = $this->resolveCategoryId($product); if (empty($categoryId)) return $preparationDays; $maxPreparation = $this->categoryPreparationService->getMaxPreparationDays($categoryId); if ($maxPreparation === null) return $preparationDays; if ($preparationDays <= $maxPreparation) return $preparationDays; $shouldCap = syncBasalamSettings()->getSettings(SettingsConfig::CAP_PREPARATION_TO_CATEGORY_MAX) !== 'no'; if ($shouldCap) { return $maxPreparation; } $message = sprintf( 'زمان آماده‌سازی محصول (%d روز) بیشتر از حداکثر مجاز دسته‌بندی باسلام (%d روز) است و طبق تنظیمات، محصول ارسال نشد.', $preparationDays, $maxPreparation ); throw NonRetryableException::invalidData(esc_html($message)); } private function resolveCategoryId($product): ?int { if (!is_object($product)) return null; $categoryId = $this->categoryService->getPrimaryCategoryId($product); return $categoryId ?: null; } }