validator = $validator; $this->factory = $factory; $this->initializeData(); } public function setStrategy(DataStrategyInterface $strategy): self { $this->strategy = $strategy; return $this; } public function fromWooProduct(int $productId): self { $product = wc_get_product($productId); if (!$product) throw new \InvalidArgumentException(esc_html("Product with ID {$productId} not found")); // Validate product first if ($this->validator) $this->validator->validate($product); // Use factory to get appropriate data handler $handler = $this->factory->createHandler($product); // Apply strategy to collect data $this->data = $this->strategy->collect($product, $handler); return $this; } public function withCategoryIds(array $categoryIds = null): self { if ($categoryIds !== null) $this->data['category_ids'] = $categoryIds; return $this; } public function build(): array { return $this->data; } public function reset(): self { $this->initializeData(); return $this; } private function initializeData(): void { $this->data = [ 'name' => '', 'sku' => null, 'description' => '', 'category_id' => null, 'category_ids' => [], 'primary_price' => null, 'stock' => null, 'weight' => null, 'package_weight' => null, 'photo' => null, 'photos' => [], 'preparation_days' => null, 'unit_type' => 6304, 'unit_quantity' => 1, 'is_wholesale' => false, 'variants' => [], 'product_attribute' => [], ]; } }