2019-02-18 07:30:40 +00:00
|
|
|
<?php
|
2018-07-17 13:28:34 +00:00
|
|
|
|
|
|
|
|
namespace Webkul\Attribute\Repositories;
|
2019-02-18 07:30:40 +00:00
|
|
|
|
2018-07-17 13:28:34 +00:00
|
|
|
use Webkul\Core\Eloquent\Repository;
|
|
|
|
|
|
|
|
|
|
class AttributeOptionRepository extends Repository
|
|
|
|
|
{
|
2019-02-18 07:30:40 +00:00
|
|
|
|
2018-07-17 13:28:34 +00:00
|
|
|
/**
|
|
|
|
|
* Specify Model class name
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
function model()
|
|
|
|
|
{
|
2019-02-18 07:30:40 +00:00
|
|
|
return 'Webkul\Attribute\Contracts\AttributeOption';
|
2018-07-17 13:28:34 +00:00
|
|
|
}
|
2019-02-26 06:25:00 +00:00
|
|
|
|
|
|
|
|
/**
|
2020-03-05 05:34:57 +00:00
|
|
|
* @param array $data
|
|
|
|
|
* @return \Webkul\Attribute\Contracts\AttributeOption
|
2019-02-26 06:25:00 +00:00
|
|
|
*/
|
|
|
|
|
public function create(array $data)
|
|
|
|
|
{
|
|
|
|
|
$option = parent::create($data);
|
|
|
|
|
|
|
|
|
|
$this->uploadSwatchImage($data, $option->id);
|
|
|
|
|
|
|
|
|
|
return $option;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-03-05 05:34:57 +00:00
|
|
|
* @param array $data
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @param string $attribute
|
|
|
|
|
* @return \Webkul\Attribute\Contracts\AttributeOption
|
2019-02-26 06:25:00 +00:00
|
|
|
*/
|
|
|
|
|
public function update(array $data, $id, $attribute = "id")
|
|
|
|
|
{
|
|
|
|
|
$option = parent::update($data, $id);
|
|
|
|
|
|
|
|
|
|
$this->uploadSwatchImage($data, $id);
|
|
|
|
|
|
|
|
|
|
return $option;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-03-05 05:34:57 +00:00
|
|
|
* @param array $data
|
2020-03-05 13:37:08 +00:00
|
|
|
* @param int $optionId
|
2020-03-05 05:34:57 +00:00
|
|
|
* @return void
|
2019-02-26 06:25:00 +00:00
|
|
|
*/
|
|
|
|
|
public function uploadSwatchImage($data, $optionId)
|
|
|
|
|
{
|
2020-02-19 11:39:17 +00:00
|
|
|
if (! isset($data['swatch_value']) || ! $data['swatch_value']) {
|
2019-02-26 06:25:00 +00:00
|
|
|
return;
|
2020-02-19 11:39:17 +00:00
|
|
|
}
|
2019-02-26 06:25:00 +00:00
|
|
|
|
|
|
|
|
if ($data['swatch_value'] instanceof \Illuminate\Http\UploadedFile) {
|
|
|
|
|
parent::update([
|
2020-03-04 06:32:53 +00:00
|
|
|
'swatch_value' => $data['swatch_value']->store('attribute_option'),
|
2020-02-27 08:03:03 +00:00
|
|
|
], $optionId);
|
2019-02-26 06:25:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-07-17 13:28:34 +00:00
|
|
|
}
|