LoginSignup
0
0

More than 3 years have passed since last update.

EC-CUBE2.17でendroid/qr-codeの最新バージョンがインストールされない

Last updated at Posted at 2020-08-12

はじめに

EC-CUBE2.17環境で、composerでendroid/qr-codeを入れようとした際に最新バージョンがインストールされなかった場合の対処法です。

やりたいこと

  • EC-CUBE2.17のマイページにQRコードを表示したい

endroid/qr-code

インストール

Packagist:https://packagist.org/packages/endroid/qr-code

$ composer require endroid/qr-code
Using version ^1.9 for endroid/qr-code
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 4 installs, 17 updates, 19 removals
  - Removing webmozart/assert (1.9.1)
  - Removing symfony/polyfill-intl-normalizer (v1.18.1)
  - Removing symfony/polyfill-intl-grapheme (v1.18.1)
  - Removing psr/container (1.0.0)
  - Removing dasprid/enum (1.0.2)
  - Removing php5friends/codeception-phpunit48-wrapper (9.0.2)
  - Removing symfony/property-info (v5.1.3)
  - Removing symfony/property-access (v5.1.3)
  - Removing myclabs/php-enum (1.7.6)
  - Removing khanamiryan/qrcode-detector-decoder (1.0.3)
  - Removing phpdocumentor/type-resolver (1.3.0)
  - Removing phpdocumentor/reflection-common (2.2.0)
  - Removing symfony/deprecation-contracts (v2.1.3)
  - Removing symfony/string (v5.1.3)
  - Removing symfony/polyfill-php80 (v1.18.1)
  - Removing symfony/service-contracts (v2.1.3)
  - Removing symfony/contracts (v1.1.0)
  - Removing codeception/lib-asserts (1.12.0)
  - Removing bacon/bacon-qr-code (2.0.2)
  - Downgrading symfony/options-resolver (v5.1.3 => v2.8.52): Loading from cache
  - Downgrading endroid/qr-code (3.9.1 => 1.9.3): Loading from cache
  - Downgrading doctrine/instantiator (1.3.1 => 1.0.5): Loading from cache
  - Downgrading codeception/stub (3.7.0 => 1.0.4): Loading from cache
  - Downgrading symfony/polyfill-ctype (v1.18.1 => v1.18.0): Loading from cache
  - Downgrading symfony/yaml (v3.4.43 => v2.8.52): Loading from cache
  - Downgrading phpdocumentor/reflection-docblock (5.2.0 => 2.0.5): Loading from cache
  - Downgrading php5friends/codeception-phpunit48-wrapper (9.0.2 => 6.0.20): Loading from cache
  - Downgrading symfony/polyfill-mbstring (v1.18.1 => v1.18.0): Loading from cache
  - Installing symfony/dom-crawler (v2.8.52): Loading from cache
  - Downgrading symfony/css-selector (v5.1.3 => v2.8.52): Loading from cache
  - Installing symfony/browser-kit (v2.8.52): Loading from cache
  - Installing symfony/debug (v2.8.52): Loading from cache
  - Downgrading symfony/console (v4.2.12 => v2.8.52): Loading from cache
  - Downgrading symfony/finder (v5.1.3 => v2.8.52): Loading from cache
  - Downgrading ralouphie/getallheaders (3.0.3 => 2.0.5): Loading from cache
  - Installing facebook/webdriver (1.1.3): Loading from cache
  - Downgrading codeception/codeception (4.1.6 => 2.4.1): Loading from cache
  - Downgrading symfony/filesystem (v5.1.3 => v2.8.52): Loading from cache
  - Downgrading symfony/config (v4.4.11 => v2.8.52): Loading from cache
  - Downgrading symfony/stopwatch (v4.4.11 => v2.8.52): Loading from cache
symfony/browser-kit suggests installing symfony/process
facebook/webdriver suggests installing phpdocumentor/phpdocumentor (2.*)
Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.
Package guzzlehttp/ringphp is abandoned, you should avoid using it. No replacement was suggested.
Package guzzlehttp/streams is abandoned, you should avoid using it. No replacement was suggested.
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Package setasign/fpdi-fpdf is abandoned, you should avoid using it. No replacement was suggested.
Package facebook/webdriver is abandoned, you should avoid using it. Use php-webdriver/webdriver instead.
Writing lock file
Generating optimized autoload files

composer.jsonを確認すると古いバージョンがインストールされています。

composer.json
"require": {
    ....
    "endroid/qr-code": "^1.9",
    ....
},

endroid/qr-codeをアンインストール

古いバージョンがインストールされてしまったので一旦アンインストールします。

$ composer remove endroid/qr-code
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 0 updates, 2 removals
  - Removing symfony/options-resolver (v2.8.52)
  - Removing endroid/qr-code (1.9.3)
Package facebook/webdriver is abandoned, you should avoid using it. Use php-webdriver/webdriver instead.
Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.
Package guzzlehttp/ringphp is abandoned, you should avoid using it. No replacement was suggested.
Package guzzlehttp/streams is abandoned, you should avoid using it. No replacement was suggested.
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Package setasign/fpdi-fpdf is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating optimized autoload files

composer.json修正

phpのバージョンが5.4.16になっている為、サーバーのPHPバージョンに合わせます。

composer.json
"config": {
    "vendor-dir": "data/vendor",
    "platform": {
        "php": "7.3.20"
    },
    "optimize-autoloader": true,
    "sort-packages": true,
    "preferred-install": {
        "*": "dist"
    }
},

再度endroid/qr-codeインストール

$ composer require endroid/qr-code
Using version ^3.9 for endroid/qr-code
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 13 installs, 0 updates, 0 removals
  - Installing myclabs/php-enum (1.7.6): Loading from cache
  - Installing symfony/polyfill-php80 (v1.18.1): Loading from cache
  - Installing symfony/polyfill-intl-normalizer (v1.18.1): Loading from cache
  - Installing symfony/polyfill-intl-grapheme (v1.18.1): Loading from cache
  - Installing symfony/string (v5.1.3): Loading from cache
  - Installing symfony/deprecation-contracts (v2.1.3): Loading from cache
  - Installing symfony/inflector (v5.1.3): Downloading (100%)         
  - Installing symfony/property-access (v5.0.11): Downloading (100%)         
  - Installing symfony/options-resolver (v5.1.3): Loading from cache
  - Installing khanamiryan/qrcode-detector-decoder (1.0.3): Loading from cache
  - Installing dasprid/enum (1.0.2): Loading from cache
  - Installing bacon/bacon-qr-code (2.0.2): Loading from cache
  - Installing endroid/qr-code (3.9.1): Loading from cache
symfony/property-access suggests installing psr/cache-implementation (To cache access methods.)
bacon/bacon-qr-code suggests installing ext-imagick (to generate QR code images)
endroid/qr-code suggests installing roave/security-advisories (Avoids installation of package versions with vulnerabilities)
endroid/qr-code suggests installing symfony/security-checker (Checks your composer.lock for vulnerabilities)
Package facebook/webdriver is abandoned, you should avoid using it. Use php-webdriver/webdriver instead.
Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.
Package guzzlehttp/ringphp is abandoned, you should avoid using it. No replacement was suggested.
Package guzzlehttp/streams is abandoned, you should avoid using it. No replacement was suggested.
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Package setasign/fpdi-fpdf is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating optimized autoload files

無事、最新バージョンの3.9がインストールされました。(2020年8月12日時点)

EC-CUBEカスタマイズ

QRコードを生成

data/class/pages/mypage/LC_Page_Mypage.php
<?php
/*
 * This file is part of EC-CUBE
 *
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
 *
 * http://www.ec-cube.co.jp/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

require_once CLASS_EX_REALDIR . 'page_extends/mypage/LC_Page_AbstractMypage_Ex.php';

use Endroid\QrCode\QrCode;    // 追加

/**
 * MyPage のページクラス.
 *
 * @package Page
 * @author EC-CUBE CO.,LTD.
 * @version $Id$
 */
class LC_Page_Mypage extends LC_Page_AbstractMypage_Ex
{
    ....

    /**
     * Page のAction.
     *
     * @return void
     */
    public function action()
    {
        ....

        // 追加
        $qrCode = new QrCode('https://qiita.com/kkamizuru/items/6a1a683ce7f9171fdc63');
        $qrCode->setSize(200);
        $this->qr_code = base64_encode($qrCode->writeString());
    }

生成したQRコードを表示

data/Smarty/templates/default/mypage/navi.tpl
        ....

        <!--▼追加-->
        <img src="data:image/gif;base64,<!--{$qr_code|h}-->">
        <!--▲追加-->

        <!--▼現在のポイント-->
        <!--{if $point_disp !== false}-->
            <div class="point_announce clearfix">
                <p>ようこそ&nbsp;&nbsp;
                    <span class="user_name"><!--{$CustomerName1|h}--> <!--{$CustomerName2|h}--></span>
                    <!--{if $smarty.const.USE_POINT !== false}-->&nbsp;
                        現在の所持ポイントは&nbsp;<span class="point st"><!--{$CustomerPoint|n2s|default:"0"|h}-->pt</span>&nbsp;です。
                    <!--{/if}-->
                </p>
            </div>
        <!--{/if}-->
        <!--▲現在のポイント-->

        ....

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0