1

In my Laravel 6.x project I have Product, ProductCategory models.

Product model:

class Product extends Model {

    protected $fillable = [
        'id',
        'item_number'
        'producer_item_number',...



foreach ($product_categories as $product_category) {
            // if you generate part to products

            if ($product_category->is_create_piece_part) {
                foreach ($product_category->piecePartPrefixes as $piece_part_prefix) {

                    // we make a copy of the product based on the prefixes set in the category
                    $piece_part_product = Product::find($product_id)->replicate();

                    // rewrite the item number with prefix
                    $piece_part_product->item_number = $piece_part_prefix->name . '-' . $piece_part_product->item_number;

                    // save new product
                    $piece_part_product->save();

                    // again original product
                    $product = Product::where('id', $product_id)->with(['brands', 'names', 'properties', 'variants'])->first();

                    // copy original product name
                    foreach ($product->names ?? [] as  $name) {
                        $piece_part_product->names()->create([
                            'lang_id' => $name->lang_id,
                            'name' =>  $name->name  . ' ' . $product->brands[0]->name . ' ' . $product->producer_item_number,
                        ]);
                    }

ProductCategory model:

class ProductCategory extends Model {

    protected $fillable = [
        'id',
        'code', ...

The prefix is ​​written in the part number of the part article, based on this, the prefix must be used to find the category into which the program places the part article.

For example, if the prefix is ​​"AKKO" then it should be classified in the article group "Spectacle Frame Parts - Center". And not just in the "Spectacle Frame" article group.

How would i know that solve?

Flower
  • 21
  • 4

0 Answers0