{"id":20982864,"url":"https://github.com/wallasfaria/magento-ruby","last_synced_at":"2025-04-10T01:10:14.630Z","repository":{"id":37935812,"uuid":"283965153","full_name":"WallasFaria/magento-ruby","owner":"WallasFaria","description":"Ruby library to consume the magento 2 api","archived":false,"fork":false,"pushed_at":"2025-01-23T13:47:30.000Z","size":186,"stargazers_count":12,"open_issues_count":2,"forks_count":9,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T18:51:03.546Z","etag":null,"topics":["magento","ruby","ruby-gem","ruby-on-rails","rubygem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WallasFaria.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-31T06:55:03.000Z","updated_at":"2025-01-23T13:47:34.000Z","dependencies_parsed_at":"2024-11-19T05:50:31.933Z","dependency_job_id":"ad6fcdbb-dc0f-43b6-909c-06692d0c87a7","html_url":"https://github.com/WallasFaria/magento-ruby","commit_stats":{"total_commits":214,"total_committers":6,"mean_commits":"35.666666666666664","dds":"0.16822429906542058","last_synced_commit":"10848d897d7cdee36719a6fc63e0fd319c475cc8"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WallasFaria%2Fmagento-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WallasFaria%2Fmagento-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WallasFaria%2Fmagento-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WallasFaria%2Fmagento-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WallasFaria","download_url":"https://codeload.github.com/WallasFaria/magento-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137886,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["magento","ruby","ruby-gem","ruby-on-rails","rubygem"],"created_at":"2024-11-19T05:46:59.589Z","updated_at":"2025-04-10T01:10:14.613Z","avatar_url":"https://github.com/WallasFaria.png","language":"Ruby","readme":"# Magento 2 Ruby library\n\nRuby library to consume the magento 2 api\n\n\u003e Tested in version 2.3 of magento\n\n[Getting started](#getting-started)\n  - [Install](#install)\n  - [Setup](#setup)\n\n[Model common methods](#model-common-methods)\n  - [find](#find)\n  - [find_by](#find_by)\n  - [first](#first)\n  - [count](#count)\n  - [all](#count)\n  - [create](#create)\n  - [update](#update)\n  - [delete](#delete)\n\n[Search criteria](#search-criteria)\n  - [Select fields](#select-fields)\n  - [Filters](#filters)\n  - [Sort order](#sort-order)\n  - [Pagination](#pagination)\n- [Record Collection](#record-collection)\n\n**Additional methods**\n\n[Product](#product)\n  - [Shurtcuts](#shurtcuts)\n  - [Update stock](#update-stock)\n  - [Add media](#add-media-to-product)\n  - [Remove media](#remove-media-from-product)\n  - [Add tier price](#add-tier-price-to-product)\n  - [Remove tier price](#remove-tier-price-from-product)\n  - [Create links](#create-links-to-product)\n  - [Remove link](#remove-link-from-product)\n\n[Order](#order)\n  - [Invoice](#invoice-an-order)\n  - [Offline Refund](#create-offline-refund-for-order)\n  - [Creates new Shipment](#creates-new-shipment-for-given-order)\n  - [Cancel](#cancel-an-order)\n\n[Invoice](#invoice)\n  - [Refund](#create-refund-for-invoice)\n  - [Capture](#capture-an-invoice)\n  - [Void](#void-an-invoice)\n  - [Send email](#send-invoice-email)\n  - [Get comments](#get-invoice-comments)\n\n[Sales Rule](#sales-rule)\n  - [Generate Sales Rules and Coupons](#generate-sales-rules-and-coupons)\n\n[Customer](#customer)\n  - [Find by token](#get-customer-by-token)\n  - [Login](#customer-login)\n  - [Reset Password](#customer-reset-password)\n\n[Guest cart](#guest-cart)\n  - [Payment information](#payment-information)\n  - [Add Coupon](#add-coupon-to-guest-cart)\n  - [Remove Coupon](#remove-coupon-from-guest-cart)\n\n[Inventory](#invoice)\n  - [Check whether a product is salable](#check-whether-a-product-is-salable)\n  - [Check whether a product is salable for a specified quantity](#check-whether-a-product-is-salable-for-a-specified-quantity)\n\n**Helper classes**\n\n- [Create product params](#create-product-params)\n- [Create product image params](#create-product-image-params)\n- [Import products from csv file](#import-products-from-csv-file)\n\n## Getting started\n\n### Install\nAdd in your Gemfile\n\n```rb\ngem 'magento', '~\u003e 0.31.0'\n```\n\nor run\n\n```sh\ngem install magento\n```\n\n### Setup\n\n```rb\nMagento.configure do |config|\n  config.url   = 'https://yourstore.com'\n  config.token = 'MAGENTO_API_KEY'\n  config.store = :default # optional, Default is :all\nend\n\nMagento.with_config(store: :other_store) do # accepts store, url and token parameters\n  Magento::Product.find('sku')\nend\n```\n\n## Model common methods\n\nAll classes that inherit from `Magento::Model` have the methods described below\n\n### `find`\n\nGet resource details with the `find` method\n\nExample:\n```rb\nMagento::Product.find('sku-test')\nMagento::Order.find(25)\nMagento::Country.find('BR')\n```\n\n### `find_by`\n\nReturns the first resource found based on the argument passed\n\nExample:\n```rb\nMagento::Product.find_by(name: 'Some product name')\nMagento::Customer.find_by(email: 'customer@email.com')\n```\n\n### `first`\n\nReturns the first resource found for the [search criteria](#search-criteria)\n\nExample:\n```rb\nMagento::Order.where(grand_total_gt: 100).first\n```\n\n### `count`\n\nReturns the total amount of the resource, also being able to use it based on the [search criteria](#search-criteria)\n\nExample:\n```rb\n\nMagento::Order.count\n\u003e\u003e 1500\n\nMagento::Order.where(status: :pending).count\n\u003e\u003e 48\n```\n\n### `all`\n\nUsed to get a list of a specific resource based on the [search criteria](#search-criteria).\n\nReturns a [Record Collection](#record-collection)\n\nExample:\n```rb\n# Default search criteria:\n#  page: 1\n#  page_size: 50\nMagento::Product.all\n\nMagento::Product\n  .order(created_at: :desc)\n  .page_size(10)\n  .all\n```\n\n### `create`\n\nCreates a new resource based on reported attributes.\n\nConsult the magento documentation for available attributes for each resource:\n\nDocumentation links:\n- [Product](https://magento.redoc.ly/2.3.6-admin/tag/products#operation/catalogProductRepositoryV1SavePost)\n- [Category](https://magento.redoc.ly/2.3.6-admin/tag/categories#operation/catalogCategoryRepositoryV1SavePost)\n- [Order](https://magento.redoc.ly/2.3.6-admin/tag/orders#operation/salesOrderRepositoryV1SavePost)\n- [Customer](https://magento.redoc.ly/2.3.6-admin/tag/customers#operation/customerAccountManagementV1CreateAccountPost)\n\nExample:\n```rb\nMagento::Order.create(\n  customer_firstname: '',\n  customer_lastname: '',\n  customer_email: '',\n  # others attrbutes ...,\n  items: [\n    {\n      sku: '',\n      price: '',\n      qty_ordered: 1,\n      # others attrbutes ...,\n    }\n  ],\n  billing_address: {\n    # attrbutes...\n  },\n  payment: {\n    # attrbutes...\n  },\n  extension_attributes: {\n    # attrbutes...\n  }\n)\n```\n\n#### `update`\n\nUpdate a resource attributes.\n\nExample:\n\n```rb\nMagento::Product.update('sku-teste', name: 'Updated name')\n\n# or by instance method\n\nproduct = Magento::Product.find('sku-teste')\n\nproduct.update(name: 'Updated name', status: '2')\n\n# or save after changing the object\n\nproduct.name = 'Updated name'\nproduct.save\n```\n\n### `delete`\n\nDelete a especific resource.\n\n```rb\nMagento::Product.delete('sku-teste')\n\n# or\nproduct = Magento::Product.find('sku-teste')\nproduct.delete\n```\n\n## Search Criteria\n\nThey are methods used to assemble the search parameters\n\nAll methods return an instance of the `Magento::Query` class. The request is only executed after calling method `all`.\n\nExample:\n\n```rb\ncustomers = Magento::Customer\n  .where(dob_gt: '1995-01-01')\n  .order(:dob)\n  .all\n\n# or\n\nquery = Magento::Customer.where(dob_gt: '1995-01-01')\n\nquery = query.order(:dob) if ordered_by_date_of_birth\n\ncustomers = query.all\n```\n\n### Select fields:\n\nExample:\n```rb\nMagento::Product.select(:id, :sku, :name).all\n\nMagento::Product\n  .select(\n    :id,\n    :sku,\n    :name,\n    extension_attributes: :category_links\n  )\n  .all\n\nMagento::Product\n  .select(\n    :id,\n    :sku,\n    :name,\n    extension_attributes: [\n      :category_links,\n      :website_ids\n    ]\n  )\n  .all\n\nMagento::Product\n  .select(\n    :id,\n    :sku,\n    :name,\n    extension_attributes: [\n      { category_links: :category_id },\n      :website_ids\n    ]\n  )\n  .all\n```\n\n### Filters\n\nExample:\n```rb\nMagento::Product.where(visibility: 4).all\nMagento::Product.where(name_like: 'IPhone%').all\nMagento::Product.where(price_gt: 100).all\n\n# price \u003e 10 AND price \u003c 20\nMagento::Product.where(price_gt: 10)\n                .where(price_lt: 20).all\n\n# price \u003c 1 OR price \u003e 100\nMagento::Product.where(price_lt: 1, price_gt: 100).all\n\nMagento::Order.where(status_in: [:canceled, :complete]).all\n\n```\n\n| Condition | Notes |\n| --------- | ----- |\n|eq         | Equals. |\n|finset     | A value within a set of values |\n|from       | The beginning of a range. Must be used with to |\n|gt         | Greater than |\n|gteq       | Greater than or equal |\n|in         | In. The value is an array |\n|like       | Like. The value can contain the SQL wildcard characters when like is specified. |\n|lt         | Less than |\n|lteq       | Less than or equal |\n|moreq      | More or equal |\n|neq        | Not equal |\n|nfinset    | A value that is not within a set of values |\n|nin        | Not in. The value is an array |\n|notnull    | Not null |\n|null       | Null |\n|to         | The end of a range. Must be used with from |\n\n\n### Sort Order\n\nExample:\n```rb\nMagento::Product.order(:sku).all\nMagento::Product.order(sku: :desc).all\nMagento::Product.order(status: :desc, name: :asc).all\n```\n\n### Pagination:\n\nExample:\n```rb\n# Set page and quantity per page\nMagento::Product\n  .page(1)       # Current page, Default is 1\n  .page_size(25) # Default is 50\n  .all\n\n# per is an alias to page_size\nMagento::Product.per(25).all\n```\n\n## Record Collection\n\nThe `all` method retorns a `Magento::RecordCollection` instance\n\nExample:\n```rb\nproducts = Magento::Product.all\n\nproducts.first\n\u003e\u003e \u003cMagento::Product @sku=\"2100\", @name=\"Biscoito Piraque Salgadinho 100G\"\u003e\n\nproducts[0]\n\u003e\u003e \u003cMagento::Product @sku=\"2100\", @name=\"Biscoito Piraque Salgadinho 100G\"\u003e\n\nproducts.last\n\u003e\u003e \u003cMagento::Product @sku=\"964\", @name=\"Biscoito Negresco 140 G Original\"\u003e\n\nproducts.map(\u0026:sku)\n\u003e\u003e [\"2100\", \"792\", \"836\", \"913\", \"964\"]\n\nproducts.size\n\u003e\u003e 5\n\nproducts.current_page\n\u003e\u003e 1\n\nproducts.next_page\n\u003e\u003e 2\n\nproducts.last_page?\n\u003e\u003e false\n\nproducts.page_size\n\u003e\u003e 5\n\nproducts.total_count\n\u003e\u003e 307\n\nproducts.filter_groups\n\u003e\u003e [\u003cMagento::FilterGroup @filters=[\u003cMagento::Filter @field=\"name\", @value=\"biscoito%\", @condition_type=\"like\"\u003e]\u003e]\n```\n\nAll Methods:\n\n```rb\n# Information about search criteria\n:current_page\n:next_page\n:last_page?\n:page_size\n:total_count\n:filter_groups\n\n# Iterating with the list of items\n:count\n:length\n:size\n\n:first\n:last\n:[]\n:find\n\n:each\n:each_with_index\n:sample\n\n:map\n:select\n:filter\n:reject\n:collect\n:take\n:take_while\n\n:sort\n:sort_by\n:reverse_each\n:reverse\n\n:all?\n:any?\n:none?\n:one?\n:empty?\n```\n\n## Product\n\n### Shurtcuts\n\nShurtcut to get custom attribute value by custom attribute code in product\n\nExemple:\n\n```rb\nproduct.attr :description\n# it is the same as\nproduct.custom_attributes.find { |a| a.attribute_code == 'description' }\u0026.value\n\n# or\nproduct.description\n```\n\nwhen the custom attribute does not exists:\n\n```rb\nproduct.attr :special_price\n\u003e nil\n\nproduct.special_price\n\u003e NoMethodError: undefined method `special_price' for #\u003cMagento::Product:...\u003e\n```\n\n```rb\nproduct.respond_to? :special_price\n\u003e false\n\nproduct.respond_to? :description\n\u003e true\n```\n\nShurtcut to get product stock and stock quantity\n\n```rb\nproduct = Magento::Product.find('sku')\n\nproduct.stock\n\u003e \u003cMagento::StockItem @item_id=7243, @product_id=1221, ...\u003e\n\nproduct.stock_quantity\n\u003e 22\n```\n\n### Update stock\n\nUpdate product stock\n\n```rb\nproduct = Magento::Product.find('sku')\nproduct.update_stock(qty: 12, is_in_stock: true)\n\n# or through the class method\n\nMagento::Product.update_stock('sku', id, {\n  qty: 12,\n  is_in_stock: true\n})\n```\n\n\u003e see all available attributes in: [Magento Rest Api Documentation](https://magento.redoc.ly/2.4.1-admin/tag/productsproductSkustockItemsitemId)\n\n\n### Add media to product\n\nCreate new gallery entry\n\nExample:\n```rb\nproduct = Magento::Product.find('sku')\n\nimage_params = {\n  media_type: 'image',\n  label: 'Image label',\n  position: 1,\n  content: {\n    base64_encoded_data: '/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAA...',\n    type: 'image/jpg',\n    name: 'filename.jpg'\n  },\n  types: ['image']\n}\n\nproduct.add_media(image_params)\n\n# or through the class method\n\nMagento::Product.add_media('sku', image_params)\n```\n\u003e see all available attributes in: [Magento Rest Api Documentation](https://magento.redoc.ly/2.3.6-admin/#operation/catalogProductAttributeMediaGalleryManagementV1CreatePost)\n\n\nyou can also use the `Magento::Params::CreateImage` helper class\n\n```rb\nparams = Magento::Params::CreateImage.new(\n  title: 'Image title',\n  path: '/path/to/image.jpg', # or url\n  position: 1,\n).to_h\n\nproduct.add_media(params)\n```\n\n\u003e see more about [Magento::Params::CreateImage](lib/magento/params/create_image.rb#L9)\n\n### Remove media from product\n\nExample:\n```rb\nproduct = Magento::Product.find('sku')\n\nproduct.add_media(madia_id)\n\n# or through the class method\n\nMagento::Product.add_media('sku', madia_id)\n```\n\n### Add tier price to product\n\nAdd `price` on product `sku` for specified `customer_group_id`\n\nThe `quantity` params is the minimun amount to apply the price\n```rb\nproduct = Magento::Product.find('sku')\nproduct.add_tier_price(3.99, quantity: 1, customer_group_id: :all)\n\n# or through the class method\n\nMagento::Product.add_tier_price('sku', 3.99, quantity: 1, customer_group_id: :all)\n```\n\n### Remove tier price from product\n\n```rb\nproduct = Magento::Product.find(1)\nproduct.remove_tier_price(quantity: 1, customer_group_id: :all)\n\n# or through the class method\n\nMagento::Product.remove_tier_price('sku', quantity: 1, customer_group_id: :all)\n```\n\n### Create links to product\n\nAssign a product link to another product\n\nExample:\n```rb\nproduct = Magento::Product.find('sku')\n\nlink_param = {\n  link_type: 'upsell',\n  linked_product_sku: 'linked_product_sku',\n  linked_product_type: 'simple',\n  position: 1,\n  sku: 'sku'\n}\n\nproduct.create_links([link_param])\n\n# or through the class method\n\nProduct.create_links('sku', [link_param])\n```\n\n### Remove link from product\n\nExample:\n```rb\nproduct = Magento::Product.find('sku')\n\nproduct.remove_link(link_type: 'simple', linked_product_sku: 'linked_product_sku')\n\n# or through the class method\n\nProduct.remove_link(\n  'sku',\n  link_type: 'simple',\n  linked_product_sku: 'linked_product_sku'\n)\n```\n\n## Order\n\n### Invoice an Order\n\nExample:\n```rb\nMagento::Order.invoice(order_id)\n\u003e\u003e 25 # return incoice id\n\n# or from instance\n\norder = Magento::Order.find(order_id)\n\ninvoice_id = order.invoice\n\n# you can pass parameters too\n\ninvoice_id = order.invoice(\n  capture: false,\n  appendComment: true,\n  items: [{ order_item_id: 123, qty: 1 }], # pass items to partial invoice\n  comment: {\n    extension_attributes: { },\n    comment: \"string\",\n    is_visible_on_front: 0\n  },\n  notify: true\n)\n```\n\n[Complete Invoice Documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdinvoice#operation/salesInvoiceOrderV1ExecutePost)\n\n### Create offline refund for order\n\nExample:\n```rb\nMagento::Order.refund(order_id)\n\u003e\u003e 12 # return refund id\n\n# or from instance\n\norder = Magento::Order.find(order_id)\n\norder.refund\n\n# you can pass parameters too\n\norder.refund(\n  items: [\n    {\n      extension_attributes: {},\n      order_item_id: 0,\n      qty: 0\n    }\n  ],\n  notify: true,\n  appendComment: true,\n  comment: {\n    extension_attributes: {},\n    comment: string,\n    is_visible_on_front: 0\n  },\n  arguments: {\n    shipping_amount: 0,\n    adjustment_positive: 0,\n    adjustment_negative: 0,\n    extension_attributes: {\n      return_to_stock_items: [0]\n    }\n  }\n)\n```\n\n[Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundOrderV1ExecutePost)\n\n### Creates new Shipment for given Order.\n\nExample:\n```rb\nMagento::Order.ship(order_id)\n\u003e\u003e 25 # return shipment id\n\n# or from instance\n\norder = Magento::Order.find(order_id)\n\norder.ship\n\n# you can pass parameters too\n\norder.ship(\n  capture: false,\n  appendComment: true,\n  items: [{ order_item_id: 123, qty: 1 }], # pass items to partial shipment\n  tracks: [\n    {\n      extension_attributes: { },\n      track_number: \"string\",\n      title: \"string\",\n      carrier_code: \"string\"\n    }\n  ]\n  notify: true\n)\n```\n\n[Complete Shipment Documentation](https://magento.redoc.ly/2.4-admin/tag/orderorderIdship#operation/salesShipOrderV1ExecutePost)\n\n\n### Cancel an Order\n\nExample:\n```rb\norder = Magento::Order.find(order_id)\n\norder.cancel # or\n\nMagento::Order.cancel(order_id)\n```\n\n### Add a comment on given Order\n\nExample:\n```rb\norder = Magento::Order.find(order_id)\n\norder.add_comment(\n  'comment',\n  is_customer_notified: 0,\n  is_visible_on_front: 1\n)\n\n# or\n\nMagento::Order.add_comment(\n  order_id,\n  'comment',\n  is_customer_notified: 0,\n  is_visible_on_front: 1\n)\n```\n\n## Invoice\n\n### Create refund for invoice\n\nExample:\n```rb\nMagento::Invoice.invoice(invoice_id)\n\u003e\u003e 12 # return refund id\n\n# or from instance\n\ninvoice = Magento::Invoice.find(invoice_id)\n\nrefund_id = invoice.refund\n\n# you can pass parameters too\n\ninvoice.refund(\n  items: [\n    {\n      extension_attributes: {},\n      order_item_id: 0,\n      qty: 0\n    }\n  ],\n  isOnline: true,\n  notify: true,\n  appendComment: true,\n  comment: {\n    extension_attributes: {},\n    comment: string,\n    is_visible_on_front: 0\n  },\n  arguments: {\n    shipping_amount: 0,\n    adjustment_positive: 0,\n    adjustment_negative: 0,\n    extension_attributes: {\n      return_to_stock_items: [0]\n    }\n  }\n)\n```\n\n[Complete Refund Documentation](https://magento.redoc.ly/2.4-admin/tag/invoicescomments#operation/salesRefundInvoiceV1ExecutePost)\n\n### Capture an invoice\n\nExample:\n```rb\ninvoice = Magento::Invoice.find(invoice_id)\ninvoice.capture\n\n# or through the class method\nMagento::Invoice.capture(invoice_id)\n```\n\n### Void an invoice\n\nExample:\n```rb\ninvoice = Magento::Invoice.find(invoice_id)\ninvoice.void\n\n# or through the class method\nMagento::Invoice.void(invoice_id)\n```\n\n### Send invoice email\n\nExample:\n```rb\ninvoice = Magento::Invoice.find(invoice_id)\ninvoice.send_email\n\n# or through the class method\nMagento::Invoice.send_email(invoice_id)\n```\n\n### Get invoice comments\n\nExample:\n```rb\nMagento::Invoice.comments(invoice_id).all\nMagento::Invoice.comments(invoice_id).where(created_at_gt: Date.today.prev_day).all\n```\n\n## Sales Rules\n\n### Generate Sales Rules and Coupons\n\n```rb\nrule = Magento::SalesRule.create(\n  name: 'Discount name',\n  website_ids: [1],\n  customer_group_ids: [0,1,2,3],\n  uses_per_customer: 1,\n  is_active: true,\n  stop_rules_processing: true,\n  is_advanced: false,\n  sort_order: 0,\n  discount_amount: 100,\n  discount_step: 1,\n  apply_to_shipping: true,\n  times_used: 0,\n  is_rss: true,\n  coupon_type: 'specific',\n  use_auto_generation: true,\n  uses_per_coupon: 1\n)\n\nrule.generate_coupon(quantity: 1, length: 10)\n```\n\nGenerate by class method\n```rb\nMagento::SalesRule.generate_coupon(\n  couponSpec: {\n    rule_id: 7,\n    quantity: 1,\n    length: 10\n  }\n)\n```\n\u003e see all params in:\n[Magento docs Coupon](https://magento.redoc.ly/2.3.5-admin/tag/couponsgenerate#operation/salesRuleCouponManagementV1GeneratePost) and\n[Magento docs SalesRules](https://magento.redoc.ly/2.3.5-admin/tag/salesRules#operation/salesRuleRuleRepositoryV1SavePost)\n\n\n## Customer\n\n### Get customer by token\n```rb\nMagento::Customer.find_by_token('user_token')\n```\n\n### Customer login\nExemple:\n```rb\nMagento::Customer.login('username', 'password')\n\n\u003e\u003e 'aj8oer4eQi44FrghgfhVdbBKN' #return user token\n```\n\n### Customer reset password\nExemple:\n```rb\nMagento::Customer.reset_password(\n    email: 'user_email',\n    reset_token: 'user_reset_token',\n    new_password: 'user_new_password'\n  )\n\n\u003e\u003e true # return true on success\n```\n\n## Guest Cart\n\n### Payment information\nSet payment information to finish the order\n\nExample:\n```rb\ncart = Magento::GuestCart.find('gXsepZcgJbY8RCJXgGioKOO9iBCR20r7')\n\n# or use \"build\" to not request information from the magento API\ncart = Magento::GuestCart.build(\n  cart_id: 'aj8oUtY1Qi44Fror6UWVN7ftX1idbBKN'\n)\n\ncart.payment_information(\n  email: 'customer@gmail.com',\n  payment: { method: 'cashondelivery' }\n)\n\n\u003e\u003e \"234575\" # return the order id\n```\n\n### Add coupon to guest cart\n\nExample:\n```rb\ncart = Magento::GuestCart.find('gXsepZcgJbY8RCJXgGioKOO9iBCR20r7')\n\ncart.add_coupon('COAU4HXE0I')\n# You can also use the class method\nMagento::GuestCart.add_coupon('gXsepZcgJbY8RCJXgGioKOO9iBCR20r7', 'COAU4HXE0I')\n\n\u003e\u003e true # return true on success\n```\n\n### Remove coupon from guest cart\n\nExample:\n```rb\ncart = Magento::GuestCart.find('gXsepZcgJbY8RCJXgGioKOO9iBCR20r7')\n\ncart.delete_coupon()\n# You can also use the class method\nMagento::GuestCart.delete_coupon('gXsepZcgJbY8RCJXgGioKOO9iBCR20r7')\n\n\u003e\u003e true # return true on success\n```\n\n## Inventory\n\n### Check whether a product is salable\n\nExample:\n```rb\nInventory.get_product_salable_quantity(sku: '4321', stock_id: 1)\n\u003e\u003e 1\n```\n\n### Check whether a product is salable for a specified quantity\n\nExample:\n```rb\nInventory.is_product_salable_for_requested_qty(\n  sku: '4321',\n  stock_id: 1,\n  requested_qty: 2\n)\n\u003e\u003e OpenStruct {\n  :salable =\u003e false,\n  :errors =\u003e [\n    [0] {\n      \"code\" =\u003e \"back_order-disabled\",\n      \"message\" =\u003e \"Backorders are disabled\"\n    },\n    ...\n  ]\n}\n```\n\n## **Helper classes**\n\n## Create product params\n\n```rb\nparams = Magento::Params::CreateProduct.new(\n  sku: '556-teste-builder',\n  name: 'REFRIGERANTE PET COCA-COLA 1,5L ORIGINAL',\n  description: 'Descrição do produto',\n  brand: 'Coca-Cola',\n  price: 4.99,\n  special_price: 3.49,\n  quantity: 2,\n  weight: 0.3,\n  attribute_set_id: 4,\n  images: [\n    *Magento::Params::CreateImage.new(\n      path: 'https://urltoimage.com/image.jpg',\n      title: 'REFRIGERANTE PET COCA-COLA 1,5L ORIGINAL',\n      position: 1,\n      main: true\n    ).variants,\n    Magento::Params::CreateImage.new(\n      path: '/path/to/image.jpg',\n      title: 'REFRIGERANTE PET COCA-COLA 1,5L ORIGINAL',\n      position: 2\n    )\n  ]\n)\n\nMagento::Product.create(params.to_h)\n```\n\n## Create product image params\n\nHelper class to create product image params.\n\nbefore generating the hash, the following image treatments are performed:\n- resize image\n- remove alpha\n- leaves square\n- convert image to jpg\n\nExample:\n```rb\nparams = Magento::Params::CreateImage.new(\n  title: 'Image title',\n  path: '/path/to/image.jpg', # or url\n  position: 1,\n  size: 'small', # options: 'large'(defaut), 'medium' and 'small',\n  disabled: true, # default is false,\n  main: true, # default is false,\n).to_h\n\nMagento::Product.add_media('sku', params)\n```\n\nThe resize defaut confiruration is:\n\n```rb\nMagento.configure do |config|\n  config.product_image.small_size  = '200x200\u003e'\n  config.product_image.medium_size = '400x400\u003e'\n  config.product_image.large_size  = '800x800\u003e'\nend\n```\n\n## Import products from csv file\n\n_TODO: exemple to [Magento::Import.from_csv](lib/magento/import.rb#L8)_\n\n_TODO: exemple to [Magento::Import.get_csv_template](lib/magento/import.rb#L14)_\n\n\n___\n\n\n## **TODO:**\n\n### Search products\n```rb\nMagento::Product.search('tshort')\n```\n\n### Last result\n```rb\nMagento::Product.last\n\u003e\u003e \u003cMagento::Product @sku=\"some-sku\" ...\u003e\n\nMagento::Product.where(name_like: 'some name%').last\n\u003e\u003e \u003cMagento::Product @sku=\"some-sku\" ...\u003e\n```\n\n### Tests\n\n___\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/WallasFaria/magento_ruby.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwallasfaria%2Fmagento-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwallasfaria%2Fmagento-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwallasfaria%2Fmagento-ruby/lists"}