【问题标题】:What should be the base URL for the images in magento?magento 中图像的基本 URL 应该是什么?
【发布时间】:2015-12-08 11:21:56
【问题描述】:

访问 Rest API (http://192.168.1.180/magento/index.php/rest/V1/products/SKU) 获取产品详细信息后,响应如下:

    {
      "attribute_code": "image",
      "value": "/6/4/64275-152378-large.jpg"
    },
    {
      "attribute_code": "small_image",
      "value": "/6/4/64275-152378-large.jpg"
    },
    {
      "attribute_code": "thumbnail",
      "value": "/6/4/64275-152378-large.jpg"
    }

attribute_code 键中 jpg 的基本 url 应该是什么?

【问题讨论】:

    标签: rest http magento magento2


    【解决方案1】:

    无需修改API请求。

    只需添加前缀:http://magento.com/pub/media/catalog/product/

    所以根据我的回复,新的 URL 将是:

    前缀:http://magento.com/pub/media/catalog/product/6/4/64275-152378-large.jpg

    【讨论】:

      【解决方案2】:
      /** @return string */
      function getMediaBaseUrl() {
          /** @var \Magento\Framework\ObjectManagerInterface $om */
          $om = \Magento\Framework\App\ObjectManager::getInstance();
          /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
          $storeManager = $om->get('Magento\Store\Model\StoreManagerInterface');
          /** @var \Magento\Store\Api\Data\StoreInterface|\Magento\Store\Model\Store $currentStore */
          $currentStore = $storeManager->getStore();
          return $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
      }
      

      【讨论】:

        猜你喜欢
        • 2020-08-21
        • 2012-10-01
        • 1970-01-01
        • 2021-01-17
        • 1970-01-01
        • 2015-08-04
        • 1970-01-01
        • 1970-01-01
        • 2015-03-22
        相关资源
        最近更新 更多