コード例 #1
0
ファイル: Simple.php プロジェクト: jigoshop/Jigoshop2
 /**
  * Removes variation from database.
  *
  * @param $variation Product\Variable\Variation Variation to remove.
  */
 public function removeVariation($variation)
 {
     if ($variation) {
         unset($this->objects[$variation->getId()]);
         $this->service->removeVariation($variation);
     }
 }
コード例 #2
0
ファイル: Variable.php プロジェクト: jigoshop/Jigoshop2
 public function ajaxRemoveVariation()
 {
     try {
         if (!isset($_POST['product_id']) || empty($_POST['product_id'])) {
             throw new Exception(__('Product was not specified.', 'jigoshop'));
         }
         if (!is_numeric($_POST['product_id'])) {
             throw new Exception(__('Invalid product ID.', 'jigoshop'));
         }
         if (!isset($_POST['variation_id']) || empty($_POST['variation_id'])) {
             throw new Exception(__('Variation was not specified.', 'jigoshop'));
         }
         if (!is_numeric($_POST['variation_id'])) {
             throw new Exception(__('Invalid variation ID.', 'jigoshop'));
         }
         $product = $this->productService->find((int) $_POST['product_id']);
         if (!$product->getId()) {
             throw new Exception(__('Product does not exists.', 'jigoshop'));
         }
         if (!$product instanceof Product\Variable) {
             throw new Exception(__('Product is not variable - unable to add variation.', 'jigoshop'));
         }
         $variation = $product->removeVariation((int) $_POST['variation_id']);
         $this->service->removeVariation($variation);
         $this->productService->save($product);
         echo json_encode(array('success' => true));
     } catch (Exception $e) {
         echo json_encode(array('success' => false, 'error' => $e->getMessage()));
     }
     exit;
 }