There's nothing I can say really, as I'm not into ZEND... All I can say is I get a stack of errors/warnings that look like :
Zend_Exception: No entry is registered for key 'liveHeader' in /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Registry.php on line 147 Call Stack: 0.0007 630840 1. {main}() /Users/koopa/Sites/ykone/trunk/public/index.php:0 0.2304 4603280 2. Zend_Application->run() /Users/koopa/Sites/ykone/trunk/public/index.php:42 0.2304 4603280 3. Bootstrap->run() /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Application.php:328 0.2346 4626200 4. Zend_Application_Bootstrap_Bootstrap->run() /Users/koopa/Sites/ykone/trunk/application/Bootstrap.php:12 0.2348 4626520 5. Zend_Controller_Front->dispatch($request = ???, $response = ???) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Application/Bootstrap/Bootstrap.php:77 1.6190 13445472 6. Zend_Controller_Plugin_Broker->postDispatch($request = class Zend_Controller_Request_Http { protected $_paramSources = array (0 => '_GET', 1 => '_POST'); protected $_requestUri = '/'; protected $_baseUrl = ''; protected $_basePath = NULL; protected $_pathInfo = '/'; protected $_params = array ('controller' => 'index', 'action' => 'index'); protected $_aliases = array (); protected $_dispatched = TRUE; protected $_module = 'default'; protected $_moduleKey = 'module'; protected $_controller = 'index'; protected $_controllerKey = 'controller'; protected $_action = 'index'; protected $_actionKey = 'action' }) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Controller/Front.php:956 1.6191 13445472 7. Zend_Layout_Controller_Plugin_Layout->postDispatch($request = class Zend_Controller_Request_Http { protected $_paramSources = array (0 => '_GET', 1 => '_POST'); protected $_requestUri = '/'; protected $_baseUrl = ''; protected $_basePath = NULL; protected $_pathInfo = '/'; protected $_params = array ('controller' => 'index', 'action' => 'index'); protected $_aliases = array (); protected $_dispatched = TRUE; protected $_module = 'default'; protected $_moduleKey = 'module'; protected $_controller = 'index'; protected $_controllerKey = 'controller'; protected $_action = 'index'; protected $_actionKey = 'action' }) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Controller/Plugin/Broker.php:330 1.6193 13445976 8. Zend_Layout->render($name = ???) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Layout/Controller/Plugin/Layout.php:142 1.6203 13450944 9. Zend_View_Abstract->render($name = 'layout.phtml') /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Layout.php:791 1.6204 13492584 10. Zend_View->_run('/Users/koopa/Sites/ykone/trunk/application/views/scripts/layout.phtml') /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/View/Abstract.php:832 1.6215 13653240 11. include('/Users/koopa/Sites/ykone/trunk/application/views/scripts/layout.phtml') /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/View.php:107 1.7286 15289440 12. YPush->LayoutTop() /Users/koopa/Sites/ykone/trunk/application/views/scripts/layout.phtml:153 1.7286 15289704 13. YPush->__call($method = 'LayoutTop', $attr = array ()) /Users/koopa/Sites/ykone/trunk/library/YPush.php:153 1.7295 15336024 14. YPush->getData() /Users/koopa/Sites/ykone/trunk/library/YPush.php:79 1.7295 15336024 15. YPush->loadData() /Users/koopa/Sites/ykone/trunk/library/YPush.php:122 1.7295 15336544 16. call_user_func_array(array (0 => class YPush_LayoutTop { private ${YPush}:_file = 'layouttop.php'; protected $_dir = ''; protected $_class = 'YPush'; protected $_attr = array (...); protected $_cache = FALSE; protected $_lifetime = 86400; private ${YPush}:_id = 'LayoutTop_2723407904'; public $request = class Zend_Controller_Request_Http { ... }; private ${Zend_View}:_useViewStream = FALSE; private ${Zend_View}:_useStreamWrapper = FALSE; private ${Zend_View_Abstract}:_path = array (...); private ${Zend_View_Abstract}:_file = NULL; private ${Zend_View_Abstract}:_helper = array (...); private ${Zend_View_Abstract}:_helperLoaded = array (...); private ${Zend_View_Abstract}:_helperLoadedDir = array (...); private ${Zend_View_Abstract}:_filter = array (...); private ${Zend_View_Abstract}:_filterClass = array (...); private ${Zend_View_Abstract}:_filterLoaded = array (...); private ${Zend_View_Abstract}:_filterLoadedDir = array (...); private ${Zend_View_Abstract}:_escape = 'htmlspecialchars'; private ${Zend_View_Abstract}:_encoding = 'ISO-8859-1'; private ${Zend_View_Abstract}:_lfiProtectionOn = TRUE; private ${Zend_View_Abstract}:_loaders = array (...); private ${Zend_View_Abstract}:_loaderTypes = array (...); private ${Zend_View_Abstract}:_strictVars = FALSE; private ${Zend_View_Abstract}:_log = NULL }, 1 => 'prepare'), array ()) /Users/koopa/Sites/ykone/trunk/library/YPush.php:132 1.7295 15336792 17. YPush_LayoutTop->prepare() /Users/koopa/Sites/ykone/trunk/library/YPush.php:132 1.7295 15336872 18. Zend_Registry::get($index = 'liveHeader') /Users/koopa/Sites/ykone/trunk/library/YPush/LayoutTop.php:15 Variables in local scope (#18): $index = 'liveHeader' $instance = class Zend_Registry { public $Zend_View_Helper_Placeholder_Registry = class Zend_View_Helper_Placeholder_Registry { protected $_containerClass = 'Zend_View_Helper_Placeholder_Container'; protected $_items = array (...) }; public $db = class Zend_Db_Adapter_Pdo_Mysql { protected $_pdoType = 'mysql'; protected $_numericDataTypes = array (...); protected $_defaultStmtClass = 'Zend_Db_Statement_Pdo'; protected $_config = array (...); protected $_fetchMode = 2; protected $_profiler = class Zend_Db_Profiler { ... }; protected $_defaultProfilerClass = 'Zend_Db_Profiler'; protected $_connection = class PDO { ... }; protected $_caseFolding = 0; protected $_autoQuoteIdentifiers = TRUE; protected $_allowSerialization = TRUE; protected $_autoReconnectOnUnserialize = FALSE }; public $db_master = class Zend_Db_Adapter_Pdo_Mysql { protected $_pdoType = 'mysql'; protected $_numericDataTypes = array (...); protected $_defaultStmtClass = 'Zend_Db_Statement_Pdo'; protected $_config = array (...); protected $_fetchMode = 2; protected $_profiler = class Zend_Db_Profiler { ... }; protected $_defaultProfilerClass = 'Zend_Db_Profiler'; protected $_connection = class PDO { ... }; protected $_caseFolding = 0; protected $_autoQuoteIdentifiers = TRUE; protected $_allowSerialization = TRUE; protected $_autoReconnectOnUnserialize = FALSE }; public $Zend_Locale = class Zend_Locale { protected $_locale = 'fr' }; public $WideLocale = 'fr_FR'; public $UrlTranslator = class Zend_Translate { private $_adapter = class Zend_Translate_Adapter_Csv { ... } }; public $config = class Zend_Config_Ini { protected $_nestSeparator = '.'; protected $_sectionSeparator = ':'; protected $_skipExtends = FALSE; protected $_allowModifications = FALSE; protected $_index = 0; protected $_count = 8; protected $_data = array (...); protected $_skipNextIteration = NULL; protected $_loadedSection = array (...); protected $_extends = array (...); protected $_loadFileErrorStr = NULL }; public $Zend_View_Helper_Doctype = class ArrayObject { public $doctypes = array (...); public $doctype = 'HTML4_LOOSE' } } Zend_Exception: No entry is registered for key 'liveLogo' in /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Registry.php on line 147 Call Stack: 0.0007 630840 1. {main}() /Users/koopa/Sites/ykone/trunk/public/index.php:0 0.2304 4603280 2. Zend_Application->run() /Users/koopa/Sites/ykone/trunk/public/index.php:42 0.2304 4603280 3. Bootstrap->run() /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Application.php:328 0.2346 4626200 4. Zend_Application_Bootstrap_Bootstrap->run() /Users/koopa/Sites/ykone/trunk/application/Bootstrap.php:12 0.2348 4626520 5. Zend_Controller_Front->dispatch($request = ???, $response = ???) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Application/Bootstrap/Bootstrap.php:77 1.6190 13445472 6. Zend_Controller_Plugin_Broker->postDispatch($request = class Zend_Controller_Request_Http { protected $_paramSources = array (0 => '_GET', 1 => '_POST'); protected $_requestUri = '/'; protected $_baseUrl = ''; protected $_basePath = NULL; protected $_pathInfo = '/'; protected $_params = array ('controller' => 'index', 'action' => 'index'); protected $_aliases = array (); protected $_dispatched = TRUE; protected $_module = 'default'; protected $_moduleKey = 'module'; protected $_controller = 'index'; protected $_controllerKey = 'controller'; protected $_action = 'index'; protected $_actionKey = 'action' }) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Controller/Front.php:956 1.6191 13445472 7. Zend_Layout_Controller_Plugin_Layout->postDispatch($request = class Zend_Controller_Request_Http { protected $_paramSources = array (0 => '_GET', 1 => '_POST'); protected $_requestUri = '/'; protected $_baseUrl = ''; protected $_basePath = NULL; protected $_pathInfo = '/'; protected $_params = array ('controller' => 'index', 'action' => 'index'); protected $_aliases = array (); protected $_dispatched = TRUE; protected $_module = 'default'; protected $_moduleKey = 'module'; protected $_controller = 'index'; protected $_controllerKey = 'controller'; protected $_action = 'index'; protected $_actionKey = 'action' }) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Controller/Plugin/Broker.php:330 1.6193 13445976 8. Zend_Layout->render($name = ???) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Layout/Controller/Plugin/Layout.php:142 1.6203 13450944 9. Zend_View_Abstract->render($name = 'layout.phtml') /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Layout.php:791 1.6204 13492584 10. Zend_View->_run('/Users/koopa/Sites/ykone/trunk/application/views/scripts/layout.phtml') /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/View/Abstract.php:832 1.6215 13653240 11. include('/Users/koopa/Sites/ykone/trunk/application/views/scripts/layout.phtml') /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/View.php:107 1.7286 15289440 12. YPush->LayoutTop() /Users/koopa/Sites/ykone/trunk/application/views/scripts/layout.phtml:153 1.7286 15289704 13. YPush->__call($method = 'LayoutTop', $attr = array ()) /Users/koopa/Sites/ykone/trunk/library/YPush.php:153 1.7295 15336024 14. YPush->getData() /Users/koopa/Sites/ykone/trunk/library/YPush.php:79 1.7295 15336024 15. YPush->loadData() /Users/koopa/Sites/ykone/trunk/library/YPush.php:122 1.7295 15336544 16. call_user_func_array(array (0 => class YPush_LayoutTop { private ${YPush}:_file = 'layouttop.php'; protected $_dir = ''; protected $_class = 'YPush'; protected $_attr = array (...); protected $_cache = FALSE; protected $_lifetime = 86400; private ${YPush}:_id = 'LayoutTop_2723407904'; public $request = class Zend_Controller_Request_Http { ... }; private ${Zend_View}:_useViewStream = FALSE; private ${Zend_View}:_useStreamWrapper = FALSE; private ${Zend_View_Abstract}:_path = array (...); private ${Zend_View_Abstract}:_file = NULL; private ${Zend_View_Abstract}:_helper = array (...); private ${Zend_View_Abstract}:_helperLoaded = array (...); private ${Zend_View_Abstract}:_helperLoadedDir = array (...); private ${Zend_View_Abstract}:_filter = array (...); private ${Zend_View_Abstract}:_filterClass = array (...); private ${Zend_View_Abstract}:_filterLoaded = array (...); private ${Zend_View_Abstract}:_filterLoadedDir = array (...); private ${Zend_View_Abstract}:_escape = 'htmlspecialchars'; private ${Zend_View_Abstract}:_encoding = 'ISO-8859-1'; private ${Zend_View_Abstract}:_lfiProtectionOn = TRUE; private ${Zend_View_Abstract}:_loaders = array (...); private ${Zend_View_Abstract}:_loaderTypes = array (...); private ${Zend_View_Abstract}:_strictVars = FALSE; private ${Zend_View_Abstract}:_log = NULL }, 1 => 'prepare'), array ()) /Users/koopa/Sites/ykone/trunk/library/YPush.php:132 1.7295 15336792 17. YPush_LayoutTop->prepare() /Users/koopa/Sites/ykone/trunk/library/YPush.php:132 1.7307 15371992 18. Zend_Registry::get($index = 'liveLogo') /Users/koopa/Sites/ykone/trunk/library/YPush/LayoutTop.php:21 Variables in local scope (#18): $index = 'liveLogo' $instance = class Zend_Registry { public $Zend_View_Helper_Placeholder_Registry = class Zend_View_Helper_Placeholder_Registry { protected $_containerClass = 'Zend_View_Helper_Placeholder_Container'; protected $_items = array (...) }; public $db = class Zend_Db_Adapter_Pdo_Mysql { protected $_pdoType = 'mysql'; protected $_numericDataTypes = array (...); protected $_defaultStmtClass = 'Zend_Db_Statement_Pdo'; protected $_config = array (...); protected $_fetchMode = 2; protected $_profiler = class Zend_Db_Profiler { ... }; protected $_defaultProfilerClass = 'Zend_Db_Profiler'; protected $_connection = class PDO { ... }; protected $_caseFolding = 0; protected $_autoQuoteIdentifiers = TRUE; protected $_allowSerialization = TRUE; protected $_autoReconnectOnUnserialize = FALSE }; public $db_master = class Zend_Db_Adapter_Pdo_Mysql { protected $_pdoType = 'mysql'; protected $_numericDataTypes = array (...); protected $_defaultStmtClass = 'Zend_Db_Statement_Pdo'; protected $_config = array (...); protected $_fetchMode = 2; protected $_profiler = class Zend_Db_Profiler { ... }; protected $_defaultProfilerClass = 'Zend_Db_Profiler'; protected $_connection = class PDO { ... }; protected $_caseFolding = 0; protected $_autoQuoteIdentifiers = TRUE; protected $_allowSerialization = TRUE; protected $_autoReconnectOnUnserialize = FALSE }; public $Zend_Locale = class Zend_Locale { protected $_locale = 'fr' }; public $WideLocale = 'fr_FR'; public $UrlTranslator = class Zend_Translate { private $_adapter = class Zend_Translate_Adapter_Csv { ... } }; public $config = class Zend_Config_Ini { protected $_nestSeparator = '.'; protected $_sectionSeparator = ':'; protected $_skipExtends = FALSE; protected $_allowModifications = FALSE; protected $_index = 0; protected $_count = 8; protected $_data = array (...); protected $_skipNextIteration = NULL; protected $_loadedSection = array (...); protected $_extends = array (...); protected $_loadFileErrorStr = NULL }; public $Zend_View_Helper_Doctype = class ArrayObject { public $doctypes = array (...); public $doctype = 'HTML4_LOOSE' } }
Any help really appreciated.
You call Zend_Registry::get('liveHeader') before Zend_Registry::set('liveHeader', $liveHeader) which is wrong. Zend_Registry is a global singelton which behaves much like an array, similar to a plain php variant:
$liveHeader = ....
$registry = array('liveHeader' => $liveHeader);
Related
I've admin dashboard with header available in all pages.
in Admin Controller I add function:
`class Admin_controller extends Admin_Core_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$data['notification_count'] = $this->order_admin_model->get_all_notifications_count();
$data['notification'] = $this->order_admin_model->get_all_notifications();
$this->load->view('admin/includes/_header', $data);
$this->load->view('admin/index');
$this->load->view('admin/includes/_footer');
}
}`
The problem is this working only for "home page (index)" dashboard. When I open anyother page then I get issue undefinied variable.
How can I call this variables in global?
`
$data['notification_count'] = $this->order_admin_model->get_all_notifications_count();
$data['notification'] = $this->order_admin_model->get_all_notifications();`
update:
I've one file Core_Controller.php and this file contains:
class Admin_Core_Controller extends Core_Controller
{
public function __construct()
{
parent::__construct();
if (!is_admin()) {
redirect(admin_url() . 'login');
exit();
}
//set control panel lang
$this->control_panel_lang = $this->selected_lang;
if (!empty($this->session->userdata('mds_control_panel_lang'))) {
$this->control_panel_lang = $this->session->userdata('mds_control_panel_lang');
//language translations
$this->language_translations = $this->get_translation_array($this->control_panel_lang->id);
}
//check long cron
if (check_cron_time_long() == true) {
//delete old sessions
$this->settings_model->delete_old_sessions();
//add last update
$this->db->where('id', 1)->update('general_settings', ['last_cron_update_long' => date('Y-m-d H:i:s')]);
}
}
protected function render($view, $data = NULL)
{
$data['notification_count'] = $this->order_admin_model->get_all_notifications_count();
$data['notification'] = $this->order_admin_model->get_all_notifications();
$this->load->view('admin/includes/_header', $data);
$this->load->view($view, $data);
$this->load->view('admin/includes/_footer');
}
public function paginate($url, $total_rows)
{
//initialize pagination
$page = $this->security->xss_clean($this->input->get('page'));
$per_page = $this->input->get('show', true);
$page = clean_number($page);
if (empty($page) || $page <= 0) {
$page = 0;
}
if ($page != 0) {
$page = $page - 1;
}
if (empty($per_page)) {
$per_page = 15;
}
$config['num_links'] = 4;
$config['base_url'] = $url;
$config['total_rows'] = $total_rows;
$config['per_page'] = $per_page;
$config['reuse_query_string'] = true;
$this->pagination->initialize($config);
return array('per_page' => $per_page, 'offset' => $page * $per_page);
}
}
You see I add your code here and now in Admin_Controller I add:
class Admin_controller extends Admin_Core_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$data['title'] = trans("admin_panel");
$data['order_count'] = $this->order_admin_model->get_all_orders_count();
$data['product_count'] = $this->product_admin_model->get_products_count();
$data['pending_product_count'] = $this->product_admin_model->get_pending_products_count();
$data['blog_posts_count'] = $this->blog_model->get_all_posts_count();
$data['members_count'] = $this->auth_model->get_users_count_by_role('member');
$data['latest_orders'] = $this->order_admin_model->get_orders_limited(15);
$data['latest_pending_products'] = $this->product_admin_model->get_latest_pending_products(15);
$data['latest_products'] = $this->product_admin_model->get_latest_products(15);
$data['latest_reviews'] = $this->review_model->get_latest_reviews(15);
$data['latest_comments'] = $this->comment_model->get_latest_comments(15);
$data['latest_members'] = $this->auth_model->get_latest_members(6);
$data['latest_transactions'] = $this->transaction_model->get_transactions_limited(15);
$data['latest_promoted_transactions'] = $this->transaction_model->get_promoted_transactions_limited(15);
$this->load->view('admin/includes/_header', $data);
$this->render('admin/index');
$this->load->view('admin/includes/_footer');
}
and after this dashboard now working and everytime is refreshed every sec.
I would suggest creating a base controller with a render function, then have your controllers extend from this base controller and use this function to render their pages. The render function can then contain the variables that need to be available on all pages.
Since you already have an Admin_Core_Controller class, you might be able to add the render function there instead (not sure of your project structure). Something like this:
class Admin_Core_Controller // ...
{
// ...
protected function render($view, $data = NULL)
{
$data['notification_count'] = $this->order_admin_model->get_all_notifications_count();
$data['notification'] = $this->order_admin_model->get_all_notifications();
$this->load->view('admin/includes/_header', $data);
$this->load->view($view, $data);
$this->load->view('admin/includes/_footer');
}
}
Then use it to render your page in Admin_Controller:
class Admin_controller extends Admin_Core_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->render('admin/index');
}
}
Edit Your Admin_Controller class should look like this - I've removed the header and footer includes (those are already rendered by the render function) and passed the $data array to render:
class Admin_controller extends Admin_Core_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$data['title'] = trans("admin_panel");
$data['order_count'] = $this->order_admin_model->get_all_orders_count();
$data['product_count'] = $this->product_admin_model->get_products_count();
$data['pending_product_count'] = $this->product_admin_model->get_pending_products_count();
$data['blog_posts_count'] = $this->blog_model->get_all_posts_count();
$data['members_count'] = $this->auth_model->get_users_count_by_role('member');
$data['latest_orders'] = $this->order_admin_model->get_orders_limited(15);
$data['latest_pending_products'] = $this->product_admin_model->get_latest_pending_products(15);
$data['latest_products'] = $this->product_admin_model->get_latest_products(15);
$data['latest_reviews'] = $this->review_model->get_latest_reviews(15);
$data['latest_comments'] = $this->comment_model->get_latest_comments(15);
$data['latest_members'] = $this->auth_model->get_latest_members(6);
$data['latest_transactions'] = $this->transaction_model->get_transactions_limited(15);
$data['latest_promoted_transactions'] = $this->transaction_model->get_promoted_transactions_limited(15);
$this->render('admin/index', $data);
}
}
I called a method from one class in another method but my class in not running.
My problem is the line that says sms::dispatch.
I will also make sure that all lines are executed, that is, both inside if and inside foreach.
The queries are also executed.
public function handle()
{
$custoemrsBirthDays = DB::table("customers")->pluck("birth_day");
foreach ($custoemrsBirthDays as $custoemrBirthDay) {
$getMonthAndDay = date('m-d', strtotime($custoemrBirthDay . "+1 day"));
if ($getMonthAndDay == Carbon::now()->format('m-d')) {
$customer = DB::table("customers")
->where("birth_day", $custoemrBirthDay)
->first();
$coupon = new Coupon();
$coupon->coupon = 'birthday' . rand(1, 1000) . '';
$coupon->discount = 13;
$coupon->save();
$coupon->customers()->attach($customer->id);
$customerMobileNumber = DB::table("mobile_numbers")
->where("customer_id", $customer->id)
->where(['is_default' => 1])
->first();
$mobileNumber = $customerMobileNumber->mobile_number;
$SMSText = "سلام خوشتیپ تولدت مبارک با این کوپن حتما یه سری به آرایشگاهمون بزن : " . $coupon->coupon . "";
SMSLog::dispatch($SMSText, $mobileNumber);
}
}
return "no birth day";
}
This is from my class :
class SMSLog implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* #return void
*/
protected $sms_text;
protected $mobileNumber;
public function __construct($sms_text, $mobileNumber)
{
$this->sms_text = $sms_text;
$this->mobileNumber = $mobileNumber;
}
/**
* Execute the job.
*
* #return void
*/
public function handle()
{
log::info("send sms message ($this->sms_text) to $this->mobileNumber");
}
}
I am new to magento. I need to automatically create a csv file whenever an order is placed by the customer.
I am using the event "sales_order_place_after" but the code in the observer is not working.
Can anyone guide me how to generate the csv file successfully whenever the order gets placed.
i keep getting errors like: Object of class Magento\Sales\Model\Order\Address could not be converted to string
Class Order implements ObserverInterface
{
protected $_request;
protected $_order;
protected $_productRepository;
protected $_scopeConfig;
protected $_customer;
protected $_storemanager;
public function __construct(
\Magento\Framework\App\RequestInterface $request,
\Magento\Sales\Model\Order $order,
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
Filesystem $filesystem,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Customer\Model\Customer $customer,
\Magento\Store\Model\StoreManagerInterface $storemanager,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Sales\Model\OrderFactory $orderFactory,
\Magento\Framework\ObjectManager\ObjectManager $objectManager,
\Psr\Log\LoggerInterface $logger,
\Magento\Catalog\Model\ProductFactory $productFactory,
\Magento\Catalog\Model\ProductRepository $productRepository
) {
$this->_scopeConfig = $scopeConfig;
$this->_customer = $customer;
$this->_storemanager = $storemanager;
$this->_request = $request;
$this->_order = $order;
$this->_fileFactory = $fileFactory;
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$this->_productRepository = $productRepository;
}
public function execute(\Magento\Framework\Event\Observer $observer) {
$order = $observer->getEvent()->getOrder();
$websiteID = $this->_storemanager->getStore()->getWebsiteId();
$headers = array( 'Customer Name', 'Customer Email', ' Phone','Shipping Address' ,'SKU','Quantity','Price','Total','Weight');
$name = strtotime('now');
$file = 'customorderexport/'.$name.'_detailed_orderexport.csv';
$this->directory->create('customorderexport');
$stream = $this->directory->openFile($file, 'w+');
$stream->lock();
$stream->writeCsv($headers);
// $orderdetail['Customer Name'] =
$orderdetail['Customer Email'] = $order->getCustomerEmail();
$orderdetail['Contact Phone'] = $order->getTelephone();
$orderdetail['Shipping Address'] = $order->getShippingAddress();
$items = $order->getAllItems();
foreach ($items as $item) {
$orderdetail['SKU'] = $item->getSKU();
$orderdetail['Quantity'] = $item->getQtyOrdered();
$orderdetail['Price'] = $item->getPrice();
$orderdetail['Total'] = $item->getGrandTotal();
$orderdetail['Weight'] = $item->getWeight();
$stream->writeCsv($orderdetail);
}
$stream->unlock();
$stream->close();
}
}
This is because
$order->getShippingAddress();
will return a OrderAddressInterface object. (Magento\Sales\Api\Data\OrderAddressInterface)
You could do following for example:
$shippingAddress = $order->getShippingAddress();
$orderdetail['Shipping Address'] = $shippingAddress->getStreet()[0];
I am trying to fetch all child product Ids from configurable product Ids.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('\Magento\Catalog\Model\Product');
$storeManager = $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface');
$currentStore = $storeManager->getStore();
$mediaUrl = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$productURL = $mediaUrl.'catalog/product';
$collection = $this->_productCollectionFactory->create();
$productCollection = $collection->addAttributeToSelect('*')->addAttributeToFilter('type_id','configurable');
$vendor_product = array();
$productData = $product->getData();
foreach($productCollection as $prodObj){
$productData = array();
$product = $product->load($prodObj->getId());
$productTypeInstance = $product->getTypeInstance();
$usedProducts = $productTypeInstance->getUsedProducts($product);
foreach ($usedProducts as $child) {
$productData['childrenIds'][] = $child->getId();
}
I get Ids of my first configurable product in all the cases
<?php
namespace Vendor\Module\Block;
class ParentAndChilds extends \Magento\Framework\View\Element\Template
{
/**
* #var Context
*/
protected $context;
/**
* #var ProductRepositoryInterface
*/
protected $productRepository;
/**
* #var SearchCriteriaBuilder
*/
protected $searchCriteriaBuilder;
/**
* #var LinkManagementInterface
*/
protected $linkManagement;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\ConfigurableProduct\Api\LinkManagementInterface $linkManagement,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
array $data = []
)
{
$this->linkManagement = $linkManagement;
$this->productRepository = $productRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context, $data);
}
public function getParentsAndChilds()
{
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('type_id', 'configurable')
->create();
$configurableProducts = $this->productRepository
->getList($searchCriteria);
$parentAndChildProducts = array();
foreach ($configurableProducts->getItems() as $configurableProduct) {
$childProducts = $this->linkManagement
->getChildren($configurableProduct->getSku());
foreach ($childProducts as $childProduct) {
$parentAndChildProducts[$configurableProduct->getId()][] = $childProduct->getId();
}
}
return $parentAndChildProducts;
}
}
To get child product Ids from a configurable product, you can use below code:
public function __construct(
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
) {
$this->productRepository = $productRepository;
}
public function execute()
{
$_productId=57786;
$_product=$this->productRepository->getById($_productId);
$childIs=$_product->getExtensionAttributes()->getConfigurableProductLinks();
print_r($childIs);
}
Output looks like:
Array
(
[31981] => 31981
[31982] => 31982
[31983] => 31983
)
Hope it will help you.
$_children = $_product->getTypeInstance()->getUsedProducts($_product);
foreach ($_children as $child){
$childProducts[] = $child;
}
$_product is the configurable product object
You can use the below code for getting Child ID.
$product = $block->getProduct();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$configurable_product_id = $product->getId();
$configurableProduct = $objectManager->get('Magento\Catalog\Model\ProductRepository')->getById($configurable_product_id);
$children = $configurableProduct->getTypeInstance()->getUsedProducts($configurableProduct); $childIds = array();
foreach ($children as $child){
$childIds[] = $child->getId();
}
sort($childIds);
print_r($childIds);
This is for sample code but I suggest do not use $objectManager directly, you can use Block on Plugin Method to get Product Object.
To get all simple children including out of stock products use:
$children = $product
->getTypeInstance()
->getChildrenIds($product->getId());
print_r($children);
I am setting up some db integration testing using Zend_Test_PHPUnit_DatabaseTestCase.
My tests run but the db tables do not get truncated so an add test fails assertion - as the xml I provide as a dataset does not match the db can anybody suggest why
TestCase
class ArtworkDBTest extends DatabaseTestCase
{
public function testAddArtwork()
{
$data=array("artwork_name"=>'test',"description"=>'test',"imgpath"=>'test',"size"=>'test',"price_information"=>'test',"category"=>1,"artwork_order"=>1);
$mockedLog=$this->getMock("Log",array("log"));
$artwork = new shop_Artwork($mockedLog,Zend_Db_Table_Abstract::getDefaultAdapter());
$artwork->addArtwork($data);
$this->assertDataSetsMatchXML('artwork-add.xml', $dataSet);
}
}
Database testing setup code (adapted from dragonbe and ibuildings tutorials)
abstract class DatabaseTestCase extends Zend_Test_PHPUnit_DatabaseTestCase
{
const DEFAULT_CONNECTION_SCHEMA = 'main';
protected $_connectionMock;
private $__configuration = NULL;
protected $_connectionSchema = self::DEFAULT_CONNECTION_SCHEMA;
protected $_seedFilesPath;
protected $dataSet;
public function __construct()
{
$this->dataSet = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet($this->getConnection());
$this->dataSet->addTable('artwork','Select* from artwork');
$this->dataSet->addTable('login','Select *from login');
$this->dataSet->addTable('category','Select *from category');
}
public function getConfiguration()
{
if ($this->__configuration == NULL) {
$this->__configuration = new Zend_Config_Ini(TEST_PATH . '/application/configs/tests.ini');
}
return $this->__configuration;
}
public function getSeedFilesPath()
{
if ($this->_seedFilesPath == NULL) {
$this->_seedFilesPath = $this->getConfiguration()->tests->seeds->folder;
}
return rtrim($this->_seedFilesPath, '/') . '/';
}
protected function getConnection()
{
if ($this->_connectionMock == NULL) {
$dbAdapterName = $this->getConfiguration()->tests->dbadapter;
$dbAdapterParams = $this->getConfiguration()->tests->dbparams->toArray();
$connection = Zend_Db::factory($dbAdapterName, $dbAdapterParams);
$this->_connectionMock = $this->createZendDbConnection(
$connection, $this->_connectionSchema
);
Zend_Db_Table_Abstract::setDefaultAdapter($connection);
}
return $this->_connectionMock;
}
protected function getDataSet()
{
return $this->createFlatXMLDataSet(TEST_PATH . '/fixtures/models/artwork-seed.xml');
}
/**
* Convert a Rowset to a Dataset
*
* #param Zend_Db_Table_Rowset_Abstract $rowset
* #param string $tableName
* #return PHPUnit_Extensions_Database_DataSet_DefaultDataSet
*/
public function convertRowsetToDataSet($rowset, $tableName = NULL)
{
$rowsetDataSet = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rowset, $tableName);
return new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($rowsetDataSet));
}
/**
* Convert a Record to a Dataset
*
* #param array $data
* #param string $tableName
* #return PHPUnit_Extensions_Database_DataSet_DefaultDataSet
*/
public function convertRecordToDataSet(Array $data, $tableName)
{
$rowset = new Zend_Db_Table_Rowset(array('data' => array($data)));
return $this->convertRowsetToDataSet($rowset, $tableName);
}
/**
* Compare dataset with data stored in the file
*
* #param string $filename
* #param PHPUnit_Extensions_Database_DataSet_IDataSet $expected
* #return boolean
*/
public function assertDataSetsMatchXML($filename, PHPUnit_Extensions_Database_DataSet_IDataSet $actual)
{
if (empty($filename) || !is_string($filename))
throw new InvalidArgumentException(
'Second parameter "filename" is not a valid string.'
);
$expected = $this->createFlatXmlDataSet($this->getSeedFilesPath() . $filename);
return $this->assertDataSetsEqual($expected, $actual);
}
}
The answer was running parent::setUp(); inside the test class's setUp() method