src/Models/Database/Product.php
public function getProductVariationJsonData()
    {
        $jsonData = [];
        $lists = ProductAttributeIntegerValue::whereIn(
            'product_id',
            $this->productVariations->pluck('variation_id')
        )->get();
        
        foreach ($lists as $list) {
            $variationModel = self::find($list->product_id);
            if (array_has($jsonData, $list->product_id)) {
                $data = array_get($jsonData, $list->product_id);
                $data[$list->attribute_id] = [
                    $list->value => ['qty' => $variationModel->qty, 'price' => $variationModel->price]
                ];
                $jsonData[$list->product_id] = $data;
            } else {
                $jsonData[$list->product_id] = [$list->attribute_id => [
                    $list->value => ['qty' => $variationModel->qty, 'price' => $variationModel->price]]
                ];
            }
        }
        return $jsonData;
    }
public function getProductVariationJsonData()
    {
        $jsonData = [];
        $lists = ProductAttributeIntegerValue::whereIn(
            'product_id',
            $this->productVariations->pluck('variation_id')
        )->get();
        
        foreach ($lists as $list) {
            $variationModel = self::find($list->product_id);
            if (array_has($jsonData, $list->product_id)) {
                $data = array_get($jsonData, $list->product_id);
                $data[$list->attribute_id] = [
                    $list->value => ['qty' => $variationModel->qty, 'price' => $variationModel->price]
                ];
                $jsonData[$list->product_id] = $data;
            } else {
                $jsonData[$list->product_id] = [$list->attribute_id => [
                    $list->value => ['qty' => $variationModel->qty, 'price' => $variationModel->price]]
                ];
            }
        }
        return $jsonData;
    }
public function getProductVariationJsonData ( ) { $ jsonData = [ ] ; $ lists = ProductAttributeIntegerValue :: whereIn ( 'product_id' , $ this -> productVariations -> pluck ( 'variation_id' ) ) -> get ( ) ; foreach ( $ lists as $ list ) { $ variationModel = self :: find ( $ list -> product_id ) ; if ( array_has ( $ jsonData , $ list -> product_id ) ) { $ data = array_get ( $ jsonData , $ list -> product_id ) ; $ data [ $ list -> attribute_id ] = [ $ list -> value => [ 'qty' => $ variationModel -> qty , 'price' => $ variationModel -> price ] ] ; $ jsonData [ $ list -> product_id ] = $ data ; } else { $ jsonData [ $ list -> product_id ] = [ $ list -> attribute_id => [ $ list -> value => [ 'qty' => $ variationModel -> qty , 'price' => $ variationModel -> price ] ] ] ; } } return $ jsonData ; }
Get the Product Variation Product Json Data
@return array $jsonData
Get the Product Variation Product Json Data