コード例 #1
0
 public function destroy(AttributeOption $attributeOption)
 {
     // wrapped in transaction because of eloquent event listeners
     DB::transaction(function () use($attributeOption) {
         $this->attributeManager->getAttributeOptionRepository()->delete($attributeOption);
     });
     return $this->success('delete');
 }
コード例 #2
0
 public function destroy(AttributeGroup $attributeGroup)
 {
     $this->attributeManager->getAttributeGroupRepository()->delete($attributeGroup);
     // recalculate stocks if necessary
     /*if ($attributeGroup->product->hasAttributeGroupStock() OR $attributeGroup->product->stocks()->count() > 1) {
           app(StockRepository::class)->recalculate($attributeGroup->product);
       }*/
     return $this->success('delete');
 }
コード例 #3
0
 public function show(Product $product, VariantManager $variantManager, AttributeManager $attributeManager)
 {
     if (!$product->isActive()) {
         abort(404);
     }
     $seller = $product->getSeller();
     $attributes = $attributeManager->getAttributesForProduct($product);
     $variants = $variantManager->getVariantRepository()->whereProduct($product)->with('attributeOptions')->findAll();
     // for stock calculation
     $product->setRelation('variants', $variants);
     return view('product::__front.products.show', compact('seller', 'product', 'attributes', 'variants'));
 }
コード例 #4
0
 public function assign(Request $request, Product $product, VariantManager $variantManager)
 {
     // Filter attributes to only authorized ones.
     $attributeOptions = $this->attributeManager->getAttributeOptionRepository()->whereHas('attributeGroup', function ($query) use($request) {
         $query->where([['seller_type', '=', $this->shop()->getMorphClass()], ['seller_id', '=', $this->shop()->getKey()]]);
     })->whereIn('id', $request->input('attributes', []))->get();
     return DB::transaction(function () use($attributeOptions, $product, $variantManager) {
         // First we need to sync to product itself.
         // If there's no attribues to add simply clean up and exit.
         $product->setAttributeOptions($attributeOptions, true);
         if ($attributeOptions->isEmpty()) {
             $variantManager->cleanUpVariants($product);
             return $this->redirectBack();
         }
         // Otherwise we need to work out the cartesian product
         // delete and create variants as necessary
         $variantManager->refreshVariants($product);
         return $this->success('edit');
     });
 }