Пример #1
0
 public function __invoke(SquareProduct $squareProduct)
 {
     $view = $this->getView();
     $html = '';
     $spid = $squareProduct->need('spid');
     $html .= '<tr>';
     $html .= sprintf('<td class="priority-col">%s</td>', $squareProduct->get('priority'));
     $html .= sprintf('<td>%s</td>', $squareProduct->get('name'));
     $sid = $squareProduct->get('sid');
     if ($sid) {
         $square = $this->squareManager->get($sid);
         $squareName = $square->get('name');
     } else {
         $squareName = sprintf($view->t('All %s'), $view->option('subject.square.type.plural'));
     }
     $html .= sprintf('<td>%s</td>', $squareName);
     $html .= sprintf('<td>%s</td>', $view->priceFormat($squareProduct->get('price'), $squareProduct->get('rate'), $squareProduct->get('gross'), null, null, 'per item', false));
     /* Actions col */
     $html .= '<td class="actions-col no-print">' . '<a href="' . $view->url('backend/config/square/product/edit', ['spid' => $spid]) . '" class="unlined gray symbolic symbolic-config">' . $view->t('Edit') . '</a> &nbsp; ' . '<a href="' . $view->url('backend/config/square/product/delete', ['spid' => $spid]) . '" class="unlined gray symbolic symbolic-cross">' . $view->t('Delete') . '</a></td>';
     $html .= '</tr>';
     return $html;
 }
Пример #2
0
 /**
  * Deletes one square product.
  *
  * @param int|SquareProduct $product
  * @return int
  * @throws InvalidArgumentException
  */
 public function delete($product)
 {
     if ($product instanceof SquareProduct) {
         $spid = $product->need('spid');
     } else {
         $spid = $product;
     }
     if (!(is_numeric($spid) && $spid > 0)) {
         throw new InvalidArgumentException('Product id must be numeric');
     }
     $product = $this->get($spid);
     $deletion = $this->squareProductTable->delete(array('spid' => $spid));
     $this->getEventManager()->trigger('delete', $product);
     return $deletion;
 }