Exemplo n.º 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;
 }
Exemplo n.º 2
0
 public function productEditAction()
 {
     $this->authorize('admin.config');
     $serviceManager = $this->getServiceLocator();
     $squareProductManager = $serviceManager->get('Square\\Manager\\SquareProductManager');
     $formElementManager = $serviceManager->get('FormElementManager');
     $spid = $this->params()->fromRoute('spid');
     if ($spid) {
         $squareProduct = $squareProductManager->get($spid);
     } else {
         $squareProduct = null;
     }
     $editForm = $formElementManager->get('Backend\\Form\\ConfigSquare\\EditProductForm');
     if ($this->getRequest()->isPost()) {
         $editForm->setData($this->params()->fromPost());
         if ($editForm->isValid()) {
             $editData = $editForm->getData();
             if (!$squareProduct) {
                 $squareProduct = new SquareProduct();
             }
             $sid = $editData['cf-square'];
             if ($sid == 'null') {
                 $sid = null;
             }
             $dateStart = $editData['cf-date-start'];
             if ($dateStart) {
                 $dateStart = (new \DateTime($dateStart))->format('Y-m-d');
             } else {
                 $dateStart = null;
             }
             $dateEnd = $editData['cf-date-end'];
             if ($dateEnd) {
                 $dateEnd = (new \DateTime($dateEnd))->format('Y-m-d');
             } else {
                 $dateEnd = null;
             }
             $price = str_replace(',', '.', $editData['cf-price']);
             $price = floatval($price);
             $price *= 100;
             $locale = $editData['cf-locale'];
             if ($locale == '0') {
                 $locale = null;
             }
             $squareProduct->set('name', $editData['cf-name']);
             $squareProduct->set('description', $editData['cf-description']);
             $squareProduct->set('options', $editData['cf-options']);
             $squareProduct->set('sid', $sid);
             $squareProduct->set('priority', $editData['cf-priority']);
             $squareProduct->set('date_start', $dateStart);
             $squareProduct->set('date_end', $dateEnd);
             $squareProduct->set('price', $price);
             $squareProduct->set('gross', $editData['cf-gross']);
             $squareProduct->set('rate', $editData['cf-rate']);
             $squareProduct->set('locale', $locale);
             $squareProductManager->save($squareProduct);
             $this->flashMessenger()->addSuccessMessage('Product has been saved');
             return $this->redirect()->toRoute('backend/config/square/product');
         }
     } else {
         if ($squareProduct) {
             $editForm->setData(array('cf-name' => $squareProduct->get('name'), 'cf-description' => $squareProduct->get('description'), 'cf-options' => $squareProduct->get('options'), 'cf-square' => $squareProduct->get('sid'), 'cf-priority' => $squareProduct->get('priority'), 'cf-date-start' => $this->dateFormat($squareProduct->get('date_start')), 'cf-date-end' => $this->dateFormat($squareProduct->get('date_end')), 'cf-price' => $this->numberFormat($squareProduct->get('price') / 100), 'cf-gross' => $squareProduct->get('gross'), 'cf-rate' => $squareProduct->get('rate')));
         }
     }
     return array('squareProduct' => $squareProduct, 'editForm' => $editForm);
 }
Exemplo n.º 3
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;
 }