api changes
This commit is contained in:
parent
3cac6fc745
commit
4ec82687cd
|
|
@ -45,9 +45,10 @@ class ProductController extends Controller
|
|||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return new ProductResource(
|
||||
$this->productRepository->findOrFail($id)
|
||||
);
|
||||
$product = $this->productRepository->findOrFail($id);
|
||||
$options = $this->productRepository->findOrFail($id)->getTypeInstance()->getProductOptions($product);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -100,4 +100,34 @@ class BundleOption extends AbstractProduct
|
|||
|
||||
return $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formed data from bundle option product
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProductOptions($product)
|
||||
{
|
||||
$products = [];
|
||||
|
||||
$products[$product->id] = [
|
||||
'id' => $product->id,
|
||||
'qty' => $product->qty,
|
||||
'price' => $product->product->getTypeInstance()->getProductPrices(),
|
||||
'name' => $product->product->name,
|
||||
'product_id' => $product->product_id,
|
||||
'is_default' => $product->is_default,
|
||||
'sort_order' => $product->sort_order,
|
||||
];
|
||||
|
||||
usort ($products, function($a, $b) {
|
||||
if ($a['sort_order'] == $b['sort_order']) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ($a['sort_order'] < $b['sort_order']) ? -1 : 1;
|
||||
});
|
||||
|
||||
return $products;
|
||||
}
|
||||
}
|
||||
|
|
@ -113,6 +113,11 @@ abstract class AbstractType
|
|||
*/
|
||||
protected $isChildrenCalculated = false;
|
||||
|
||||
/**
|
||||
* get product options
|
||||
*/
|
||||
protected $getProductOptions = [];
|
||||
|
||||
/**
|
||||
* Create a new product type instance.
|
||||
*
|
||||
|
|
@ -694,4 +699,10 @@ abstract class AbstractType
|
|||
|
||||
$item->save();
|
||||
}
|
||||
|
||||
//get product options
|
||||
public function getProductOptions()
|
||||
{
|
||||
return $this->getProductOptions;
|
||||
}
|
||||
}
|
||||
|
|
@ -69,6 +69,11 @@ class Bundle extends AbstractType
|
|||
*/
|
||||
protected $isChildrenCalculated = true;
|
||||
|
||||
/**
|
||||
* getProductOptions
|
||||
*/
|
||||
protected $getProductOptions = [];
|
||||
|
||||
/**
|
||||
* Create a new product type instance.
|
||||
*
|
||||
|
|
@ -633,4 +638,14 @@ class Bundle extends AbstractType
|
|||
|
||||
$item->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* get product options
|
||||
*/
|
||||
public function getProductOptions($product = "")
|
||||
{
|
||||
$bundleOption = app('Webkul\Product\Helpers\BundleOption');
|
||||
$options = $bundleOption->getProductOptions($product);
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
|
@ -49,6 +49,11 @@ class Configurable extends AbstractType
|
|||
*/
|
||||
protected $hasVariants = true;
|
||||
|
||||
/**
|
||||
* get product options
|
||||
*/
|
||||
protected $getProductOptions = [];
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return \Webkul\Product\Contracts\Product
|
||||
|
|
@ -546,4 +551,12 @@ class Configurable extends AbstractType
|
|||
|
||||
$item->save();
|
||||
}
|
||||
|
||||
//product options
|
||||
public function getProductOptions($product = "")
|
||||
{
|
||||
$configurableOption = app('Webkul\Product\Helpers\ConfigurableOption');
|
||||
$options = $configurableOption->getConfigurationConfig($product);
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
|
@ -55,6 +55,11 @@ class Downloadable extends AbstractType
|
|||
*/
|
||||
protected $isStockable = false;
|
||||
|
||||
/**
|
||||
* getProductOptions
|
||||
*/
|
||||
protected $getProductOptions = [];
|
||||
|
||||
/**
|
||||
* Create a new product type instance.
|
||||
*
|
||||
|
|
@ -252,4 +257,16 @@ class Downloadable extends AbstractType
|
|||
|
||||
$item->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* get product options
|
||||
*/
|
||||
// public function getProductOptions($product)
|
||||
// {
|
||||
// $configurableOption = app('Webkul\Product\Helpers\DownloadableOption');
|
||||
// dd($configurableOption);
|
||||
// $options = $configurableOption->getDownloadableConfig($product);
|
||||
// dd($options);
|
||||
// return $options;
|
||||
// }
|
||||
}
|
||||
Loading…
Reference in New Issue