/** * @param PropertyValue $values * @return string * @throws \Exception */ public function destroy(PropertyValue $values) { if ($values->id) { if ($values->delete()) { return json_encode(['status' => 'oke']); } } return json_encode(['status' => 'noke']); }
/** * @param $product * @param $data * @param $category * @param $group */ protected function productProperties($product, $data, $category, $group) { foreach ($data->specs as $spec) { if (!empty($spec->spec) && !empty($spec->value)) { $prop = PropertyTranslation::where('name', $spec->spec)->first(); if (!$prop) { $prop = Property::create(['type' => 'options', 'category_id' => $category->id, 'group_id' => $group->id, 'nl' => ['name' => $spec->spec], 'en' => ['name' => $spec->spec]]); $prop = $prop->id; } else { $prop = $prop->property_id; } $option = PropertyOptionTranslation::join('product_properties_options', 'product_properties_options.id', '=', 'product_properties_options_translations.option_id')->where('property_id', $prop)->where('name', $spec->value)->first(); if (!$option) { $option = PropertyOption::create(['property_id' => $prop, 'nl' => ['name' => $spec->value], 'en' => ['name' => $spec->value]]); $option = $option->id; } else { $option = $option->option_id; } $value = PropertyValue::create(['product_id' => $product->id, 'property_id' => $prop, 'option_id' => $option]); } } }