Esempio n. 1
0
 /**
  * Saves (updates or creates) a square product.
  *
  * @param SquareProduct $product
  * @return SquareProduct
  * @throws RuntimeException
  */
 public function save(SquareProduct $product)
 {
     if ($product->get('spid')) {
         /* Update existing square product */
         /* Determine updated properties */
         $updates = array();
         foreach ($product->need('updatedProperties') as $property) {
             $updates[$property] = $product->get($property);
         }
         if ($updates) {
             $this->squareProductTable->update($updates, array('spid' => $product->get('spid')));
         }
         $product->reset();
         $this->getEventManager()->trigger('save.update', $product);
     } else {
         /* Insert square product */
         if ($product->getExtra('nspid')) {
             $spid = $product->getExtra('nspid');
         } else {
             $spid = null;
         }
         $this->squareProductTable->insert(array('spid' => $spid, 'sid' => $product->get('sid'), 'name' => $product->need('name'), 'description' => $product->get('description'), 'options' => $product->need('options'), 'price' => $product->need('price'), 'rate' => $product->need('rate'), 'gross' => $product->need('gross'), 'priority' => $product->need('priority'), 'locale' => $product->get('locale')));
         $spid = $this->squareProductTable->getLastInsertValue();
         if (!(is_numeric($spid) && $spid > 0)) {
             throw new RuntimeException('Failed to save product');
         }
         $product->add('spid', $spid);
         $this->getEventManager()->trigger('save.insert', $product);
     }
     $this->getEventManager()->trigger('save', $product);
     return $product;
 }
Esempio n. 2
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;
 }