/** * Renders grid column * * @param \Magento\Framework\DataObject $row * @return string */ public function render(\Magento\Framework\DataObject $row) { $line = parent::_getValue($row); $wrappedLine = ''; $lineLength = $this->getColumn()->getData('lineLength') ? $this->getColumn()->getData('lineLength') : $this->_defaultMaxLineLength; for ($i = 0, $n = floor($this->string->strlen($line) / $lineLength); $i <= $n; $i++) { $wrappedLine .= $this->string->substr($line, $lineLength * $i, $lineLength) . "<br />"; } return $wrappedLine; }
/** * Load search results * * @return $this */ public function load() { $result = []; if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) { $this->setResults($result); return $this; } $collection = $this->queryFactory->get()->getSearchCollection()->addAttributeToSelect('name')->addAttributeToSelect('description')->addBackendSearchFilter($this->getQuery())->setCurPage($this->getStart())->setPageSize($this->getLimit())->load(); foreach ($collection as $product) { $description = strip_tags($product->getDescription()); $result[] = ['id' => 'product/1/' . $product->getId(), 'type' => __('Product'), 'name' => $product->getName(), 'description' => $this->string->substr($description, 0, 30), 'url' => $this->_adminhtmlData->getUrl('catalog/product/edit', ['id' => $product->getId()])]; } $this->setResults($result); return $this; }
/** * Return formatted option value ready to edit, ready to parse * * @param string $optionValue Prepared for cart option value * @return string */ public function getEditableOptionValue($optionValue) { $option = $this->getOption(); $result = ''; if (!$this->_isSingleSelection()) { foreach (explode(',', $optionValue) as $_value) { $_result = $option->getValueById($_value); if ($_result) { $result .= $_result->getTitle() . ', '; } else { if ($this->getListener()) { $this->getListener()->setHasError(true)->setMessage($this->_getWrongConfigurationMessage()); $result = ''; break; } } } $result = $this->string->substr($result, 0, -2); } elseif ($this->_isSingleSelection()) { $_result = $option->getValueById($optionValue); if ($_result) { $result = $_result->getTitle(); } else { if ($this->getListener()) { $this->getListener()->setHasError(true)->setMessage($this->_getWrongConfigurationMessage()); } $result = ''; } } else { $result = $optionValue; } return $result; }
/** * Add meta information from product to head block * * @return \Magento\Catalog\Block\Product\View */ protected function _prepareLayout() { $this->getLayout()->createBlock('Magento\\Catalog\\Block\\Breadcrumbs'); $product = $this->getProduct(); if (!$product) { return parent::_prepareLayout(); } $title = $product->getMetaTitle(); if ($title) { $this->pageConfig->getTitle()->set($title); } $keyword = $product->getMetaKeyword(); $currentCategory = $this->_coreRegistry->registry('current_category'); if ($keyword) { $this->pageConfig->setKeywords($keyword); } elseif ($currentCategory) { $this->pageConfig->setKeywords($product->getName()); } $description = $product->getMetaDescription(); if ($description) { $this->pageConfig->setDescription($description); } else { $this->pageConfig->setDescription($this->string->substr($product->getDescription(), 0, 255)); } if ($this->_productHelper->canUseCanonicalTag()) { $this->pageConfig->addRemotePageAsset($product->getUrlModel()->getUrl($product, ['_ignore_category' => true]), 'canonical', ['attributes' => ['rel' => 'canonical']]); } $pageMainTitle = $this->getLayout()->getBlock('page.main.title'); if ($pageMainTitle) { $pageMainTitle->setPageTitle($product->getName()); } return parent::_prepareLayout(); }
/** * @param string $queryText * @param int|string $maxQueryLength * @return string */ private function getPreparedQueryText($queryText, $maxQueryLength) { if ($this->isQueryTooLong($queryText, $maxQueryLength)) { $queryText = $this->string->substr($queryText, 0, $maxQueryLength); } return $queryText; }
/** * Filter value * * @param string $string * @return string */ public function filter($string) { $length = $this->length; $this->remainder = ''; if (0 == $length) { return ''; } $originalLength = $this->string->strlen($string); if ($originalLength > $length) { $length -= $this->string->strlen($this->etc); if ($length <= 0) { return ''; } $preparedString = $string; $preparedLength = $length; if (!$this->breakWords) { $preparedString = preg_replace('/\\s+?(\\S+)?$/u', '', $this->string->substr($string, 0, $length + 1)); $preparedLength = $this->string->strlen($preparedString); } $this->remainder = $this->string->substr($string, $preparedLength, $originalLength); return $this->string->substr($preparedString, 0, $length) . $this->etc; } return $string; }
public function testSubstr() { $this->assertSame('tring', $this->_string->substr('string', 1)); }
/** * Prepare and set request in property of current instance * * @param \Magento\Framework\DataObject $request * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function setRequest(\Magento\Framework\DataObject $request) { $this->_request = $request; $this->setStore($request->getStoreId()); $requestObject = new \Magento\Framework\DataObject(); $requestObject->setIsGenerateLabelReturn($request->getIsGenerateLabelReturn()); $requestObject->setStoreId($request->getStoreId()); if ($request->getLimitMethod()) { $requestObject->setService($request->getLimitMethod()); } $requestObject = $this->_addParams($requestObject); if ($request->getDestPostcode()) { $requestObject->setDestPostal($request->getDestPostcode()); } $requestObject->setOrigCountry($this->_getDefaultValue($request->getOrigCountry(), Shipment::XML_PATH_STORE_COUNTRY_ID))->setOrigCountryId($this->_getDefaultValue($request->getOrigCountryId(), Shipment::XML_PATH_STORE_COUNTRY_ID)); $shippingWeight = $request->getPackageWeight(); $requestObject->setValue(round($request->getPackageValue(), 2))->setValueWithDiscount($request->getPackageValueWithDiscount())->setCustomsValue($request->getPackageCustomsValue())->setDestStreet($this->string->substr(str_replace("\n", '', $request->getDestStreet()), 0, 35))->setDestStreetLine2($request->getDestStreetLine2())->setDestCity($request->getDestCity())->setOrigCompanyName($request->getOrigCompanyName())->setOrigCity($request->getOrigCity())->setOrigPhoneNumber($request->getOrigPhoneNumber())->setOrigPersonName($request->getOrigPersonName())->setOrigEmail($this->_scopeConfig->getValue('trans_email/ident_general/email', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $requestObject->getStoreId()))->setOrigCity($request->getOrigCity())->setOrigPostal($request->getOrigPostal())->setOrigStreetLine2($request->getOrigStreetLine2())->setDestPhoneNumber($request->getDestPhoneNumber())->setDestPersonName($request->getDestPersonName())->setDestCompanyName($request->getDestCompanyName()); $originStreet2 = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ADDRESS2, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $requestObject->getStoreId()); $requestObject->setOrigStreet($request->getOrigStreet() ? $request->getOrigStreet() : $originStreet2); if (is_numeric($request->getOrigState())) { $requestObject->setOrigState($this->_regionFactory->create()->load($request->getOrigState())->getCode()); } else { $requestObject->setOrigState($request->getOrigState()); } if ($request->getDestCountryId()) { $destCountry = $request->getDestCountryId(); } else { $destCountry = self::USA_COUNTRY_ID; } // for DHL, Puerto Rico state for US will assume as Puerto Rico country // for Puerto Rico, dhl will ship as international if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)) { $destCountry = self::PUERTORICO_COUNTRY_ID; } $requestObject->setDestCountryId($destCountry)->setDestState($request->getDestRegionCode())->setWeight($shippingWeight)->setFreeMethodWeight($request->getFreeMethodWeight())->setOrderShipment($request->getOrderShipment()); if ($request->getPackageId()) { $requestObject->setPackageId($request->getPackageId()); } $requestObject->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax()); $this->setRawRequest($requestObject); return $this; }