Skip to content
This repository was archived by the owner on Apr 30, 2023. It is now read-only.

Call to undefined method Magento\Bundle\Model\Product\Type::getConfigurableAttributeCollection() is Fixed as per code #57

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Block/Adminhtml/System/Config/CategoryFeed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*/

namespace Facebook\BusinessExtension\Block\Adminhtml\System\Config;

use Magento\Backend\Block\Widget\Button;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;

class CategoryFeed extends Field
{
/**
* @var string
*/
protected $_template = 'Facebook_BusinessExtension::system/config/category_feed.phtml';

/**
* Remove scope label
*
* @param AbstractElement $element
* @return string
*/
public function render(AbstractElement $element)
{
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}

/**
* @todo move to helper
* @return string
*/
public function getAjaxUrl()
{
return $this->getUrl('fbeadmin/ajax/categoryUpload');
}

/**
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
return $this->_toHtml();
}

/**
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getButtonHtml()
{
/** @var Button $button */
$button = $this->getLayout()->createBlock(Button::class);
return $button->setData(['id' => 'fb_category_upload_btn', 'label' => __('Upload to Facebook')])
->toHtml();
}
}
6 changes: 2 additions & 4 deletions Block/Pixel/InitiateCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ public function getContentIDs()
$productIds = [];
$cart = $this->fbeHelper->getObject(\Magento\Checkout\Model\Cart::class);
$items = $cart->getQuote()->getAllVisibleItems();
$productModel = $this->fbeHelper->getObject(\Magento\Catalog\Model\Product::class);
foreach ($items as $item) {
$product = $productModel->load($item->getProductId());
$product = $item->getProduct();
$productIds[] = $product->getId();
}
return $this->arrayToCommaSeparatedStringValues($productIds);
Expand Down Expand Up @@ -49,10 +48,9 @@ public function getContents()
}
$contents = [];
$items = $cart->getQuote()->getAllVisibleItems();
$productModel = $this->fbeHelper->getObject(\Magento\Catalog\Model\Product::class);
$priceHelper = $this->objectManager->get(\Magento\Framework\Pricing\Helper\Data::class);
foreach ($items as $item) {
$product = $productModel->load($item->getProductId());
$product = $item->getProduct();
$price = $priceHelper->currency($product->getFinalPrice(), false, false);
$content = '{id:"' . $product->getId() . '",quantity:' . (int)$item->getQty()
. ',item_price:' . $price . "}";
Expand Down
7 changes: 2 additions & 5 deletions Block/Pixel/Purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ public function getContentIDs()
$order = $this->fbeHelper->getObject(\Magento\Checkout\Model\Session::class)->getLastRealOrder();
if ($order) {
$items = $order->getItemsCollection();
$productModel = $this->fbeHelper->getObject(Product::class);
foreach ($items as $item) {
// @todo do not load product model in loop - this can be a performance killer, use product collection
$product = $productModel->load($item->getProductId());
$product = $item->getProduct();
$productIds[] = $product->getId();
}
}
Expand Down Expand Up @@ -53,11 +51,10 @@ public function getContents()
if ($order) {
$priceHelper = $this->objectManager->get(\Magento\Framework\Pricing\Helper\Data::class);
$items = $order->getItemsCollection();
$productModel = $this->fbeHelper->getObject(Product::class);
foreach ($items as $item) {
/** @var Product $product */
// @todo reuse results from self::getContentIDs()
$product = $productModel->load($item->getProductId());
$product = $item->getProduct();
$price = $priceHelper->currency($product->getFinalPrice(), false, false);
$content = '{id:"' . $product->getId() . '",quantity:' . (int)$item->getQtyOrdered()
. ',item_price:' . $price . '}';
Expand Down
52 changes: 52 additions & 0 deletions Controller/Adminhtml/Ajax/CategoryUpload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*/

namespace Facebook\BusinessExtension\Controller\Adminhtml\Ajax;

use Exception;
use Facebook\BusinessExtension\Helper\FBEHelper;
use Facebook\BusinessExtension\Model\Feed\CategoryCollection;

use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;

class CategoryUpload extends AbstractAjax
{
/**
* @var CategoryCollection
*/
protected $categoryCollection;

public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
FBEHelper $fbeHelper,
CategoryCollection $categoryCollection
) {
parent::__construct($context, $resultJsonFactory, $fbeHelper);
$this->categoryCollection = $categoryCollection;
}

public function executeForJson()
{
$response = [];

if (!$this->_fbeHelper->getAccessToken()) {
$response['success'] = false;
$response['message'] = __('Set up the extension before uploading category.');
return $response;
}

try {
$feedPushResponse = $this->categoryCollection->pushAllCategoriesToFbCollections();
$response['success'] = true;
$response['feed_push_response'] = $feedPushResponse;
} catch (Exception $e) {
$response['success'] = false;
$response['message'] = $e->getMessage();
}
return $response;
}
}
11 changes: 5 additions & 6 deletions Controller/Pixel/ProductInfoForAddToCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ class ProductInfoForAddToCart extends \Magento\Framework\App\Action\Action
protected $_resultJsonFactory;
protected $_productFactory;
protected $_fbeHelper;
protected $_eventManager;
protected $_formKeyValidator;
protected $_magentoDataHelper;

public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Catalog\Model\ProductFactory $productFactory,
FBEHelper $helper,
\Magento\Framework\Event\ManagerInterface $eventManager,
\Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
\Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
\Facebook\BusinessExtension\Helper\MagentoDataHelper $magentoDataHelper
) {
parent::__construct($context);
$this->_resultJsonFactory = $resultJsonFactory;
$this->_productFactory = $productFactory;
$this->_fbeHelper = $helper;
$this->_eventManager = $eventManager;
$this->_formKeyValidator = $formKeyValidator;
$this->_magentoDataHelper = $magentoDataHelper;
}

private function getCategory($product)
Expand Down Expand Up @@ -63,8 +63,7 @@ private function getValue($product)
private function getProductInfo($product_sku)
{
$response_data = [];
$product = $this->_productFactory->create();
$product->load($product->getIdBySku($product_sku));
$product = $this->_magentoDataHelper->getProductWithSku($product_sku);
if ($product->getId()) {
$response_data['id'] = $product->getId();
$response_data['name'] = $product->getName();
Expand Down
24 changes: 13 additions & 11 deletions Helper/MagentoDataHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class MagentoDataHelper extends AbstractHelper
*/
protected $customerMetadata;

/**
* @var \Magento\Catalog\Api\ProductRepositoryInterface
*/
protected $productRepository;

/**
* MagentoDataHelper constructor
*
Expand All @@ -55,14 +60,16 @@ public function __construct(
\Facebook\BusinessExtension\Logger\Logger $logger,
\Magento\Catalog\Model\ProductFactory $productFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Customer\Api\CustomerMetadataInterface $customerMetadata
\Magento\Customer\Api\CustomerMetadataInterface $customerMetadata,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
) {
parent::__construct($context);
$this->objectManager = $objectManager;
$this->logger = $logger;
$this->productFactory = $productFactory;
$this->storeManager = $storeManager;
$this->customerMetadata = $customerMetadata;
$this->productRepository = $productRepository;
}

/**
Expand Down Expand Up @@ -121,8 +128,7 @@ public function getDateOfBirth()
*/
public function getProductWithSku($productSku)
{
$product = $this->productFactory->create();
$product->load($product->getIdBySku($productSku));
$product = $this->productRepository->get($productSku);
return $product;
}

Expand Down Expand Up @@ -184,9 +190,8 @@ public function getCartContentIds()
return null;
}
$items = $cart->getQuote()->getAllVisibleItems();
$productModel = $this->objectManager->get(\Magento\Catalog\Model\Product::class);
foreach ($items as $item) {
$product = $productModel->load($item->getProductId());
$product = $item->getProduct();
$productIds[] = $product->getId();
}
return $productIds;
Expand Down Expand Up @@ -241,10 +246,9 @@ public function getCartContents()
}
$contents = [];
$items = $cart->getQuote()->getAllVisibleItems();
$productModel = $this->objectManager->get(\Magento\Catalog\Model\Product::class);
$priceHelper = $this->objectManager->get(\Magento\Framework\Pricing\Helper\Data::class);
foreach ($items as $item) {
$product = $productModel->load($item->getProductId());
$product = $item->getProduct();
$contents[] = [
'product_id' => $product->getId(),
'quantity' => $item->getQty(),
Expand All @@ -266,9 +270,8 @@ public function getOrderContentIds()
}
$productIds = [];
$items = $order->getAllVisibleItems();
$productModel = $this->objectManager->get(\Magento\Catalog\Model\Product::class);
foreach ($items as $item) {
$product = $productModel->load($item->getProductId());
$product = $item->getProduct();
$productIds[] = $product->getId();
}
return $productIds;
Expand Down Expand Up @@ -306,10 +309,9 @@ public function getOrderContents()
}
$contents = [];
$items = $order->getAllVisibleItems();
$productModel = $this->objectManager->get(\Magento\Catalog\Model\Product::class);
$priceHelper = $this->objectManager->get(\Magento\Framework\Pricing\Helper\Data::class);
foreach ($items as $item) {
$product = $productModel->load($item->getProductId());
$product = $item->getProduct();
$contents[] = [
'product_id' => $product->getId(),
'quantity' => (int)$item->getQtyOrdered(),
Expand Down
2 changes: 1 addition & 1 deletion Logger/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ class Handler extends \Magento\Framework\Logger\Handler\Base
* File name
* @var string
*/
protected $fileName = 'var/log/facebook-business-extension.log';
protected $fileName = '/var/log/facebook-business-extension.log';
}
58 changes: 0 additions & 58 deletions Model/Config/Source/Product/InventorySource.php

This file was deleted.

Loading