Returns the attribute item for the given code and type

@param string $code Attribute code
@param string|null $type Attribute type
@return \Aimeos\MShop\Attribute\Item\Iface|null Attribute object or null if not found
770425
public function get( $code, $type = null )
	{
		if( isset( $this->attributes[$code] ) && isset( $this->attributes[$code][$type] ) ) {
			return $this->attributes[$code][$type];
		}

		$manager = \Aimeos\MShop::create( $this->getContext(), 'attribute' );

		$search = $manager->createSearch();
		$expr = array(
			$search->compare( '==', 'attribute.code', $code ),
			$search->compare( '==', 'attribute.type', $type ),
		);
		$search->setConditions( $search->combine( '&&', $expr ) );

		$result = $manager->searchItems( $search );

		if( ( $item = reset( $result ) ) !== false )
		{
			$this->attributes[$code][$type] = $item;
			return $item;
		}
	}
478445
public function get_attribute( $key ) {
		if ( 'id' === $key ) {
			return $this->get_id();
		}

		// Return a "null" if not found attribute.
		if ( ! array_key_exists( $key, $this->attributes ) ) {
			return;
		}

		// The value should be returned.
		$value = $this->attributes[ $key ];

		// Cast to native PHP type and return if has case.
		if ( $this->has_cast( $key ) ) {
			return $this->cast_attribute( $key, $value );
		}

		return $value;
	}
950527
public function update($name, $type, $code, $desc = null)
    {
        $legacyKernel = Eresus_Kernel::app()->getLegacyKernel();
        $filename = $legacyKernel->froot . 'templates/';
        if ($type)
        {
            $filename .= "$type/";
        }
        $filename .= "$name.html";
        $item = $this->get($name, $type, true);
        $item['code'] = $code;
        if (!is_null($desc))
        {
            $item['desc'] = $desc;
        }
        $content = "{* {$item['desc']} *}\n{$item['code']}";
        $result = file_put_contents($filename, $content) > 0;
        return $result;
    }
224790
public static function get($code, $data=null) {
    self::predefine();
    if (defined($code)) {
      $def = unserialize(constant($code));
      $error = new ApplicationError($def[0], $def[1], $def[2], $def[3], $data);
      return $error;
    }
    else {
      throw new IllegalArgumentException("The error code '".$code."' is not defined");
    }
  }
699521
public static function defaultAttributeItems($attribute, $type = 0, $json = false) {
		$static = new static;

		return $static->getAttributeItems($attribute, $type, $json, true);
	}
1151559
public function getAttributesToSend($type = null)
    {
        if (is_array($this->attributesToSend)) {
            if ($type == null) {
                return $this->attributesToSend;
            } else {
                foreach($this->attributesToSend as $i => $attr) {
                    if (is_array($attr)) {
                        $tmp = $attr[0];
                    } else {
                        $tmp = $attr;
                    }
                    if ($type == ord(substr($tmp, 0, 1))) {
                        return $this->decodeAttribute(substr($tmp, 2), $type);
                    }
                }
                return null;
            }
        }

        return array();
    }
706350
public function getFieldByCode($code)
    {
        foreach ($this->_fields as $field) {
            if ($field instanceof FieldInterface) {
                if ($field->getCode() == $code) {
                    return $field;
                }
            }
        }

        return null;
    }
725531
public function getAttributes( $type = null )
	{
		if( $type === null ) {
			return $this->_attributes;
		}

		$list = array();

		foreach( $this->_attributes as $attrItem )
		{
			if( $attrItem->getType() === $type ) {
				$list[] = $attrItem;
			}
		}

		return $list;
	}
340882
protected static function toXpath($code, $type='html', $encoding='UTF-8') {
		$doc = new \DOMDocument();
		if ($type == 'xml')
			@$doc->loadXML('<?xml encoding="'.$encoding.'">' . $code);
		else
			@$doc->loadHTML('<?xml encoding="'.$encoding.'">' . $code);

		foreach($doc->childNodes as $item) {
			if($item->nodeType == XML_PI_NODE)
				$doc->removeChild($item); #remove encoding node
		}

		return new \DOMXPath($doc);
	}
70073
protected function getSafeValue($code)
    {
        if (is_bool($code)) {
            return $code ? '(bool) true' : '(bool) false';
        }

        if (is_scalar($code)) {
            return $code;
        }

        if (is_array($code)) {
            return print_r($code, true);
        }

        return getType($code);
    }
262348
public function getAccessToken($type = 'client', $code = null){
        $param = array(
            'appid'  => $this->appId,
            'secret' => $this->appSecret
        );

        switch ($type) {
            case 'client':
                $param['grant_type'] = 'client_credential';
                $url = "{$this->apiURL}/token";
                break;

            case 'code':
                $param['code'] = $code;
                $param['grant_type'] = 'authorization_code';
                $url = "{$this->oauthApiURL}/oauth2/access_token";
                break;

            default:
                throw new \Exception('不支持的grant_type类型！');
                break;
        }

        $token = self::http($url, $param);
        $token = json_decode($token, true);

        if(is_array($token)){
            if(isset($token['errcode'])){
                throw new \Exception($token['errmsg']);
            } else {
                $this->accessToken = $token['access_token'];
                return $token;
            }
        } else {
            throw new \Exception('获取微信access_token失败！');
        }
    }
1366305
public function getFeatureByCode($code)
    {
        $feature = $this->features()->getEager()->first(function($item) use ($code) {
            return $item->code === $code;
        });

        if (is_null($feature)) {
            throw new InvalidPlanFeatureException($code);
        }

        return $feature;
    }
871942
protected static function validateCode($type, $code, $iblockId = null)
    {
        global $APPLICATION;

        if (is_null($code)) {
            // if code of info block is not updated
            return true;
        }

        try {
            $type = trim($type);
            $code = trim($code);

            if (strlen($code) <= 0) {
                throw new \Exception('EMPTY_CODE');
            }

            $rsSimilarIblock = IblockTable::query()
                ->setFilter(['IBLOCK_TYPE_ID' => $type, 'CODE' => $code, '!ID' => $iblockId])
                ->setSelect(['ID'])
                ->exec();

            if ($rsSimilarIblock->getSelectedRowsCount() > 0) {
                throw new \Exception('CODE_ALREDY_USED');
            }

            return true;
        } catch (\Exception $e) {
            Loc::loadMessages(__FILE__);

            $APPLICATION->ThrowException(Loc::getMessage('BEX_TOOLS_IBLOCK_' . $e->getMessage()));
            return false;
        }
    }
115687
public function getByCode($code)
    {
        if (\is_scalar($code) && ! empty($code = trim($this->uppercaseAndSafeTransliterate($code)))) {
            foreach ($this->items as $auto_category) {
                if ($auto_category->getCode() === $code) {
                    return $auto_category;
                }
            }
        }
    }
177437
public function getCoupons($code = null)
    {
        $requestData = new Get\RequestData($code);
        $request = new Get\Request($requestData);

        $apiResponse = $this->sendRequest($request, Get\ApiResponse::class);
        /** @var Get\Response $response */
        $response = $apiResponse->getResponse();
        foreach ($response->getCoupons() as $coupon) {
            $validFrom = $coupon->getValidFrom();
            if ($validFrom !== null) {
                $validFrom->setTime(0, 0, 0);
            }

            $validTo = $coupon->getValidTo();
            if ($validTo !== null) {
                $validTo->setTime(0, 0, 0);
            }
        }

        return $apiResponse;
    }
1102935
protected function getStockItems( $code )
	{
		$manager = \Aimeos\MShop::create( $this->getContext(), 'stock' );

		$search = $manager->createSearch();
		$search->setConditions( $search->compare( '==', 'stock.productcode', $code ) );

		return $manager->searchItems( $search );
	}
1011557
public function checkCode($code)
    {
        $res = $this->twofactorAdapter->check($code);

        if($res)
        {
            setcookie('twofactorDir-' . $this->dir, $this->cookieCode, 0, "/");
            self::redirect();
        }

        return $res;
    }