Ejemplo n.º 1
0
 public function action_artwork_uploaded()
 {
     $artwork_table = '';
     if (\Input::post()) {
         $item = \Cart::item(\Input::post('cart_uid'));
         $artwork = \Order\Model_Artwork::find_one_by_file_id(\Input::post('file_id'));
         if ($item && $artwork) {
             $artwork_table .= '<tr>';
             $artwork_table .= '<td>';
             $artwork_table .= $artwork->type;
             $artwork_table .= '</td>';
             $artwork_table .= '<td>';
             $artwork_table .= $artwork->name;
             $artwork_table .= '</td>';
             $artwork_table .= '<td>';
             $artwork_table .= \Form::open(array('action' => \Uri::create('order/cart/cart_update'), 'method' => 'post', 'class' => 'edit_cart_form'));
             $artwork_table .= \Form::select("artwork_quantity[{$artwork->id}]", $artwork->quantity, \Helper::numbers_array(1, $item->get('quantity')), array('class' => 'select_init w_60'));
             $artwork_table .= \Form::close();
             $artwork_table .= '</td>';
             $artwork_table .= '<td>';
             $artwork_table .= '<a href="' . \Uri::create('order/cart/delete_artwork/' . $artwork->file_id) . '" class="remove_item"></a>';
             $artwork_table .= '</td>';
             $artwork_table .= '</tr>';
         }
     }
     echo $artwork_table;
 }
Ejemplo n.º 2
0
 public function delete_artwork($file_id = null, $return = false)
 {
     $out = array();
     $storage = new \StorageAPIs(\Session::get('ysi.sHost'), \Session::get('ysi.sApp'), \Session::get('ysi.sTr'));
     if (strlen(\Session::get('ysi.sToken')) == 0 || strlen($file_id) == 0) {
         $out = array('errorcode' => '', 'errormessage' => 'Internal server error, please try again.');
     } else {
         $storage->setAuthToken(\Session::get('ysi.sToken'));
         $responseObject = $storage->deleteFile($file_id);
         $current = $responseObject->getErrorStatus();
         if (!empty($current)) {
             $out = array('errorcode' => '', 'errormessage' => 'Internal server error, please try again.');
             //echo " Error code: ".$current->getCode(). "\n";
             //echo " Error message: ".$current->getMessage()."\n";
         } else {
             // Delete artwork from db
             if ($artwork = \Order\Model_Artwork::find_one_by_file_id($file_id)) {
                 $unique_id = $artwork->unique_id;
                 $order_id = $artwork->order_id;
                 if ($artwork->delete()) {
                     // Reorder artworks
                     if ($artworks = \Order\Model_Artwork::find(array('where' => array('unique_id' => $unique_id, 'order_id' => $order_id, 'deleted_at' => 0), 'order_by' => array('type' => 'asc')))) {
                         foreach ($artworks as $key => $artwork_item) {
                             $artwork_item->type = $key + 1;
                             $artwork_item->save();
                         }
                     }
                 }
             }
             $current = $responseObject->getStatus();
             if (!empty($current)) {
                 $out['data']['file_id'] = $file_id;
             } else {
                 $out['data']['file_id'] = $file_id;
             }
         }
     }
     if ($return) {
         return $out;
     }
     echo json_encode($out);
 }