/** * Renders grid column * * @param \Magento\Framework\Object $row * @return string */ public function render(\Magento\Framework\Object $row) { $readDetailsHtml = $row->getUrl() ? '<a class="action-details" target="_blank" href="' . $row->getUrl() . '">' . __('Read Details') . '</a>' : ''; $markAsReadHtml = !$row->getIsRead() ? '<a class="action-mark" href="' . $this->getUrl('*/*/markAsRead/', array('_current' => true, 'id' => $row->getId())) . '">' . __('Mark as Read') . '</a>' : ''; $encodedUrl = $this->_urlHelper->getEncodedUrl(); return sprintf('%s%s<a class="action-delete" href="%s" onClick="deleteConfirm(\'%s\', this.href); return false;">%s</a>', $readDetailsHtml, $markAsReadHtml, $this->getUrl('*/*/remove/', array('_current' => true, 'id' => $row->getId(), \Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED => $encodedUrl)), __('Are you sure?'), __('Remove')); }
/** * Renderer for "Action" column in Newsletter templates grid * * @param \Magento\Framework\Object $row * @return string */ public function render(\Magento\Framework\Object $row) { if ($row->isValidForSend()) { $actions[] = ['url' => $this->getUrl('*/queue/edit', ['template_id' => $row->getId()]), 'caption' => __('Queue Newsletter')]; } $actions[] = ['url' => $this->getUrl('*/*/preview', ['id' => $row->getId()]), 'popup' => true, 'caption' => __('Preview')]; $this->getColumn()->setActions($actions); return parent::render($row); }
/** * Retrieve gift message save url * * @param \Magento\Framework\Object $item * @param string $type * @param array $params * @return string */ public function getEditUrl(\Magento\Framework\Object $item, $type, $params = array()) { if ($item->getGiftMessageId()) { $params = array_merge($params, array('message' => $item->getGiftMessageId(), 'item' => $item->getId(), 'type' => $type)); return $this->_getUrl('giftmessage/index/edit', $params); } else { $params = array_merge($params, array('item' => $item->getId(), 'type' => $type)); return $this->_getUrl('giftmessage/index/new', $params); } }
/** * Set new increment id * * @param \Magento\Framework\Object $object * @return $this */ public function beforeSave($object) { if (!$object->getId()) { $this->getAttribute()->getEntity()->setNewIncrementId($object); } return $this; }
/** * Return recurring payment child Orders Ids * * * @param \Magento\Framework\Object $object * @return array */ public function getChildOrderIds($object) { $adapter = $this->_getReadAdapter(); $bind = array(':payment_id' => $object->getId()); $select = $adapter->select()->from(array('main_table' => $this->getTable('recurring_payment_order')), array('order_id'))->where('payment_id=:payment_id'); return $adapter->fetchCol($select, $bind); }
/** * Render grid column * * @param \Magento\Framework\Object $row * @return string */ public function render(\Magento\Framework\Object $row) { $actions = []; $actions[] = ['url' => $this->getUrl('adminhtml/*/preview', ['id' => $row->getId()]), 'popup' => true, 'caption' => __('Preview')]; $this->getColumn()->setActions($actions); return parent::render($row); }
/** * Set attribute value * * @param \Magento\Framework\Object $object * @return $this */ protected function _setAttributeValue($object) { $storeId = $object->getStoreId(); $defaultStoreId = \Magento\Store\Model\Store::DEFAULT_STORE_ID; if (!isset($this->_entityAttributeValues[$object->getId()])) { return $this; } $productValues = $this->_entityAttributeValues[$object->getId()]; if (!isset($productValues[$storeId]) && !isset($productValues[$defaultStoreId])) { return $this; } $value = isset($productValues[$storeId]) ? $productValues[$storeId] : $productValues[$defaultStoreId]; $value = $this->_prepareDatetimeValue($value, $object); $value = $this->_prepareMultiselectValue($value, $object); $object->setData($this->getAttribute(), $value); return $this; }
/** * Renders grid column * * @param \Magento\Framework\Object $row * @return string */ public function render(\Magento\Framework\Object $row) { if ($row->getSubscriberStatus() == \Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED) { return '<input type="checkbox" name="subscriber[]" value="' . $row->getId() . '" class="subscriberCheckbox"/>'; } else { return ''; } }
/** * Renders column * * @param \Magento\Framework\Object $row * @return string */ public function render(\Magento\Framework\Object $row) { $actions = []; if ($row->getQueueStatus() == \Magento\Newsletter\Model\Queue::STATUS_NEVER) { if (!$row->getQueueStartAt() && $row->getSubscribersTotal()) { $actions[] = ['url' => $this->getUrl('*/*/start', ['id' => $row->getId()]), 'caption' => __('Start')]; } } elseif ($row->getQueueStatus() == \Magento\Newsletter\Model\Queue::STATUS_SENDING) { $actions[] = ['url' => $this->getUrl('*/*/pause', ['id' => $row->getId()]), 'caption' => __('Pause')]; $actions[] = ['url' => $this->getUrl('*/*/cancel', ['id' => $row->getId()]), 'confirm' => __('Do you really want to cancel the queue?'), 'caption' => __('Cancel')]; } elseif ($row->getQueueStatus() == \Magento\Newsletter\Model\Queue::STATUS_PAUSE) { $actions[] = ['url' => $this->getUrl('*/*/resume', ['id' => $row->getId()]), 'caption' => __('Resume')]; } $actions[] = ['url' => $this->getUrl('*/*/preview', ['id' => $row->getId()]), 'caption' => __('Preview'), 'popup' => true]; $this->getColumn()->setActions($actions); return parent::render($row); }
/** * Set default shipping to address * * @param \Magento\Framework\Object $address * @return $this */ protected function _afterSave(\Magento\Framework\Object $address) { if ($address->getIsCustomerSaveTransaction()) { return $this; } if ($address->getId() && ($address->getIsDefaultBilling() || $address->getIsDefaultShipping())) { $customer = $this->_createCustomer()->load($address->getCustomerId()); if ($address->getIsDefaultBilling()) { $customer->setDefaultBilling($address->getId()); } if ($address->getIsDefaultShipping()) { $customer->setDefaultShipping($address->getId()); } $customer->save(); } return $this; }
/** * Before save * * @param \Magento\Framework\Object $object * @return $this */ public function beforeSave($object) { if ($object->getId()) { return $this; } if (!$object->hasData('website_id')) { $object->setData('website_id', $this->_storeManager->getStore()->getWebsiteId()); } return $this; }
/** * Renders grid column * * @param \Magento\Framework\Object $row * @return string */ public function render(\Magento\Framework\Object $row) { $values = $this->_getValues(); $value = $row->getData($this->getColumn()->getIndex()); if (is_array($values)) { $checked = in_array($value, $values) ? ' checked="checked"' : ''; } else { $checked = $value === $this->getColumn()->getValue() ? ' checked="checked"' : ''; } $html = '<input type="radio" name="' . $this->getColumn()->getHtmlName() . '" '; $html .= 'value="' . $row->getId() . '" class="radio"' . $checked . '/>'; return $html; }
/** * Before save * * @param \Magento\Framework\Object $object * @return $this */ public function beforeSave($object) { if ($object->getId()) { return $this; } if (!$object->hasStoreId()) { $object->setStoreId($this->_storeManager->getStore()->getId()); } if (!$object->hasData('created_in')) { $object->setData('created_in', $this->_storeManager->getStore($object->getStoreId())->getName()); } return $this; }
/** * Set qty and custom price for quote item * * @param Item $item * @param \Magento\Framework\Object $request * @param Product $candidate * @return void */ public function prepare(Item $item, Object $request, Product $candidate) { /** * We specify qty after we know about parent (for stock) */ if ($request->getResetCount() && !$candidate->getStickWithinParent() && $item->getId() == $request->getId()) { $item->setData(CartItemInterface::KEY_QTY, 0); } $item->addQty($candidate->getCartQty()); $customPrice = $request->getCustomPrice(); if (!empty($customPrice)) { $item->setCustomPrice($customPrice); $item->setOriginalCustomPrice($customPrice); } }
/** * Render single action as link html * * @param array $action * @param \Magento\Framework\Object $row * @return string|false */ protected function _toLinkHtml($action, \Magento\Framework\Object $row) { $product = $row->getProduct(); if (isset($action['process']) && $action['process'] == 'configurable') { if ($product->canConfigure()) { $style = ''; $onClick = sprintf('onclick="return %s.configureItem(%s)"', $action['control_object'], $row->getId()); return sprintf('<a href="%s" %s %s>%s</a>', $action['url'], $style, $onClick, $action['caption']); } else { return false; } } else { return parent::_toLinkHtml($action, $row); } }
/** * Check is current entity has changes, by comparing current object state with stored snapshot * * @param \Magento\Framework\Object $entity * @return bool */ public function isModified(\Magento\Framework\Object $entity) { if (!$entity->getId()) { return true; } $entityClass = get_class($entity); if (!isset($this->snapshotData[$entityClass][$entity->getId()])) { return true; } foreach ($this->snapshotData[$entityClass][$entity->getId()] as $field => $value) { if ($entity->getDataByKey($field) != $value) { return true; } } return false; }
/** * Initialize quote item object * * @param \Magento\Framework\Object $request * @param Product $product * * @return \Magento\Quote\Model\Quote\Item */ public function init(Product $product, $request) { $item = $this->quoteItemFactory->create(); $this->setItemStoreId($item); /** * We can't modify existing child items */ if ($item->getId() && $product->getParentProductId()) { return $item; } $item->setOptions($product->getCustomOptions()); $item->setProduct($product); if ($request->getResetCount() && !$product->getStickWithinParent() && $item->getId() === $request->getId()) { $item->setData('qty', 0); } return $item; }
/** * Add customer to array * * @param \Magento\Framework\Object|\Magento\Customer\Model\Customer $customer * @return $this */ public function addCustomer(\Magento\Framework\Object $customer) { $email = strtolower(trim($customer->getEmail())); if (!isset($this->_customerIds[$email])) { $this->_customerIds[$email] = []; } $this->_customerIds[$email][$customer->getWebsiteId()] = $customer->getId(); return $this; }
/** * Retrieve identifier of block item * * @param \Magento\Framework\Object $item * @return int */ public function getIdentifierId($item) { return $item->getId(); }
/** * Retrieve product identifier linked with item * * @param \Magento\Framework\Object $item * @return int */ public function getProductId($item) { return $item->getId(); }
/** * {@inheritdoc} */ protected function _afterDelete(\Magento\Framework\Object $address) { if ($address->getId()) { $customer = $this->_createCustomer()->load($address->getCustomerId()); if ($customer->getDefaultBilling() == $address->getId()) { $customer->setDefaultBilling(null); } if ($customer->getDefaultShipping() == $address->getId()) { $customer->setDefaultShipping(null); } $customer->save(); } return parent::_afterDelete($address); }
/** * Retrieve the Url for a specified sales order row. * * @param \Magento\Sales\Model\Order|\Magento\Framework\Object $row * @return string */ public function getRowUrl($row) { return $this->getUrl('sales/order/view', array('order_id' => $row->getId())); }
/** * Create url for passed item using passed url model * * @param \Magento\Framework\Object $item * @return string */ public function getUrl($item) { return $item->getId(); }
/** * Delete entity attribute values * * @param \Magento\Framework\Object $object * @param string $table * @param array $info * @return $this */ protected function _deleteAttributes($object, $table, $info) { $adapter = $this->_getWriteAdapter(); $entityIdField = $this->getEntityIdField(); $globalValues = array(); $websiteAttributes = array(); $storeAttributes = array(); /** * Separate attributes by scope */ foreach ($info as $itemData) { $attribute = $this->getAttribute($itemData['attribute_id']); if ($attribute->isScopeStore()) { $storeAttributes[] = (int) $itemData['attribute_id']; } elseif ($attribute->isScopeWebsite()) { $websiteAttributes[] = (int) $itemData['attribute_id']; } elseif ($itemData['value_id'] !== null) { $globalValues[] = (int) $itemData['value_id']; } } /** * Delete global scope attributes */ if (!empty($globalValues)) { $adapter->delete($table, array('value_id IN (?)' => $globalValues)); } $condition = array($entityIdField . ' = ?' => $object->getId(), 'entity_type_id = ?' => $object->getEntityTypeId()); /** * Delete website scope attributes */ if (!empty($websiteAttributes)) { $storeIds = $object->getWebsiteStoreIds(); if (!empty($storeIds)) { $delCondition = $condition; $delCondition['attribute_id IN(?)'] = $websiteAttributes; $delCondition['store_id IN(?)'] = $storeIds; $adapter->delete($table, $delCondition); } } /** * Delete store scope attributes */ if (!empty($storeAttributes)) { $delCondition = $condition; $delCondition['attribute_id IN(?)'] = $storeAttributes; $delCondition['store_id = ?'] = (int) $object->getStoreId(); $adapter->delete($table, $delCondition); } return $this; }
/** * Retrieve select object for loading entity attributes values * * @param \Magento\Framework\Object $object * @param string $table * @return \Zend_Db_Select */ protected function _getLoadAttributesSelect($object, $table) { $select = $this->_getReadAdapter()->select()->from($table, array())->where($this->getEntityIdField() . ' =?', $object->getId()); return $select; }
/** * Return row url for js event handlers * * @param \Magento\Catalog\Model\Product|\Magento\Framework\Object $row * @return string */ public function getRowUrl($row) { return $this->getUrl('adminhtml/*/edit', array('product' => $row->getId())) . 'category'; }
/** * Checks allowed quote item for gift messages * * @param \Magento\Framework\Object $item * @return bool * @SuppressWarnings(PHPMD.BooleanGetMethodName) */ public function getIsAllowedQuoteItem($item) { if (!in_array($item->getId(), $this->getAllowQuoteItems())) { if ($item->getGiftMessageId() && $this->isGiftMessagesAvailable($item)) { $this->addAllowQuoteItem($item->getId()); return true; } return false; } return true; }
/** * @param \Magento\Catalog\Model\Product|\Magento\Framework\Object $row * @return string */ public function getRowUrl($row) { return $this->getUrl('catalog/*/edit', array('store' => $this->getRequest()->getParam('store'), 'id' => $row->getId())); }
/** * Validate product attribute value for condition * * @param \Magento\Framework\Object $object * @return bool */ public function validate(\Magento\Framework\Object $object) { $attrCode = $this->getAttribute(); if ('category_ids' == $attrCode) { return $this->validateAttribute($object->getAvailableInCategories()); } elseif (!isset($this->_entityAttributeValues[$object->getId()])) { if (!$object->getResource()) { return false; } $attr = $object->getResource()->getAttribute($attrCode); if ($attr && $attr->getBackendType() == 'datetime' && !is_int($this->getValue())) { $this->setValue(strtotime($this->getValue())); $value = strtotime($object->getData($attrCode)); return $this->validateAttribute($value); } if ($attr && $attr->getFrontendInput() == 'multiselect') { $value = $object->getData($attrCode); $value = strlen($value) ? explode(',', $value) : array(); return $this->validateAttribute($value); } return parent::validate($object); } else { $result = false; // any valid value will set it to TRUE // remember old attribute state $oldAttrValue = $object->hasData($attrCode) ? $object->getData($attrCode) : null; foreach ($this->_entityAttributeValues[$object->getId()] as $value) { $attr = $object->getResource()->getAttribute($attrCode); if ($attr && $attr->getBackendType() == 'datetime') { $value = strtotime($value); } elseif ($attr && $attr->getFrontendInput() == 'multiselect') { $value = strlen($value) ? explode(',', $value) : array(); } $object->setData($attrCode, $value); $result |= parent::validate($object); if ($result) { break; } } if (is_null($oldAttrValue)) { $object->unsetData($attrCode); } else { $object->setData($attrCode, $oldAttrValue); } return (bool) $result; } }
/** * @param \SR\Weblog\Model\BlogPosts|\Magento\Framework\Object $row * @return string */ public function getRowUrl($row) { return $this->getUrl('weblog/*/edit', ['blogpost_id' => $row->getId()]); }