<commit_before><?php
namespace Botamp\Botamp\Resource;

class ProductEntity extends Resource {

  protected $productHelper;

  public function __construct(\Botamp\Botamp\Helper\ProductHelper $productHelper) {
    parent::__construct();
    $this->productHelper = $productHelper;
  }

  public function createOrUpdate($product) {
    return $product->getBotampEntityId() === null ? $this->create($product) : $this->update($product);
  }

  public function create($product) {
    $attributes = $this->getAttributes($product);
    $entity = $this->botamp->entities->create($attributes);
    $product->setBotampEntityId($entity->getBody()['data']['id']);
    return $entity;
  }

  public function update($product) {
    if(($entityId = $product->getBotampEntityId()) !== null) {
      $attributes = $this->getAttributes($product);
      return $this->botamp->entities->update($entityId, $attributes);
    }
  }

  public function delete($product) {
    if(($entityId = $product->getBotampEntityId()) !== null)
      $this->botamp->entities->delete($entityId);
  }

  public function importAllProducts() {
    $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
    $factoryClassPath = 'Magento\Catalog\Model\ResourceModel\Product\CollectionFactory';
    $collectionFactory = $objectManager->create($factoryClassPath);
    $products = $collectionFactory->create()->addAttributeToSelect('*')->load();
    foreach($products as $product)
      if(!$this->isCreated($product))
        $this->create($product);
  }

  protected function getAttributes($product) {
    return [
      'title' => $product->getName(),
      'description' => $product->getDescription(),
      'url' => $product->getUrlModel()->getUrl($product),
      'entity_type' => 'product',
      // 'image_url' => $this->productHelper->getProductImageUrl($product),
    ];
  }
}<commit_msg>Fixed import products bug<commit_after><?php
namespace Botamp\Botamp\Resource;

class ProductEntity extends Resource {

  protected $productHelper;

  public function __construct(\Botamp\Botamp\Helper\ProductHelper $productHelper) {
    parent::__construct();
    $this->productHelper = $productHelper;
  }

  public function createOrUpdate($product) {
    return $product->getBotampEntityId() === null ? $this->create($product) : $this->update($product);
  }

  public function create($product) {
    $attributes = $this->getAttributes($product);
    $entity = $this->botamp->entities->create($attributes);
    $product->setBotampEntityId($entity->getBody()['data']['id']);
    return $entity;
  }

  public function update($product) {
    if(($entityId = $product->getBotampEntityId()) !== null) {
      $attributes = $this->getAttributes($product);
      return $this->botamp->entities->update($entityId, $attributes);
    }
  }

  public function delete($product) {
    if(($entityId = $product->getBotampEntityId()) !== null)
      $this->botamp->entities->delete($entityId);
  }

  public function importAllProducts() {
    $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
    $factoryClassPath = 'Magento\Catalog\Model\ResourceModel\Product\CollectionFactory';
    $collectionFactory = $objectManager->create($factoryClassPath);
    $products = $collectionFactory->create()->addAttributeToSelect('*')->load();
    foreach($products as $product)
      if($product->getBotampEntityId() !== null)
        $this->create($product);
  }

  protected function getAttributes($product) {
    return [
      'title' => $product->getName(),
      'description' => $product->getDescription(),
      'url' => $product->getUrlModel()->getUrl($product),
      'entity_type' => 'product',
      // 'image_url' => $this->productHelper->getProductImageUrl($product),
    ];
  }
}
{'fraction_non_alphanumeric': 0.17008251264306629, 'fraction_numerical': 0.0, 'mean_word_length': 4.478134110787172, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2456584', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1067, 'n_words': 168}