function onGridProductAfterSave(Am_Event $event) { $product = $event->getGrid()->getRecord(); $vars = $event->getGrid()->getForm()->getValue(); if (empty($vars['img'])) { $product->img = null; $product->img_path = null; $product->img_cart_path = null; $product->img_detail_path = null; $product->img_orig_path = null; $product->update(); return; } $sizes = array('img' => array('w' => $this->getConfig('product_image_width', 200), 'h' => $this->getConfig('product_image_height', 200), 't' => Am_Image::RESIZE_CROP), 'img_cart' => array('w' => $this->getConfig('img_cart_width', 50), 'h' => $this->getConfig('img_cart_height', 50), 't' => Am_Image::RESIZE_CROP), 'img_detail' => array('w' => $this->getConfig('img_detail_width', 400), 'h' => $this->getConfig('img_detail_height', 400), 't' => Am_Image::RESIZE_GIZMO)); if ($product->img) { $upload = $this->getDi()->uploadTable->load($product->img); if ($upload->prefix != self::UPLOAD_PREFIX) { throw new Am_Exception_InputError('Incorrect prefix requested [%s]', $upload->prefix); } switch ($upload->getType()) { case 'image/gif': $ext = 'gif'; break; case 'image/png': $ext = 'png'; break; case 'image/jpeg': $ext = 'jpg'; break; default: throw new Am_Exception_InputError(sprintf('Unknown MIME type [%s]', $mime)); } $name = str_replace('.' . self::UPLOAD_PREFIX . '.', '', $upload->path); $filename = $upload->getFullPath(); $image = new Am_Image($upload->getFullPath(), $upload->getType()); foreach ($sizes as $id => $size) { $newName = 'cart/' . $size['w'] . '_' . $size['h'] . '/' . $name . '.jpg'; $newFilename = ROOT_DIR . '/data/public/' . $newName; if (!file_exists($newFilename)) { if (!is_dir(dirname($newFilename))) { mkdir(dirname($newFilename), 0777, true); } $i = clone $image; $i->resize($size['w'], $size['h'], $size['t'])->save($newFilename); } $product->{$id . '_path'} = $newName; } $newOrigName = 'cart/orig/' . $name . '.' . $ext; $newOrigFilename = ROOT_DIR . '/data/public/' . $newOrigName; if (!file_exists($newOrigFilename)) { if (!is_dir(dirname($newOrigFilename))) { mkdir(dirname($newOrigFilename), 0777, true); } copy($filename, $newOrigFilename); $product->img_orig_path = $newOrigName; } $product->update(); } }
function onGridProductValuesToForm(Am_Event $event) { $args = $event->getArgs(); $values = $args[0]; $product = $event->getGrid()->getRecord(); if ($sliiing_billers = json_decode($product->data()->getBlob('sliiing_billers'), true)) { $values['_sliiing_billers'] = $sliiing_billers; $event->setArg(0, $values); } }
function onGridCouponBatchInitForm(Am_Event $event) { /* @var $form Am_Form_Admin */ $form = $event->getGrid()->getForm(); $fieldSet = $form->getElementById('coupon-batch'); $batch = $event->getGrid()->getRecord(); $affGroup = $fieldSet->addGroup()->setLabel(___("Affiliate\n" . "this affiliate will get commission for payment in case of " . "coupon from this batch is used during payment. " . "This affiliate will be assigned to user as default affiliate " . "in case of user has not default affiliate assigned yet.")); $affEl = $affGroup->addText('_aff', array('placeholder' => ___('Type Username or E-Mail')))->setId('aff-affiliate'); $fieldSet->addScript()->setScript(<<<CUT \$("input#aff-affiliate").autocomplete({ minLength: 2, source: window.rootUrl + "/aff/admin/autocomplete/" }); CUT ); if (!empty($batch->aff_id)) { try { $aff = $this->getDi()->userTable->load($batch->aff_id); $affEl->setValue($aff->login); $affEl->setAttribute('style', 'display:none'); $url = new Am_View_Helper_UserUrl(); $affHtml = sprintf('<div><a href="%s">%s %s (%s)</a> [<a href="javascript:;" title="%s" class="local" id="aff-unassign-affiliate">x</a>]</div>', Am_Controller::escape($url->userUrl($batch->aff_id)), $aff->name_f, $aff->name_l, $aff->email, ___('Unassign Affiliate')); $affGroup->addStatic()->setContent($affHtml); $affGroup->addScript()->setScript(<<<CUT \$('#aff-unassign-affiliate').click(function(){ \$(this).closest('div').remove(); \$('#aff-affiliate').val(''); \$('#aff-affiliate').show(); }) CUT ); } catch (Am_Exception $e) { // ignore if affiliate was deleted } } }
function onGridCouponBatchInitForm(Am_Event $event) { /* @var $form Am_Form_Admin */ $form = $event->getGrid()->getForm(); $fieldSet = $form->getElementById('coupon-batch'); $batch = $event->getGrid()->getRecord(); $affGroup = $fieldSet->addGroup()->setLabel(___("Affiliate\n" . "whenever coupons from this batch is used, commission will always be credited to " . "this affiliate. This is true even when another affiliate is permanently " . "tagged to the customer. For sales where the coupon is NOT used, the " . "original (previous) affiliate will continue receiving commissions. If the " . "customer has no affiliate, this affiliate will permanently be tagged to the " . "customer, and will receive credit for future sales.")); $affEl = $affGroup->addText('_aff', array('placeholder' => ___('Type Username or E-Mail')))->setId('aff-affiliate'); $fieldSet->addScript()->setScript(<<<CUT \$("input#aff-affiliate").autocomplete({ minLength: 2, source: window.rootUrl + "/aff/admin/autocomplete/" }); CUT ); if (!empty($batch->aff_id)) { try { $aff = $this->getDi()->userTable->load($batch->aff_id); $affEl->setValue($aff->login); $affEl->setAttribute('style', 'display:none'); $url = new Am_View_Helper_UserUrl(); $affHtml = sprintf('<div><a href="%s">%s %s (%s)</a> [<a href="javascript:;" title="%s" class="local" id="aff-unassign-affiliate">x</a>]</div>', Am_Controller::escape($url->userUrl($batch->aff_id)), $aff->name_f, $aff->name_l, $aff->email, ___('Unassign Affiliate')); $affGroup->addStatic()->setContent($affHtml); $affGroup->addScript()->setScript(<<<CUT \$('#aff-unassign-affiliate').click(function(){ \$(this).closest('div').remove(); \$('#aff-affiliate').val(''); \$('#aff-affiliate').show(); }) CUT ); } catch (Am_Exception $e) { // ignore if affiliate was deleted } } }
function onGridProductValuesToForm(Am_Event $event) { $args = $event->getArgs(); $values = $args[0]; $product = $event->getGrid()->getRecord(); if ($rate = unserialize($product->data()->getBlob('vat_eu_rate'))) { $values['_rate'] = $rate; $event->setArg(0, $values); } }
function onGridUserOnBeforeRun(Am_Event $event) { /* @var $grid Am_Grid_Editable */ $grid = $event->getGrid(); /* @var $query Am_Query_User */ $query = $grid->getDataSource(); $date = sqlTime(sprintf('-%d minutes', $this->getConfig('timeout', 5))); $query->leftJoin('?_login_session', 'ls', 'u.user_id=ls.user_id')->addField("SUM(IF(modified>'{$date}' AND need_logout=0, 1, 0))", 'login_session_cnt'); $loginIndicator = new Am_Grid_Field('login_indicator', ___('Login Indicator'), false); $loginIndicator->setRenderFunction(array($this, 'renderLoginIndicator')); $action = $grid->actionGet('customize'); $action->addField($loginIndicator); }